View Javadoc
1   /*
2    * The basecode project
3    *
4    * Copyright (c) 2007-2019 University of British Columbia
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *       http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   *
18   */
19  package ubic.basecode.ontology.jena;
20  
21  import com.hp.hpl.jena.ontology.Restriction;
22  import ubic.basecode.ontology.model.OntologyCardinalityRestriction;
23  
24  import java.util.Set;
25  
26  /**
27   * @author pavlidis
28   */
29  public class OntologyCardinalityRestrictionImpl extends OntologyRestrictionImpl implements
30          OntologyCardinalityRestriction {
31  
32      /**
33       *
34       */
35      private static final long serialVersionUID = 1L;
36      int cardinality = 0;
37      CardinalityType cardType;
38  
39      public OntologyCardinalityRestrictionImpl( Restriction resource, Set<Restriction> additionalRestrictions ) {
40          super( resource, additionalRestrictions );
41  
42          if ( resource.isMaxCardinalityRestriction() ) {
43              this.cardType = CardinalityType.MAX_CARDINALITY;
44              this.cardinality = resource.asMaxCardinalityRestriction().getMaxCardinality();
45          } else if ( resource.isMinCardinalityRestriction() ) {
46              this.cardType = CardinalityType.MIN_CARDINALITY;
47              this.cardinality = resource.asMinCardinalityRestriction().getMinCardinality();
48          } else if ( resource.isCardinalityRestriction() ) {
49              this.cardType = CardinalityType.CARDINALITY;
50              this.cardinality = resource.asCardinalityRestriction().getCardinality();
51          } else {
52              throw new IllegalArgumentException( "Must pass in a cardinality restriction" );
53          }
54  
55      }
56  
57      @Override
58      public int getCardinality() {
59          return cardinality;
60      }
61  
62      @Override
63      public CardinalityType getCardinalityType() {
64          return cardType;
65      }
66  
67      @Override
68      public String toString() {
69          return " cardinality restriction: " + cardType + "  " + this.getCardinality();
70      }
71  
72  }