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