View Javadoc
1   package org.eclipse.aether.version;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   * 
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   * 
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  /**
23   * A range of versions.
24   */
25  public interface VersionRange
26  {
27  
28      /**
29       * Determines whether the specified version is contained within this range.
30       * 
31       * @param version The version to test, must not be {@code null}.
32       * @return {@code true} if this range contains the specified version, {@code false} otherwise.
33       */
34      boolean containsVersion( Version version );
35  
36      /**
37       * Gets a lower bound (if any) for this range. If existent, this range does not contain any version smaller than its
38       * lower bound. Note that complex version ranges might exclude some versions even within their bounds.
39       * 
40       * @return A lower bound for this range or {@code null} is there is none.
41       */
42      Bound getLowerBound();
43  
44      /**
45       * Gets an upper bound (if any) for this range. If existent, this range does not contain any version greater than
46       * its upper bound. Note that complex version ranges might exclude some versions even within their bounds.
47       * 
48       * @return An upper bound for this range or {@code null} is there is none.
49       */
50      Bound getUpperBound();
51  
52      /**
53       * A bound of a version range.
54       */
55      static final class Bound
56      {
57  
58          private final Version version;
59  
60          private final boolean inclusive;
61  
62          /**
63           * Creates a new bound with the specified properties.
64           * 
65           * @param version The bounding version, must not be {@code null}.
66           * @param inclusive A flag whether the specified version is included in the range or not.
67           */
68          public Bound( Version version, boolean inclusive )
69          {
70              if ( version == null )
71              {
72                  throw new IllegalArgumentException( "version missing" );
73              }
74              this.version = version;
75              this.inclusive = inclusive;
76          }
77  
78          /**
79           * Gets the bounding version.
80           * 
81           * @return The bounding version, never {@code null}.
82           */
83          public Version getVersion()
84          {
85              return version;
86          }
87  
88          /**
89           * Indicates whether the bounding version is included in the range or not.
90           * 
91           * @return {@code true} if the bounding version is included in the range, {@code false} if not.
92           */
93          public boolean isInclusive()
94          {
95              return inclusive;
96          }
97  
98          @Override
99          public boolean equals( Object obj )
100         {
101             if ( obj == this )
102             {
103                 return true;
104             }
105             else if ( obj == null || !getClass().equals( obj.getClass() ) )
106             {
107                 return false;
108             }
109 
110             Bound that = (Bound) obj;
111             return inclusive == that.inclusive && version.equals( that.version );
112         }
113 
114         @Override
115         public int hashCode()
116         {
117             int hash = 17;
118             hash = hash * 31 + version.hashCode();
119             hash = hash * 31 + ( inclusive ? 1 : 0 );
120             return hash;
121         }
122 
123         @Override
124         public String toString()
125         {
126             return String.valueOf( version );
127         }
128 
129     }
130 
131 }