/** * @param versionConstraint the version constraint to merge * @return the version constraint with the upper version or null if both are ranges based * @throws IncompatibleVersionConstraintException version constraints are incompatible */ private VersionConstraint mergeVersions(VersionConstraint versionConstraint) throws IncompatibleVersionConstraintException { if (this.version != null) { return mergeVersions(this, versionConstraint); } else if (versionConstraint.getVersion() != null) { return mergeVersions(versionConstraint, this); } return null; }
/** * @param versionConstraintWithVersion the version constraint based on version * @param versionConstraint the version constraint for which we don't know yet if it's based on * version or ranges * @return the merged version constraint * @throws IncompatibleVersionConstraintException version constraints are incompatible */ private VersionConstraint mergeVersions( VersionConstraint versionConstraintWithVersion, VersionConstraint versionConstraint) throws IncompatibleVersionConstraintException { if (versionConstraint.getVersion() != null) { return versionConstraintWithVersion.getVersion().compareTo(versionConstraint.getVersion()) >= 0 ? versionConstraintWithVersion : versionConstraint; } else { if (!versionConstraint.containsVersion(versionConstraintWithVersion.getVersion())) { throw new IncompatibleVersionConstraintException( "Version [" + versionConstraintWithVersion.getVersion() + "] is not part of version constraint [" + versionConstraint + "]"); } return versionConstraintWithVersion; } }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null || !(obj instanceof VersionConstraint)) { return false; } VersionConstraint versionConstraint = (VersionConstraint) obj; return this.ranges.equals(versionConstraint.getRanges()) && ObjectUtils.equals(this.version, versionConstraint.getVersion()); }
/** * Created a new {@link DefaultVersionConstraint} by cloning the provided version constraint. * * @param versionConstraint the version constrain to copy */ public DefaultVersionConstraint(VersionConstraint versionConstraint) { this(versionConstraint.getRanges(), versionConstraint.getVersion()); }