22 |
package nongnu.cashews.rdf; |
package nongnu.cashews.rdf; |
23 |
|
|
24 |
import java.io.Serializable; |
import java.io.Serializable; |
25 |
|
import java.util.HashSet; |
26 |
import java.util.Set; |
import java.util.Set; |
27 |
|
|
28 |
/** |
/** |
56 |
private Set<Triple> graph; |
private Set<Triple> graph; |
57 |
|
|
58 |
/** |
/** |
59 |
|
* Constructs a new empty graph. |
60 |
|
*/ |
61 |
|
public Graph() |
62 |
|
{ |
63 |
|
graph = new HashSet<Triple>(); |
64 |
|
} |
65 |
|
|
66 |
|
/** |
67 |
* Returns true if the specified object is either of type <code>Graph</code>, |
* Returns true if the specified object is either of type <code>Graph</code>, |
68 |
* or a sub-type, and contains an equivalent set of triples. If the specified |
* or a sub-type, and contains an equivalent set of triples. If the specified |
69 |
* object is null, false is returned. |
* object is null, false is returned. |
97 |
} |
} |
98 |
|
|
99 |
/** |
/** |
100 |
* Returns the graph of RDF triples. |
* Returns a clone of the graph of RDF triples. |
101 |
* |
* |
102 |
* @return a graph of RDF triples. |
* @return a clone of the RDF triple graph. |
103 |
*/ |
*/ |
104 |
public Set<Triple> getGraph() |
public Set<Triple> getGraph() |
105 |
{ |
{ |
106 |
return graph; |
Set<Triple> clonedSet = new HashSet<Triple>(); |
107 |
|
for (Triple triple : graph) |
108 |
|
clonedSet.add(triple.clone()); |
109 |
|
return clonedSet; |
110 |
|
} |
111 |
|
|
112 |
|
/** |
113 |
|
* Adds a triple to the graph. |
114 |
|
* |
115 |
|
* @param triple the triple to add. |
116 |
|
*/ |
117 |
|
public void addTriple(Triple triple) |
118 |
|
{ |
119 |
|
graph.add(triple); |
120 |
} |
} |
121 |
|
|
122 |
|
/** |
123 |
|
* Returns a textual representation of the graph. |
124 |
|
* |
125 |
|
* @return a textual representation. |
126 |
|
*/ |
127 |
|
public String toString() |
128 |
|
{ |
129 |
|
return getClass().getName() + |
130 |
|
"[graph = " + |
131 |
|
graph + |
132 |
|
"]"; |
133 |
|
} |
134 |
|
|
135 |
} |
} |