Permalink
Browse files

Alpha version of the GexfWriter

  • Loading branch information...
1 parent f4a9981 commit c5fd84cffecebfe77a1041a5a9d02756a64e31af @jmcampanini committed Aug 4, 2010
Showing with 573 additions and 321 deletions.
  1. +1 −1 pom.xml
  2. +3 −0 src/main/java/com/ojn/gexf4j/core/Gexf.java
  3. +3 −2 src/main/java/com/ojn/gexf4j/core/Graph.java
  4. +2 −2 src/main/java/com/ojn/gexf4j/core/Node.java
  5. +6 −0 src/main/java/com/ojn/gexf4j/core/data/AttributeList.java
  6. +10 −0 src/main/java/com/ojn/gexf4j/core/data/AttributeValueList.java
  7. +1 −3 src/main/java/com/ojn/gexf4j/core/data/Datum.java
  8. +12 −0 src/main/java/com/ojn/gexf4j/core/impl/GexfImpl.java
  9. +8 −16 src/main/java/com/ojn/gexf4j/core/impl/GraphImpl.java
  10. +21 −6 src/main/java/com/ojn/gexf4j/core/impl/NodeImpl.java
  11. +5 −7 src/main/java/com/ojn/gexf4j/core/impl/SliceableDatumBase.java
  12. +5 −20 src/main/java/com/ojn/gexf4j/core/impl/StaxGraphReader.java
  13. +2 −2 src/main/java/com/ojn/gexf4j/core/impl/data/AttributeImpl.java
  14. +30 −0 src/main/java/com/ojn/gexf4j/core/impl/data/AttributeListImpl.java
  15. +1 −0 src/main/java/com/ojn/gexf4j/core/impl/data/AttributeValueImpl.java
  16. +34 −0 src/main/java/com/ojn/gexf4j/core/impl/data/AttributeValueListImpl.java
  17. +1 −1 src/main/java/com/ojn/gexf4j/core/impl/dynamic/DynamicBase.java
  18. +2 −8 src/main/java/com/ojn/gexf4j/core/impl/reader/EdgeEntityParser.java
  19. +2 −8 src/main/java/com/ojn/gexf4j/core/impl/reader/EdgesEntityParser.java
  20. +2 −6 src/main/java/com/ojn/gexf4j/core/impl/reader/GexfEntityParser.java
  21. +4 −9 src/main/java/com/ojn/gexf4j/core/impl/reader/GraphEntityParser.java
  22. +2 −11 src/main/java/com/ojn/gexf4j/core/impl/reader/MetaEntityParser.java
  23. +1 −1 src/main/java/com/ojn/gexf4j/core/impl/viz/NodeShapeImpl.java
  24. +5 −1 src/main/java/com/ojn/gexf4j/core/impl/writer/AbstractEntityWriter.java
  25. +14 −7 src/main/java/com/ojn/gexf4j/core/impl/writer/GexfEntityWriter.java
  26. +7 −2 src/main/java/com/ojn/gexf4j/core/impl/writer/GraphEntityWriter.java
  27. +4 −11 src/main/java/com/ojn/gexf4j/core/impl/writer/NodeEntityWriter.java
  28. +17 −11 src/test/java/com/ojn/gexf4j/core/GraphWriterTest.java
  29. +2 −2 src/test/java/com/ojn/gexf4j/core/impl/StaxGraphWriterTest.java
  30. +12 −15 src/test/java/com/ojn/gexf4j/core/testgraphs/BasicGraphBuilder.java
  31. +49 −45 src/test/java/com/ojn/gexf4j/core/testgraphs/DataGraphBuilder.java
  32. +100 −71 src/test/java/com/ojn/gexf4j/core/testgraphs/DynamicGraphBuilder.java
  33. +26 −0 src/test/java/com/ojn/gexf4j/core/testgraphs/GexfBuilder.java
  34. +0 −10 src/test/java/com/ojn/gexf4j/core/testgraphs/GraphBuilder.java
  35. +52 −0 src/test/java/com/ojn/gexf4j/core/testgraphs/HierarchyInlineBuilder.java
  36. +60 −0 src/test/java/com/ojn/gexf4j/core/testgraphs/HierarchyPIDBuilder.java
  37. +0 −43 src/test/java/com/ojn/gexf4j/core/testgraphs/MetaDataGraphBuilder.java
  38. +31 −0 src/test/java/com/ojn/gexf4j/core/testgraphs/PhylogenyBuilder.java
  39. +36 −0 src/test/java/com/ojn/gexf4j/core/testgraphs/VisualizationBuilder.java
View
@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.ojn.gexf4j</groupId>
<artifactId>gexf4j-core</artifactId>
- <version>0.1.0</version>
+ <version>0.2.0-ALPHA</version>
<name>gexf4j-core</name>
<build>
<plugins>
@@ -12,4 +12,7 @@
Metadata getMetadata();
Graph getGraph();
+
+ boolean hasVisualization();
+ Gexf setVisualization(boolean viz);
}
@@ -1,5 +1,7 @@
package com.ojn.gexf4j.core;
+import java.util.List;
+
import com.ojn.gexf4j.core.data.AttributeList;
import com.ojn.gexf4j.core.dynamic.Dynamic;
import com.ojn.gexf4j.core.dynamic.TimeType;
@@ -18,6 +20,5 @@
TimeType getTimeType();
Graph setTimeType(TimeType timeType);
- AttributeList getNodeAttributes();
- AttributeList getEdgeAttributes();
+ List<AttributeList> getAttributeLists();
}
@@ -43,6 +43,6 @@
boolean hasPID();
Node clearPID();
- Node getPID();
- Node setPID(Node pid);
+ String getPID();
+ Node setPID(String pid);
}
@@ -11,4 +11,10 @@
Mode getMode();
AttributeList setMode(Mode mode);
+
+ Attribute createAttribute(AttributeType type, String title);
+ Attribute createAttribute(String id, AttributeType type, String title);
+
+ AttributeList addAttribute(AttributeType type, String title);
+ AttributeList addAttribute(String id, AttributeType type, String title);
}
@@ -0,0 +1,10 @@
+package com.ojn.gexf4j.core.data;
+
+import java.util.List;
+
+public interface AttributeValueList extends List<AttributeValue> {
+
+ AttributeValueList addValue(Attribute attribute, String value);
+
+ AttributeValue createValue(Attribute attribute, String value);
+}
@@ -1,8 +1,6 @@
package com.ojn.gexf4j.core.data;
-import java.util.List;
-
public interface Datum {
- List<AttributeValue> getAttributeValues();
+ AttributeValueList getAttributeValues();
}
@@ -13,6 +13,7 @@
private String variant = null;
private Graph graph = null;
private Metadata meta = null;
+ private boolean viz = false;
public GexfImpl() {
graph = new GraphImpl();
@@ -58,4 +59,15 @@ public Gexf setVariant(String variant) {
this.variant = variant;
return this;
}
+
+ @Override
+ public boolean hasVisualization() {
+ return viz;
+ }
+
+ @Override
+ public Gexf setVisualization(boolean viz) {
+ this.viz = viz;
+ return this;
+ }
}
@@ -12,25 +12,21 @@
import com.ojn.gexf4j.core.IDType;
import com.ojn.gexf4j.core.Mode;
import com.ojn.gexf4j.core.Node;
-import com.ojn.gexf4j.core.data.AttributeClass;
import com.ojn.gexf4j.core.data.AttributeList;
import com.ojn.gexf4j.core.dynamic.TimeType;
-import com.ojn.gexf4j.core.impl.data.AttributeListImpl;
import com.ojn.gexf4j.core.impl.dynamic.DynamicBase;
public class GraphImpl extends DynamicBase<Graph> implements Graph {
private EdgeType edgeType = EdgeType.UNDIRECTED;
- private AttributeList edgeAttributeList = null;
- private AttributeList nodeAttributeList = null;
+ private List<AttributeList> attributeLists = null;
private IDType idType = IDType.STRING;
private Mode mode = Mode.STATIC;
private List<Node> nodes = null;
private TimeType timeType = TimeType.DATE;
public GraphImpl() {
- edgeAttributeList = new AttributeListImpl(AttributeClass.EDGE);
- nodeAttributeList = new AttributeListImpl(AttributeClass.NODE);
+ attributeLists = new ArrayList<AttributeList>();
nodes = new ArrayList<Node>();
}
@@ -44,11 +40,6 @@ public EdgeType getDefaultEdgeType() {
return edgeType;
}
- @Override
- public AttributeList getEdgeAttributes() {
- return edgeAttributeList;
- }
-
@Override
public IDType getIDType() {
return idType;
@@ -59,11 +50,6 @@ public Mode getMode() {
return mode;
}
- @Override
- public AttributeList getNodeAttributes() {
- return nodeAttributeList;
- }
-
@Override
public TimeType getTimeType() {
return timeType;
@@ -114,6 +100,7 @@ public Node createNode(String id) {
for (Node n : nodes) {
rv.addAll(n.getEdges());
+ rv.addAll(n.getAllEdges());
}
return rv;
@@ -123,4 +110,9 @@ public Node createNode(String id) {
public List<Node> getNodes() {
return nodes;
}
+
+ @Override
+ public List<AttributeList> getAttributeLists() {
+ return attributeLists;
+ }
}
@@ -9,7 +9,9 @@
import com.ojn.gexf4j.core.Edge;
import com.ojn.gexf4j.core.Node;
+import com.ojn.gexf4j.core.impl.viz.NodeShapeImpl;
import com.ojn.gexf4j.core.viz.Color;
+import com.ojn.gexf4j.core.viz.NodeShape;
import com.ojn.gexf4j.core.viz.NodeShapeEntity;
import com.ojn.gexf4j.core.viz.Position;
@@ -18,7 +20,7 @@
private String id = "";
private String label = "";
private Color color = null;
- private Node pid = null;
+ private String pid = null;
private Position position = null;
private NodeShapeEntity shape = null;
private float size = Float.MIN_VALUE;
@@ -38,6 +40,7 @@ public NodeImpl(String id) {
this.nodes = new ArrayList<Node>();
this.edges = new ArrayList<Edge>();
this.parentForList = new ArrayList<Node>();
+ this.shape = new NodeShapeImpl();
}
@Override
@@ -109,7 +112,7 @@ public String getLabel() {
}
@Override
- public Node getPID() {
+ public String getPID() {
checkState(hasPID(), "PID has not been set.");
return pid;
}
@@ -127,7 +130,6 @@ public Position getPosition() {
@Override
public NodeShapeEntity getShapeEntity() {
- checkState(hasShape(), "Shape has not been set.");
return shape;
}
@@ -149,7 +151,7 @@ public boolean hasPosition() {
@Override
public boolean hasShape() {
- return (shape != null);
+ return (shape.getNodeShape() != NodeShape.NOTSET);
}
@Override
@@ -165,8 +167,9 @@ public Node setLabel(String label) {
}
@Override
- public Node setPID(Node pid) {
+ public Node setPID(String pid) {
checkArgument(pid != null, "PID cannot be null.");
+ checkArgument(!pid.trim().isEmpty(), "PID cannot be empty or blank.");
this.pid = pid;
return this;
}
@@ -240,9 +243,21 @@ public Node createNode(String id) {
List<Edge> rv = new ArrayList<Edge>();
for (Node n : getNodes()) {
- rv.addAll(n.getEdges());
+ _getEdges(rv, n);
}
return rv;
}
+
+ private List<Edge> _getEdges(List<Edge> soFar, Node n) {
+ // add the nodes' edges
+ soFar.addAll(n.getEdges());
+
+ // call this function on all of the sub nodes
+ for (Node subNode : n.getNodes()) {
+ _getEdges(soFar, subNode);
+ }
+
+ return soFar;
+ }
}
@@ -1,22 +1,20 @@
package com.ojn.gexf4j.core.impl;
-import java.util.ArrayList;
-import java.util.List;
-
import com.ojn.gexf4j.core.SlicableDatum;
-import com.ojn.gexf4j.core.data.AttributeValue;
+import com.ojn.gexf4j.core.data.AttributeValueList;
+import com.ojn.gexf4j.core.impl.data.AttributeValueListImpl;
import com.ojn.gexf4j.core.impl.dynamic.SlicableBase;
public abstract class SliceableDatumBase<T extends Object> extends SlicableBase<T> implements SlicableDatum<T> {
- private List<AttributeValue> attributes = null;
+ private AttributeValueList attributes = null;
public SliceableDatumBase() {
- attributes = new ArrayList<AttributeValue>();
+ attributes = new AttributeValueListImpl();
}
@Override
- public List<AttributeValue> getAttributeValues() {
+ public AttributeValueList getAttributeValues() {
return attributes;
}
}
@@ -3,30 +3,15 @@
import java.io.IOException;
import java.io.InputStream;
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-
-import com.ojn.gexf4j.core.Graph;
+import com.ojn.gexf4j.core.Gexf;
import com.ojn.gexf4j.core.GexfReader;
-import com.ojn.gexf4j.core.impl.reader.GexfEntityParser;
public class StaxGraphReader implements GexfReader {
@Override
- public Graph readFromStream(InputStream in) throws IOException {
-
- try {
- XMLInputFactory inputFactory = XMLInputFactory.newInstance();
- XMLStreamReader reader = inputFactory.createXMLStreamReader(in);
-
- GexfEntityParser gexfParser = new GexfEntityParser(reader);
-
- return gexfParser.getGraph();
-
- } catch (XMLStreamException e) {
- e.printStackTrace();
- return null;
- }
+ public Gexf readFromStream(InputStream in) throws IOException {
+ // TODO Auto-generated method stub
+ return null;
}
+
}
@@ -20,9 +20,9 @@
public AttributeImpl(String id, AttributeType type, String title) {
checkArgument(id != null, "ID cannot be null.");
- checkArgument(id.trim().isEmpty(), "ID cannot be null or blank.");
+ checkArgument(!id.trim().isEmpty(), "ID cannot be empty or blank.");
checkArgument(title != null, "Title cannot be null.");
- checkArgument(title.trim().isEmpty(), "Title cannot be null or blank.");
+ checkArgument(!title.trim().isEmpty(), "Title cannot be null or blank.");
this.id = id;
this.type = type;
@@ -5,11 +5,13 @@
import java.util.ArrayList;
import java.util.Date;
+import java.util.UUID;
import com.ojn.gexf4j.core.Mode;
import com.ojn.gexf4j.core.data.Attribute;
import com.ojn.gexf4j.core.data.AttributeClass;
import com.ojn.gexf4j.core.data.AttributeList;
+import com.ojn.gexf4j.core.data.AttributeType;
public class AttributeListImpl extends ArrayList<Attribute> implements AttributeList {
private static final long serialVersionUID = 8240096318919688740L;
@@ -90,4 +92,32 @@ public AttributeList setStartDate(Date startDate) {
this.endDate = startDate;
return this;
}
+
+ @Override
+ public Attribute createAttribute(AttributeType type, String title) {
+ return createAttribute(UUID.randomUUID().toString(), type, title);
+ }
+
+ @Override
+ public Attribute createAttribute(String id, AttributeType type, String title) {
+ checkArgument(id != null, "ID cannot be null.");
+ checkArgument(!id.trim().isEmpty(), "ID cannot be empty or blank.");
+ checkArgument(title != null, "Title cannot be null.");
+ checkArgument(!title.trim().isEmpty(), "Title cannot be empty or blank.");
+
+ Attribute rv = new AttributeImpl(id, type, title);
+ this.add(rv);
+ return rv;
+ }
+
+ @Override
+ public AttributeList addAttribute(AttributeType type, String title) {
+ return addAttribute(UUID.randomUUID().toString(), type, title);
+ }
+
+ @Override
+ public AttributeList addAttribute(String id, AttributeType type, String title) {
+ createAttribute(id, type, title);
+ return this;
+ }
}
@@ -34,6 +34,7 @@ public String getValue() {
@Override
public AttributeValue setValue(String value) {
checkArgument(value != null, "Value cannot be null.");
+ this.value = value;
return this;
}
}
Oops, something went wrong.

0 comments on commit c5fd84c

Please sign in to comment.