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