1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package ubic.basecode.ontology.jena;
20
21 import com.hp.hpl.jena.rdf.model.RDFNode;
22 import com.hp.hpl.jena.rdf.model.Resource;
23 import com.hp.hpl.jena.rdf.model.Statement;
24 import com.hp.hpl.jena.vocabulary.RDFS;
25 import ubic.basecode.ontology.jena.vocabulary.OBO;
26 import ubic.basecode.ontology.model.AnnotationProperty;
27
28 import javax.annotation.Nullable;
29
30
31
32
33
34
35 public class AnnotationPropertyImpl extends AbstractOntologyResource implements AnnotationProperty {
36
37 private final String contents;
38
39 private final com.hp.hpl.jena.ontology.AnnotationProperty property;
40
41
42
43
44
45
46 public AnnotationPropertyImpl( com.hp.hpl.jena.ontology.AnnotationProperty prop, @Nullable RDFNode object ) {
47 super( prop );
48 this.property = prop;
49
50 if ( object == null ) {
51 this.contents = null;
52 } else if ( object.isResource() ) {
53
54 Resource r = ( Resource ) object;
55 Statement s = r.getProperty( RDFS.label );
56 if ( s != null ) {
57 this.contents = s.getObject().toString();
58 } else {
59 this.contents = null;
60 }
61 } else {
62 this.contents = JenaUtils.asString( object );
63 }
64
65 }
66
67 @Override
68 public boolean equals( @Nullable Object obj ) {
69 if ( this == obj ) return true;
70 if ( obj == null ) return false;
71 if ( getClass() != obj.getClass() ) return false;
72 final AnnotationPropertyImpl/basecode/ontology/jena/AnnotationPropertyImpl.html#AnnotationPropertyImpl">AnnotationPropertyImpl other = ( AnnotationPropertyImpl ) obj;
73 if ( contents == null ) {
74 if ( other.contents != null ) return false;
75 } else if ( !contents.equals( other.contents ) ) return false;
76 if ( property == null ) {
77 if ( other.property != null ) return false;
78 } else if ( !property.equals( other.property ) ) return false;
79 return true;
80 }
81
82 @Override
83 public String getUri() {
84 return property.getURI();
85 }
86
87 @Override
88 public String getContents() {
89 return contents;
90 }
91
92 @Override
93 public String getProperty() {
94 if ( property.getLabel( null ) != null ) {
95 return property.getLabel( null );
96 } else if ( property.getLocalName() != null ) {
97 return property.getLocalName();
98 } else {
99 return property.toString();
100 }
101 }
102
103 @Override
104 public boolean isObsolete() {
105 return super.isObsolete() || property.hasSuperProperty( OBO.ObsoleteProperty, false );
106 }
107
108 @Override
109 public int hashCode() {
110 final int PRIME = 31;
111 int result = 1;
112 result = PRIME * result + ( ( contents == null ) ? 0 : contents.hashCode() );
113 result = PRIME * result + ( ( property == null ) ? 0 : property.hashCode() );
114 return result;
115 }
116
117 @Override
118 public String toString() {
119 return property.getLocalName() + " " + contents;
120 }
121
122 }