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