01: package org.ontoware.rdf2go.model.node.impl;
02:
03: import org.ontoware.rdf2go.model.node.BlankNode;
04: import org.ontoware.rdf2go.model.node.DatatypeLiteral;
05: import org.ontoware.rdf2go.model.node.LanguageTagLiteral;
06: import org.ontoware.rdf2go.model.node.Node;
07: import org.ontoware.rdf2go.model.node.PlainLiteral;
08: import org.ontoware.rdf2go.model.node.URI;
09:
10: public class NodeUtils {
11:
12: /**
13: * The following sorting order is defined by different Node types: URI >
14: * BlankNode > PlainLiteral > LnaguageTaggedLiteral > DatatypedLiteral
15: */
16: public static int compareByType(Node a, Node b) {
17: if (a instanceof URI) {
18: if (b instanceof URI)
19: return 0;
20: return 1;
21: } else if (a instanceof BlankNode) {
22: if (b instanceof URI)
23: return -1;
24: if (b instanceof BlankNode)
25: return 0;
26: return 1;
27:
28: } else if (a instanceof PlainLiteral) {
29: if (b instanceof URI || b instanceof BlankNode)
30: return -1;
31: if (b instanceof PlainLiteral)
32: return 0;
33: return 1;
34: } else if (a instanceof LanguageTagLiteral) {
35: if (b instanceof URI || b instanceof BlankNode
36: || b instanceof PlainLiteral)
37: return -1;
38: if (b instanceof LanguageTagLiteral)
39: return 0;
40: return 1;
41: } else if (a instanceof DatatypeLiteral) {
42: if (b instanceof URI || b instanceof BlankNode
43: || b instanceof PlainLiteral
44: || b instanceof LanguageTagLiteral)
45: return -1;
46: if (b instanceof DatatypeLiteral)
47: return 0;
48: throw new IllegalArgumentException();
49: } else
50: throw new IllegalArgumentException();
51:
52: }
53: }
|