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 import java.util.Objects;
29
30
31
32
33
34
35 class AnnotationPropertyImpl extends AbstractOntologyResource implements AnnotationProperty {
36
37 private final com.hp.hpl.jena.ontology.AnnotationProperty property;
38 @Nullable
39 private final RDFNode object;
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 this.object = object;
49 }
50
51 @Override
52 public String getProperty() {
53 if ( property.getLabel( null ) != null ) {
54 return property.getLabel( null );
55 } else if ( property.getLocalName() != null ) {
56 return property.getLocalName();
57 } else {
58 return property.toString();
59 }
60 }
61
62 @Override
63 public String getContents() {
64 if ( this.object == null ) {
65 return null;
66 } else if ( object.isResource() ) {
67
68 Resource r = ( Resource ) object;
69 Statement s = r.getProperty( RDFS.label );
70 if ( s != null ) {
71 return s.getObject().toString();
72 } else {
73 return null;
74 }
75 } else {
76 return JenaUtils.asString( object );
77 }
78 }
79
80 @Override
81 public boolean isObsolete() {
82 return super.isObsolete() || property.hasSuperProperty( OBO.ObsoleteProperty, false );
83 }
84
85 @Override
86 public boolean equals( @Nullable Object obj ) {
87 if ( this == obj ) return true;
88 if ( obj == null ) return false;
89 if ( obj instanceof AnnotationPropertyImpl ) {
90 final AnnotationPropertyImpl/basecode/ontology/jena/AnnotationPropertyImpl.html#AnnotationPropertyImpl">AnnotationPropertyImpl other = ( AnnotationPropertyImpl ) obj;
91 return super.equals( other )
92 && Objects.equals( object, other.object );
93 } else if ( obj instanceof AnnotationProperty ) {
94 final AnnotationPropertyubic/basecode/ontology/model/AnnotationProperty.html#AnnotationProperty">AnnotationProperty other = ( AnnotationProperty ) obj;
95 return super.equals( other )
96 && Objects.equals( getContents(), other.getContents() );
97 }
98 return false;
99 }
100
101 @Override
102 public int hashCode() {
103 return Objects.hash( super.hashCode(), object );
104 }
105
106 @Override
107 public String toString() {
108 return property.getLocalName() + " " + object;
109 }
110
111 }