1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package ubic.basecode.ontology.model;
20
21 import ubic.basecode.ontology.OntologyUtil;
22
23 import com.hp.hpl.jena.rdf.model.RDFNode;
24 import com.hp.hpl.jena.rdf.model.Resource;
25 import com.hp.hpl.jena.rdf.model.Statement;
26 import com.hp.hpl.jena.rdf.model.impl.PropertyImpl;
27
28
29
30
31
32
33
34 public class AnnotationPropertyImpl implements AnnotationProperty {
35
36 private String contents;
37
38 private com.hp.hpl.jena.ontology.AnnotationProperty property;
39
40
41
42
43
44
45 public AnnotationPropertyImpl( com.hp.hpl.jena.ontology.AnnotationProperty prop, RDFNode object ) {
46 this.property = prop;
47
48 if ( object.isResource() ) {
49
50 Resource r = ( Resource ) object;
51 Statement s = r.getProperty( new PropertyImpl( "http://www.w3.org/2000/01/rdf-schema#label" ) );
52 if ( s != null ) {
53 this.contents = s.getObject().toString();
54 }
55 } else {
56 this.contents = OntologyUtil.asString( object );
57 }
58
59 }
60
61 @Override
62 public boolean equals( Object obj ) {
63 if ( this == obj ) return true;
64 if ( obj == null ) return false;
65 if ( getClass() != obj.getClass() ) return false;
66 final AnnotationPropertyImpl other = ( AnnotationPropertyImpl ) obj;
67 if ( contents == null ) {
68 if ( other.contents != null ) return false;
69 } else if ( !contents.equals( other.contents ) ) return false;
70 if ( property == null ) {
71 if ( other.property != null ) return false;
72 } else if ( !property.equals( other.property ) ) return false;
73 return true;
74 }
75
76 @Override
77 public String getContents() {
78 return contents;
79 }
80
81 @Override
82 public String getProperty() {
83 if ( property.getLabel( null ) != null ) {
84 return property.getLabel( null );
85 } else if ( property.getLocalName() != null ) {
86 return property.getLocalName();
87 } else {
88 return property.toString();
89 }
90 }
91
92 @Override
93 public int hashCode() {
94 final int PRIME = 31;
95 int result = 1;
96 result = PRIME * result + ( ( contents == null ) ? 0 : contents.hashCode() );
97 result = PRIME * result + ( ( property == null ) ? 0 : property.hashCode() );
98 return result;
99 }
100
101 @Override
102 public String toString() {
103 return property.getLocalName() + " " + contents;
104 }
105
106 }