KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > maven > artifact > versioning > Restriction


1 package org.apache.maven.artifact.versioning;
2
3 /*
4  * Copyright 2001-2005 The Apache Software Foundation.
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 /**
20  * Describes a restriction in versioning.
21  *
22  * @author <a HREF="mailto:brett@apache.org">Brett Porter</a>
23  * @version $Id: Restriction.java 219815 2005-07-19 23:45:44Z brett $
24  */

25 public class Restriction
26 {
27     private final ArtifactVersion lowerBound;
28
29     private final boolean lowerBoundInclusive;
30
31     private final ArtifactVersion upperBound;
32
33     private final boolean upperBoundInclusive;
34
35     static final Restriction EVERYTHING = new Restriction( null, false, null, false );
36
37     public Restriction( ArtifactVersion lowerBound, boolean lowerBoundInclusive, ArtifactVersion upperBound,
38                         boolean upperBoundInclusive )
39     {
40         this.lowerBound = lowerBound;
41         this.lowerBoundInclusive = lowerBoundInclusive;
42         this.upperBound = upperBound;
43         this.upperBoundInclusive = upperBoundInclusive;
44     }
45
46     public ArtifactVersion getLowerBound()
47     {
48         return lowerBound;
49     }
50
51     public boolean isLowerBoundInclusive()
52     {
53         return lowerBoundInclusive;
54     }
55
56     public ArtifactVersion getUpperBound()
57     {
58         return upperBound;
59     }
60
61     public boolean isUpperBoundInclusive()
62     {
63         return upperBoundInclusive;
64     }
65
66     public boolean containsVersion( ArtifactVersion version )
67     {
68         if ( lowerBound != null )
69         {
70             int comparison = lowerBound.compareTo( version );
71             if ( comparison == 0 && !lowerBoundInclusive )
72             {
73                 return false;
74             }
75             if ( comparison > 0 )
76             {
77                 return false;
78             }
79         }
80         if ( upperBound != null )
81         {
82             int comparison = upperBound.compareTo( version );
83             if ( comparison == 0 && !upperBoundInclusive )
84             {
85                 return false;
86             }
87             if ( comparison < 0 )
88             {
89                 return false;
90             }
91         }
92         return true;
93     }
94 }
95
Popular Tags