View Javadoc
1   /*
2    * The baseCode project
3    *
4    * Copyright (c) 2013 University of British Columbia
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
7    * the License. You may obtain a copy of the License at
8    *
9    * http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
12   * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
13   * specific language governing permissions and limitations under the License.
14   */
15  package ubic.basecode.ontology.model;
16  
17  import javax.annotation.Nullable;
18  import java.util.Collection;
19  import java.util.Comparator;
20  import java.util.Objects;
21  
22  /**
23   * A light-weight version of OntologyTerms. Only supports a subset of the functionality of OntologyTermImpl (namely, it
24   * is missing the inference components)
25   *
26   * @author Paul
27   */
28  
29  public class OntologyTermSimple implements OntologyTerm {
30  
31      /**
32       *
33       */
34      private static final long serialVersionUID = -2589717267279872909L;
35  
36      private final String description;
37      private final boolean obsolete;
38      private final String term;
39      private final String uri;
40  
41      public OntologyTermSimple( String uri, String term ) {
42          this( uri, term, "", false );
43      }
44  
45      public OntologyTermSimple( String uri, String term, String description, boolean isObsolete ) {
46          this.uri = uri;
47          this.term = term;
48          this.description = description;
49          this.obsolete = isObsolete;
50      }
51  
52      @Override
53      public Collection<String> getAlternativeIds() {
54          throw new UnsupportedOperationException( "Use a OntologyTermImpl" );
55      }
56  
57      @Override
58      public Collection<AnnotationProperty> getAnnotations() {
59          throw new UnsupportedOperationException( "Use a OntologyTermImpl" );
60      }
61  
62      @Override
63      public Collection<OntologyTerm> getChildren( boolean direct, boolean includeAdditionalProperties, boolean keepObsoletes ) {
64          throw new UnsupportedOperationException( "Use a OntologyTermImpl" );
65      }
66  
67      @Override
68      public String getComment() {
69          return this.description;
70      }
71  
72      @Override
73      public Collection<OntologyIndividual> getIndividuals( boolean direct ) {
74          throw new UnsupportedOperationException( "Use a OntologyTermImpl" );
75      }
76  
77      @Override
78      public String getLabel() {
79          return term;
80      }
81  
82      @Override
83      public String getLocalName() {
84          return term;
85      }
86  
87      @Override
88      public Object getModel() {
89          throw new UnsupportedOperationException( "Use a OntologyTermImpl" );
90      }
91  
92      @Override
93      public Collection<OntologyTerm> getParents( boolean direct, boolean includeAdditionalProperties, boolean keepObsoletes ) {
94          throw new UnsupportedOperationException( "Use a OntologyTermImpl" );
95      }
96  
97      @Override
98      public Collection<OntologyRestriction> getRestrictions() {
99          throw new UnsupportedOperationException( "Use a OntologyTermImpl" );
100     }
101 
102     @Override
103     public boolean isRoot() {
104         throw new UnsupportedOperationException( "Use a OntologyTermImpl" );
105     }
106 
107     @Override
108     public boolean isTermObsolete() {
109         return obsolete;
110     }
111 
112     @Override
113     public String getTerm() {
114         return this.term;
115     }
116 
117     @Override
118     public String getUri() {
119         return this.uri;
120     }
121 
122     @Override
123     public boolean isObsolete() {
124         return obsolete;
125     }
126 
127     @Nullable
128     @Override
129     public Double getScore() {
130         return null;
131     }
132 
133     @Override
134     public int compareTo( OntologyResource other ) {
135         return Objects.compare( getUri(), other.getUri(), Comparator.nullsLast( Comparator.naturalOrder() ) );
136     }
137 
138     @Override
139     public boolean equals( Object obj ) {
140         if ( this == obj ) return true;
141         if ( obj == null ) return false;
142         if ( getClass() != obj.getClass() ) return false;
143         final OntologyResource./ubic/basecode/ontology/model/OntologyResource.html#OntologyResource">OntologyResource other = ( OntologyResource ) obj;
144         if ( getLabel() == null ) {
145             if ( other.getLabel() != null ) return false;
146         } else if ( !getLabel().equals( other.getLabel() ) ) return false;
147         if ( getUri() == null ) {
148             if ( other.getUri() != null ) return false;
149         } else if ( !getUri().equals( other.getUri() ) ) return false;
150         return true;
151     }
152 
153     @Override
154     public int hashCode() {
155         return Objects.hash( getLabel(), getUri() );
156     }
157 }