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  class OntologyCardinalityRestrictionImpl extends OntologyRestrictionImpl implements
30          OntologyCardinalityRestriction {
31  
32      private final int cardinality;
33      private final CardinalityType cardType;
34  
35      public OntologyCardinalityRestrictionImpl( Restriction resource, Set<Restriction> additionalRestrictions ) {
36          super( resource, additionalRestrictions );
37  
38          if ( resource.isMaxCardinalityRestriction() ) {
39              this.cardType = CardinalityType.MAX_CARDINALITY;
40              this.cardinality = resource.asMaxCardinalityRestriction().getMaxCardinality();
41          } else if ( resource.isMinCardinalityRestriction() ) {
42              this.cardType = CardinalityType.MIN_CARDINALITY;
43              this.cardinality = resource.asMinCardinalityRestriction().getMinCardinality();
44          } else if ( resource.isCardinalityRestriction() ) {
45              this.cardType = CardinalityType.CARDINALITY;
46              this.cardinality = resource.asCardinalityRestriction().getCardinality();
47          } else {
48              throw new IllegalArgumentException( "Must pass in a cardinality restriction" );
49          }
50  
51      }
52  
53      @Override
54      public int getCardinality() {
55          return cardinality;
56      }
57  
58      @Override
59      public CardinalityType getCardinalityType() {
60          return cardType;
61      }
62  
63      @Override
64      public String toString() {
65          return " cardinality restriction: " + cardType + "  " + this.getCardinality();
66      }
67  
68  }