forked from graphaware/neo4j-timetree
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 45b151d
Showing
15 changed files
with
2,115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.buildpath | ||
.project | ||
.settings | ||
target/ | ||
.idea/ | ||
*.class | ||
*.iml | ||
*.iws | ||
*.ipr | ||
*.db | ||
.DS_Store | ||
.classpath |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
language: java |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<!-- | ||
~ Copyright (c) 2014 GraphAware | ||
~ | ||
~ This file is part of GraphAware. | ||
~ | ||
~ GraphAware is free software: you can redistribute it and/or modify it under the terms of | ||
~ the GNU General Public License as published by the Free Software Foundation, either | ||
~ version 3 of the License, or (at your option) any later version. | ||
~ | ||
~ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
~ without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
~ See the GNU General Public License for more details. You should have received a copy of | ||
~ the GNU General Public License along with this program. If not, see | ||
~ <http://www.gnu.org/licenses/>. | ||
--> | ||
|
||
<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/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>timetree</artifactId> | ||
<version>2.0.3.1.1-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<parent> | ||
<groupId>com.graphaware.neo4j</groupId> | ||
<artifactId>framework-parent</artifactId> | ||
<version>2.0.3.1</version> | ||
</parent> | ||
|
||
<name>GraphAware TimeTree Module</name> | ||
<description>GraphAware Framework Module for creating a time tree for representing time series data</description> | ||
<url>http://graphaware.com</url> | ||
|
||
<licenses> | ||
<license> | ||
<name>GNU General Public License, version 3</name> | ||
<url>http://www.gnu.org/licenses/gpl-3.0.txt</url> | ||
<distribution>repo</distribution> | ||
</license> | ||
</licenses> | ||
|
||
<scm> | ||
<connection>scm:git:[email protected]:graphaware/timetree.git</connection> | ||
<developerConnection>scm:git:[email protected]:graphaware/timetree.git</developerConnection> | ||
<url>[email protected]:graphaware/timetree.git</url> | ||
</scm> | ||
|
||
<developers> | ||
<developer> | ||
<id>bachmanm</id> | ||
<name>Michal Bachman</name> | ||
<email>[email protected]</email> | ||
</developer> | ||
</developers> | ||
|
||
<dependencies> | ||
|
||
<!-- GraphAware Framework --> | ||
<dependency> | ||
<groupId>com.graphaware.neo4j</groupId> | ||
<artifactId>common</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.graphaware.neo4j</groupId> | ||
<artifactId>api</artifactId> | ||
</dependency> | ||
|
||
<!-- Spring Framework --> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-webmvc</artifactId> | ||
</dependency> | ||
|
||
<!-- Neo4j --> | ||
<dependency> | ||
<groupId>org.neo4j</groupId> | ||
<artifactId>neo4j</artifactId> | ||
</dependency> | ||
|
||
<!-- Joda --> | ||
<dependency> | ||
<groupId>joda-time</groupId> | ||
<artifactId>joda-time</artifactId> | ||
</dependency> | ||
|
||
<!-- Testing --> | ||
<dependency> | ||
<groupId>com.graphaware.neo4j</groupId> | ||
<artifactId>server-community</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.graphaware.neo4j</groupId> | ||
<artifactId>tests</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
115 changes: 115 additions & 0 deletions
115
src/main/java/com/graphaware/module/timetree/Resolution.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* Copyright (c) 2014 GraphAware | ||
* | ||
* This file is part of GraphAware. | ||
* | ||
* GraphAware is free software: you can redistribute it and/or modify it under the terms of | ||
* the GNU General Public License as published by the Free Software Foundation, either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the GNU General Public License for more details. You should have received a copy of | ||
* the GNU General Public License along with this program. If not, see | ||
* <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.graphaware.module.timetree; | ||
|
||
import org.apache.log4j.Logger; | ||
import org.joda.time.DateTimeFieldType; | ||
import org.neo4j.graphdb.Label; | ||
import org.neo4j.graphdb.Node; | ||
|
||
/** | ||
* Resolution of a {@link TimeTree}. | ||
*/ | ||
public enum Resolution { | ||
|
||
YEAR(TimeTreeLabels.Year, DateTimeFieldType.year()), | ||
MONTH(TimeTreeLabels.Month, DateTimeFieldType.monthOfYear()), | ||
DAY(TimeTreeLabels.Day, DateTimeFieldType.dayOfMonth()), | ||
HOUR(TimeTreeLabels.Hour, DateTimeFieldType.hourOfDay()), | ||
MINUTE(TimeTreeLabels.Minute, DateTimeFieldType.minuteOfHour()), | ||
SECOND(TimeTreeLabels.Second, DateTimeFieldType.secondOfMinute()), | ||
MILLISECOND(TimeTreeLabels.Millisecond, DateTimeFieldType.millisOfSecond()); | ||
|
||
private static final Logger LOG = Logger.getLogger(Resolution.class); | ||
|
||
private final Label label; | ||
private final DateTimeFieldType dateTimeFieldType; | ||
|
||
private Resolution(Label label, DateTimeFieldType dateTimeFieldType) { | ||
this.label = label; | ||
this.dateTimeFieldType = dateTimeFieldType; | ||
} | ||
|
||
/** | ||
* Get the label corresponding to this resolution level. Nodes representing the level will get this label. | ||
* | ||
* @return label. | ||
*/ | ||
public Label getLabel() { | ||
return label; | ||
} | ||
|
||
/** | ||
* Get the {@link DateTimeFieldType} corresponding to this resolution level. | ||
* | ||
* @return field type. | ||
*/ | ||
public DateTimeFieldType getDateTimeFieldType() { | ||
return dateTimeFieldType; | ||
} | ||
|
||
/** | ||
* Get the resolution one level below this resolution. | ||
* | ||
* @return child resolution. | ||
* @throws IllegalStateException if this resolution does not have children. | ||
*/ | ||
public Resolution getChild() { | ||
if (this.ordinal() >= values().length - 1) { | ||
LOG.error("Parent resolution " + this.toString() + " does not have children. This is a bug."); | ||
throw new IllegalStateException("Parent resolution " + this.toString() + " does not have children. This is a bug."); | ||
} | ||
|
||
return values()[this.ordinal() + 1]; | ||
} | ||
|
||
/** | ||
* Find the resolution level that the given node corresponds to. The node must be from a GraphAware TimeTree and must | ||
* not be the root of the tree. | ||
* | ||
* @param node to find resolution for. | ||
* @return resolution. | ||
* @throws IllegalArgumentException in case the given node is not from GraphAware TimeTree or is the root. | ||
*/ | ||
public static Resolution findForNode(Node node) { | ||
for (Label label : node.getLabels()) { | ||
Resolution resolution = findForLabel(label); | ||
if (resolution != null) { | ||
return resolution; | ||
} | ||
} | ||
|
||
LOG.error("Node " + node.toString() + " does not have a corresponding resolution. This is a bug."); | ||
throw new IllegalArgumentException("Node " + node.toString() + " does not have a corresponding resolution. This is a bug."); | ||
} | ||
|
||
/** | ||
* Find the resolution corresponding to the given label. | ||
* | ||
* @param label to find the resolution for. | ||
* @return resolution for label, null if there is no corresponding resolution. | ||
*/ | ||
private static Resolution findForLabel(Label label) { | ||
for (Resolution resolution : values()) { | ||
if (resolution.getLabel().name().equals(label.name())) { | ||
return resolution; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} |
122 changes: 122 additions & 0 deletions
122
src/main/java/com/graphaware/module/timetree/TimeTree.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* | ||
* Copyright (c) 2014 GraphAware | ||
* | ||
* This file is part of GraphAware. | ||
* | ||
* GraphAware is free software: you can redistribute it and/or modify it under the terms of | ||
* the GNU General Public License as published by the Free Software Foundation, either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the GNU General Public License for more details. You should have received a copy of | ||
* the GNU General Public License along with this program. If not, see | ||
* <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.graphaware.module.timetree; | ||
|
||
import org.joda.time.DateTimeZone; | ||
import org.neo4j.graphdb.Node; | ||
|
||
/** | ||
* API for representing time as a tree (also called GraphAware TimeTree). Provides methods for creating and retrieving | ||
* nodes that represent instances of time, making sure that a tree of time is maintained with each created node. | ||
* There is no support for changes or deletes. | ||
*/ | ||
public interface TimeTree { | ||
|
||
/** | ||
* Get a node representing this time instant. If one doesn't exist, it will be created. | ||
* <p/> | ||
* The resolution of the time instant (i.e., whether it is a day, hour, minute, etc.) depends on the implementation, | ||
* which can choose a sensible default, require to be configured with a default when instantiated, or both. | ||
* <p/> | ||
* The time zone of the time instant depends on the implementation, which can choose a default, require to be | ||
* configured with a default when instantiated, or both. | ||
* | ||
* @return node representing the time instant when this method was called. | ||
*/ | ||
Node getNow(); | ||
|
||
/** | ||
* Get a node representing this time instant. If one doesn't exist, it will be created. | ||
* <p/> | ||
* The resolution of the time instant (i.e., whether it is a day, hour, minute, etc.) depends on the implementation, | ||
* which can choose a sensible default, require to be configured with a default when instantiated, or both. | ||
* | ||
* @param timeZone specific time zone. | ||
* @return node representing the time instant when this method was called. | ||
*/ | ||
Node getNow(DateTimeZone timeZone); | ||
|
||
/** | ||
* Get a node representing this time instant. If one doesn't exist, it will be created. | ||
* <p/> | ||
* The time zone of the time instant depends on the implementation, which can choose a default, require to be | ||
* configured with a default when instantiated, or both. | ||
* | ||
* @param resolution specific resolution. | ||
* @return node representing the time instant when this method was called. | ||
*/ | ||
Node getNow(Resolution resolution); | ||
|
||
/** | ||
* Get a node representing this time instant. If one doesn't exist, it will be created. | ||
* | ||
* @param timeZone specific time zone. | ||
* @param resolution specific resolution. | ||
* @return node representing the time instant when this method was called. | ||
*/ | ||
Node getNow(DateTimeZone timeZone, Resolution resolution); | ||
|
||
/** | ||
* Get a node representing a specific time instant. If one doesn't exist, it will be created. | ||
* <p/> | ||
* The resolution of the time instant (i.e., whether it is a day, hour, minute, etc.) depends on the implementation, | ||
* which can choose a sensible default, require to be configured with a default when instantiated, or both. | ||
* <p/> | ||
* The time zone of the time instant depends on the implementation, which can choose a default, require to be | ||
* configured with a default when instantiated, or both. | ||
* | ||
* @param time UTC time in ms from 1/1/1970. | ||
* @return node representing a specific time instant. | ||
*/ | ||
Node getInstant(long time); | ||
|
||
/** | ||
* Get a node representing a specific time instant. If one doesn't exist, it will be created. | ||
* <p/> | ||
* The resolution of the time instant (i.e., whether it is a day, hour, minute, etc.) depends on the implementation, | ||
* which can choose a sensible default, require to be configured with a default when instantiated, or both. | ||
* | ||
* @param time UTC time in ms from 1/1/1970. | ||
* @param timeZone specific time zone. | ||
* @return node representing a specific time instant. | ||
*/ | ||
Node getInstant(long time, DateTimeZone timeZone); | ||
|
||
/** | ||
* Get a node representing a specific time instant. If one doesn't exist, it will be created. | ||
* <p/> | ||
* The time zone of the time instant depends on the implementation, which can choose a default, require to be | ||
* configured with a default when instantiated, or both. | ||
* | ||
* @param time UTC time in ms from 1/1/1970. | ||
* @param resolution specific resolution. | ||
* @return node representing a specific time instant. | ||
*/ | ||
Node getInstant(long time, Resolution resolution); | ||
|
||
/** | ||
* Get a node representing a specific time instant. If one doesn't exist, it will be created. | ||
* | ||
* @param time UTC time in ms from 1/1/1970. | ||
* @param timeZone specific time zone. | ||
* @param resolution specific resolution. | ||
* @return node representing a specific time instant. | ||
*/ | ||
Node getInstant(long time, DateTimeZone timeZone, Resolution resolution); | ||
|
||
|
||
} |
Oops, something went wrong.