01: /*
02: * LICENSE INFORMATION
03: * Copyright 2005-2007 by FZI (http://www.fzi.de).
04: * Licensed under a BSD license (http://www.opensource.org/licenses/bsd-license.php)
05: * <OWNER> = Max Völkel
06: * <ORGANIZATION> = FZI Forschungszentrum Informatik Karlsruhe, Karlsruhe, Germany
07: * <YEAR> = 2007
08: *
09: * Project information at http://semweb4j.org/rdf2go
10: */
11: package org.ontoware.rdf2go.model.impl;
12:
13: import java.util.Arrays;
14:
15: import org.ontoware.rdf2go.model.Statement;
16: import org.slf4j.Logger;
17: import org.slf4j.LoggerFactory;
18:
19: public abstract class AbstractStatement implements Statement {
20:
21: @SuppressWarnings("unused")
22: private static Logger log = LoggerFactory
23: .getLogger(StatementImpl.class);
24:
25: public void dump(String[] options) {
26: boolean sysout = true;
27: boolean _log = false;
28: if (options != null) {
29: sysout = Arrays.asList(options).contains("sysout");
30: _log = Arrays.asList(options).contains("log");
31: }
32:
33: String s = this .toString();
34: if (sysout)
35: System.out.println(s);
36: if (_log)
37: log.debug(s);
38: }
39:
40: @Override
41: public boolean equals(Object o) {
42: if (o instanceof Statement) {
43: Statement oStmt = (Statement) o;
44: boolean subjects = this .getSubject().equals(
45: oStmt.getSubject());
46: if (!subjects)
47: log.debug("Subjects differ: " + this .getSubject()
48: + " vs " + oStmt.getSubject());
49: boolean predicates = this .getPredicate().equals(
50: oStmt.getPredicate());
51: if (!predicates)
52: log.debug("Prediactes differ: " + this .getPredicate()
53: + " vs " + oStmt.getPredicate());
54: boolean objects = this .getObject()
55: .equals(oStmt.getObject());
56: if (!objects)
57: log.debug("Objects differ: " + this .getObject()
58: + " vs " + oStmt.getObject());
59: return subjects && predicates && objects;
60: }
61: //else
62: return false;
63: }
64:
65: @Override
66: public int hashCode() {
67: return this .getSubject().hashCode()
68: + this .getPredicate().hashCode()
69: + this .getObject().hashCode();
70: }
71:
72: public int compareTo(Statement o) {
73: log.debug("Comparing " + this + " to " + o);
74: if (this .getSubject().equals(o.getSubject())) {
75: if (this .getPredicate().equals(o.getPredicate()))
76: // only objects differ (maybe)
77: return this .getObject().compareTo(o.getObject());
78: // else: difference is in prediactes (maybe objects, too)
79: return this .getPredicate().compareTo(o.getPredicate());
80: }
81: //else: subjects differ
82: return this .getSubject().compareTo(o.getSubject());
83: }
84:
85: public boolean matches(Statement statement) {
86: return equals(statement);
87: }
88: }
|