Skip to content
This repository
Browse code

first commit

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

0 notes on commit ef673c3

Please sign in to comment.
Something went wrong with that request. Please try again.