Author: tchemit Date: 2014-08-23 11:08:49 +0200 (Sat, 23 Aug 2014) New Revision: 2671 Url: http://forge.nuiton.org/projects/nuiton-utils/repository/revisions/2671 Log: fixes #3461: Introduce a Versions class Added: trunk/src/main/java/org/nuiton/util/version/Versions.java Added: trunk/src/main/java/org/nuiton/util/version/Versions.java =================================================================== --- trunk/src/main/java/org/nuiton/util/version/Versions.java (rev 0) +++ trunk/src/main/java/org/nuiton/util/version/Versions.java 2014-08-23 09:08:49 UTC (rev 2671) @@ -0,0 +1,101 @@ +package org.nuiton.util.version; + +/** + * Useful class around {@link Version}. + * + * Created on 8/23/14. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.0-rc-6 + */ +public class Versions { + + /** + * Shortcut method to get a version from his string representation. + * + * @param version string representation of the version + * @return converted version from the string representation + */ + public static Version valueOf(String version) { + Version v = VersionBuilder.create(version).build(); + return v; + } + + /** + * Tests if two versions are equals. + * + * @param version0 the first version + * @param version1 the second version + * @return {@code true} if versions are equals, {@code false} otherwise. + */ + public static boolean equals(String version0, String version1) { + Version v0 = valueOf(version0); + Version v1 = valueOf(version1); + boolean result = v0.equals(v1); + return result; + } + + /** + * Tests if the first version is smaller than the second version. + * + * @param version0 the first version + * @param version1 the second version + * @return {@code true} if {@code version0} is before {@code version1}, + * {@code false} otherwise. + */ + public static boolean smallerThan(String version0, String version1) { + Version v0 = valueOf(version0); + Version v1 = valueOf(version1); + boolean result = v0.before(v1); + return result; + } + + /** + * Tests if the first version is greater than the second version. + * + * @param version0 the first version + * @param version1 the second version + * @return {@code true} if {@code version0} is after {@code version1}, + * {@code false} otherwise. + */ + public static boolean greaterThan(String version0, String version1) { + Version v0 = valueOf(version0); + Version v1 = valueOf(version1); + boolean result = v0.after(v1); + return result; + } + + /** + * Create a version from the given one and set to it the {@code snapshot} state to {@code true}. + * + * @param version version to clone + * @return the cloned version with the {@code snapshot} state to {@code true} + * @throws IllegalArgumentException if {@code snapshot} state is already set to {@code true} on + * the given {@code version}. + */ + public static Version addSnapshot(Version version) { + if (version.isSnapshot()) { + throw new IllegalArgumentException( + "version " + version + "is already a snapshot"); + } + Version result = VersionBuilder.create(version).setSnapshot(true).build(); + return result; + } + + /** + * Create a version from the given one and set to it the {@code snapshot} state to {@code false}. + * + * @param version version to clone + * @return the cloned version with the {@code snapshot} state to {@code true} + * @throws IllegalArgumentException if {@code snapshot} state is already set to {@code false} on + * the given {@code version} + */ + public static Version removeSnapshot(Version version) { + if (!version.isSnapshot()) { + throw new IllegalArgumentException( + "version " + version + "is already a snapshot"); + } + Version result = VersionBuilder.create(version).setSnapshot(false).build(); + return result; + } +} Property changes on: trunk/src/main/java/org/nuiton/util/version/Versions.java ___________________________________________________________________ Added: svn:eol-style + native Added: svn:keywords + Author Date Id Revision
participants (1)
-
tchemit@users.nuiton.org