changeset 2308:ba8428eae57f

Another small tweak of the Graph API review-thread: http://icedtea.classpath.org/pipermail/thermostat/2016-May/018851.html reviewed-by: jerboaa
author Mario Torre <neugens.limasoftware@gmail.com>
date Tue, 24 May 2016 11:09:57 +0200
parents 6cf7ebdafb46
children 7cb8987aa6bc
files platform/collections/src/main/java/com/redhat/thermostat/collections/graph/Graph.java platform/collections/src/main/java/com/redhat/thermostat/collections/graph/Relationship.java
diffstat 2 files changed, 23 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/platform/collections/src/main/java/com/redhat/thermostat/collections/graph/Graph.java	Fri May 20 17:09:05 2016 +0200
+++ b/platform/collections/src/main/java/com/redhat/thermostat/collections/graph/Graph.java	Tue May 24 11:09:57 2016 +0200
@@ -40,7 +40,9 @@
 import java.util.Set;
 
 /**
- * A simple interface defining methods for a general purpose Graph.
+ * A simple interface defining methods for a general purpose Graph where
+ * the {@code Vertices} in the Graph are represented by {@link Node}s and the
+ * {@code Edges} are the {@link Relationship}s between them.
  */
 public interface Graph extends Iterable<Node> {
 
@@ -61,13 +63,17 @@
     boolean addRelationship(Relationship relationship);
 
     /**
-     * Returns the size of this Graph. The size is intended as the number of
-     * {@link Relationship}s contained in the Graph.
+     * Returns the size of this Graph. The size of a Graph is the number of
+     * {@link Relationship}s contained in the Graph, not the number of
+     * {@link Node}s. A Graph with size of zero may still
+     * contain a number of not-connected Nodes. Such Graph is considered empty
+     * and is referred to as Null-Graph or Edgeless.
      */
     int size();
 
     /**
      * Returns the order, or the number of {@link Node}s, of this Graph.
+     * A Zero-Order Graph is an empty graph with no Nodes and no Relationships.
      */
     int order();
 
--- a/platform/collections/src/main/java/com/redhat/thermostat/collections/graph/Relationship.java	Fri May 20 17:09:05 2016 +0200
+++ b/platform/collections/src/main/java/com/redhat/thermostat/collections/graph/Relationship.java	Tue May 24 11:09:57 2016 +0200
@@ -39,6 +39,10 @@
 import java.util.HashMap;
 import java.util.Map;
 
+/**
+ * A class abstracting a connection between two {@link Node}s, such as an Edge
+ * in a Graph.
+ */
 public class Relationship {
     
     public static final String NAME = "name";
@@ -67,7 +71,16 @@
     public final String getName() {
         return (String) properties.get(NAME);
     }
-    
+
+    @SuppressWarnings("unchecked")
+    public <E> E getProperty(String propertyName) {
+        return (E) properties.get(propertyName);
+    }
+
+    public Map<String, Object> getProperties() {
+        return properties;
+    }
+
     public Node getFrom() {
         return from;
     }