/** * @return A String representation of this filter / pattern, which follows this convention: {@link * #min} + {@value #VERSION_SEPARATOR} + {@link #max} */ @Override public String toString() { StringBuffer buffer = new StringBuffer(); buffer.append(min.toString()); buffer.append(VERSION_SEPARATOR); buffer.append(max.toString()); return buffer.toString(); }
/** * Creates a new VersionPattern with the interval from <code>min</code> to <code>max</code>, where * <code>min</code> and <code>max</code> are part of the valid versions interval if <code> * minInclusive == true</code>, <code>maxInclusive == true</code> respectively. * * <p>Note: The invariant is that <code>min</code> is always the smaller version (lower end point) * and <code>max</code> is the bigger version (upper end point). So make sure you pass the smaller * version as <code>min</code> and the bigger version as <code>max</code>! * * @param min the lower end point of the valid versions interval * @param max the upper end point of the valid versions interval * @param minInclusive whether <code>min</code> is part of the valid versions interval. * @param maxInclusive whether <code>max</code> is part of the valid versions interval. */ public VersionPattern(VersionRangeEndPoint min, VersionRangeEndPoint max) { if (min == null || max == null) throw new IllegalArgumentException("min and max must NOT be null!"); if (min.compareTo(max) > 0) throw new IllegalArgumentException( "The given min version is not allowed to be greater than max!"); this.min = min; this.max = max; }
/** * Returns the upper bound of valid versions given a minimum version and a {@link MatchRule}. * * @param min the minimum Version, the lower bound of the valid version range. * @param rule the {@link MatchRule} to use for determining the upper bound (<code>max</code>). * @return the upper bound of valid versions given a minimum version and a {@link MatchRule}. */ private static VersionRangeEndPoint getUpperBoundForRule( VersionRangeEndPoint min, MatchRule rule) { VersionRangeEndPoint max = min.changeLocation(EndPointLocation.UPPER); if (!max.isInclusive()) max = max.changeInclusive(true); Version upperEndPoint = max.getEndPoint(); boolean changed = false; switch (rule) { case GreaterOrEqual: upperEndPoint = upperEndPoint.changeMajor(Integer.MAX_VALUE); case Equivalent: upperEndPoint = upperEndPoint.changeMinor(Integer.MAX_VALUE); case Compatible: upperEndPoint = upperEndPoint.changeRelease(Integer.MAX_VALUE); upperEndPoint = upperEndPoint.changePatchLevel(Integer.MAX_VALUE); changed = true; case Perfect: if (changed) max = max.changeVersion(upperEndPoint); return max; default: throw new RuntimeException( "The MatchRule enum has been extended but the " + "'getUpperBoundForRule' method hasn't been updated!"); } }
/** * Returns <code>true</code> if the given <code>version</code> is in the range of valid versions, * <code>false</code> otherwise. * * @param version the version to check for validity. * @return <code>true</code> if the given <code>version</code> is in the range of valid versions, * <code>false</code> otherwise. */ public boolean matches(Version version) { boolean lowerBoundHolds = false; if (min.getEndPoint().compareTo(version) < 0 || min.getEndPoint().compareTo(version) == 0 && min.isInclusive()) lowerBoundHolds = true; boolean upperBoundHolds = false; if (max.getEndPoint().compareTo(version) > 0 || max.getEndPoint().compareTo(version) == 0 && max.isInclusive()) upperBoundHolds = true; return lowerBoundHolds & upperBoundHolds; }
public char getMaxInclusiveChar() { return max.getInclusiveChar(); }
/** * @return <code>true</code> if the maximum version (<code>max</code>) is part of the valid * versions of this pattern, <code>false</code> otherwise (<code>max</code> is a supremum). */ public boolean isMaxInclusive() { return max.isInclusive(); }
public char getMinInclusiveChar() { return min.getInclusiveChar(); }
/** * @return <code>true</code> if the minimum version (<code>min</code>) is part of the valid * versions of this pattern, <code>false</code> otherwise (<code>min</code> is an infimum). */ public boolean isMinInclusive() { return min.isInclusive(); }