Permalink
Browse files

first commit

  • Loading branch information...
Roberto Tyley
Roberto Tyley committed Feb 26, 2009
0 parents commit ef673c3677eed3888631b85820fb07f1b87b8d5a
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" output="target/classes" path="src/main/java"/>
+ <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
+ <classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
+ <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
@@ -0,0 +1 @@
+*/target
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>glug</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.maven.ide.eclipse.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.maven.ide.eclipse.maven2Nature</nature>
+ </natures>
+</projectDescription>
@@ -0,0 +1,5 @@
+#Thu Feb 26 01:53:43 GMT 2009
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.source=1.6
@@ -0,0 +1,8 @@
+#Thu Feb 26 01:46:20 GMT 2009
+activeProfiles=
+eclipse.preferences.version=1
+fullBuildGoals=process-test-resources
+includeModules=false
+resolveWorkspaceProjects=true
+resourceFilterGoals=process-resources resources\:testResources
+version=1
26 pom.xml
@@ -0,0 +1,26 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>com.gu</groupId>
+ <artifactId>glug</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <dependencies>
+ <dependency>
+ <groupId>joda-time</groupId>
+ <artifactId>joda-time</artifactId>
+ <version>1.6</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <target>1.6</target>
+ <source>1.6</source>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
@@ -0,0 +1,48 @@
+package com.gu.glug;
+
+import java.util.NavigableMap;
+import java.util.SortedMap;
+import java.util.SortedSet;
+import java.util.TreeSet;
+import java.util.Map.Entry;
+
+import org.joda.time.Instant;
+import org.joda.time.Interval;
+
+public class SignificantInstants {
+ private NavigableMap<Instant, SignificantInterval> significantInstants;
+
+ SignificantInterval getSignificantIntervalAt(Instant instant) {
+ Entry<Instant, SignificantInterval> floorEntry = significantInstants.floorEntry(instant);
+ if (floorEntry==null) {
+ return null;
+ }
+ SignificantInterval sigInt = floorEntry.getValue();
+ return sigInt.getInterval().contains(instant) ? sigInt : null;
+ }
+
+ SortedSet<SignificantInterval> getSignificantIntervalsDuring(Interval interval) {
+ return new TreeSet<SignificantInterval>(subMapFor(interval).values()); // Make SignificantInterval implement Comparable!
+ }
+
+ void add(SignificantInterval significantInterval) {
+ Interval interval = significantInterval.getInterval();
+ Instant startInstant = interval.getStart().toInstant(), endInstant = interval.getEnd().toInstant();
+
+ if (significantInstants.containsKey(startInstant) ||
+ significantInstants.containsKey(endInstant) ||
+ containsSignificantInstantsDuring(interval)) {
+ throw new IllegalArgumentException();
+ }
+ significantInstants.put(startInstant, significantInterval);
+ significantInstants.put(endInstant, significantInterval);
+ }
+
+ private boolean containsSignificantInstantsDuring(Interval interval) {
+ return !subMapFor(interval).isEmpty();
+ }
+
+ private SortedMap<Instant, SignificantInterval> subMapFor(Interval interval) {
+ return significantInstants.subMap(interval.getStart().toInstant(), interval.getEnd().toInstant());
+ }
+}
@@ -0,0 +1,46 @@
+package com.gu.glug;
+
+import org.joda.time.Interval;
+
+public class SignificantInterval implements Comparable<SignificantInterval> {
+ final Interval interval;
+
+ public SignificantInterval(Interval interval) {
+ this.interval = interval;
+ }
+
+ public Interval getInterval() {
+ return interval;
+ }
+
+ @Override
+ public int hashCode() {
+ return interval.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ SignificantInterval other = (SignificantInterval) obj;
+
+ return interval.equals(other.interval);
+ }
+
+ @Override
+ public int compareTo(SignificantInterval o) {
+ if (interval.isAfter(o.interval)) {
+ return 1;
+ }
+ if (interval.isBefore(o.interval)) {
+ return -1;
+ }
+ return 0;
+ }
+
+
+}

0 comments on commit ef673c3

Please sign in to comment.