All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.dockerjava.core.RemoteApiVersion Maven / Gradle / Ivy

There is a newer version: 3.4.1
Show newest version
package com.github.dockerjava.core;

import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;

import java.io.Serializable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Bean to encapsulate the version of the Docker Remote (REST)
 * API
 * 

* Contains the minor and major version of the API as well as operations to compare API versions. * * @author Marcus Thiesen */ public class RemoteApiVersion implements Serializable { private static final long serialVersionUID = -5382212999262115459L; private static final Pattern VERSION_REGEX = Pattern.compile("v?(\\d+)\\.(\\d+)"); /** * Online documentation is not available anymore. */ public static final RemoteApiVersion VERSION_1_7 = RemoteApiVersion.create(1, 7); /** * @see Docker API 1.16 */ public static final RemoteApiVersion VERSION_1_16 = RemoteApiVersion.create(1, 16); /** * @see Docker API 1.17 */ public static final RemoteApiVersion VERSION_1_17 = RemoteApiVersion.create(1, 17); /** * @see Docker API 1.18 */ public static final RemoteApiVersion VERSION_1_18 = RemoteApiVersion.create(1, 18); /** * @see Docker API 1.19 */ public static final RemoteApiVersion VERSION_1_19 = RemoteApiVersion.create(1, 19); /** * @see Docker API 1.20 */ public static final RemoteApiVersion VERSION_1_20 = RemoteApiVersion.create(1, 20); /** * @see Docker API 1.21 */ public static final RemoteApiVersion VERSION_1_21 = RemoteApiVersion.create(1, 21); /** * @see Docker API 1.22 */ public static final RemoteApiVersion VERSION_1_22 = RemoteApiVersion.create(1, 22); /** * @see Docker API 1.22 */ public static final RemoteApiVersion VERSION_1_23 = RemoteApiVersion.create(1, 23); /** * @see Docker API 1.22 */ public static final RemoteApiVersion VERSION_1_24 = RemoteApiVersion.create(1, 24); /* * @see Docker API 1.25 */ public static final RemoteApiVersion VERSION_1_25 = RemoteApiVersion.create(1, 25); /** * Unknown, docker doesn't reflect reality. I.e. we implemented method, but for javadoc it not clear when it was added. */ public static final RemoteApiVersion UNKNOWN_VERSION = new RemoteApiVersion(0, 0) { @Override public boolean isGreaterOrEqual(final RemoteApiVersion other) { return false; } @Override public String toString() { return MoreObjects.toStringHelper(this).addValue("UNKNOWN_VERSION").toString(); } @Override public String asWebPathPart() { return ""; } }; private final int major; private final int minor; private RemoteApiVersion(final int major, final int minor) { this.major = major; this.minor = minor; } public static RemoteApiVersion create(final int major, final int minor) { Preconditions.checkArgument(major > 0, "Major version must be bigger than 0 but is " + major); Preconditions.checkArgument(minor > 0, "Minor version must be bigger than 0 but is " + minor); return new RemoteApiVersion(major, minor); } public static RemoteApiVersion unknown() { return UNKNOWN_VERSION; } public static RemoteApiVersion parseConfig(final String version) { Preconditions.checkArgument(version != null, "Version must not be null"); final Matcher matcher = VERSION_REGEX.matcher(version); if (matcher.matches()) { return create(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2))); } throw new IllegalArgumentException(version + " can not be parsed"); } public static RemoteApiVersion parseConfigWithDefault(final String version) { if (Strings.isNullOrEmpty(version)) { return UNKNOWN_VERSION; } try { return parseConfig(version); } catch (IllegalArgumentException e) { return UNKNOWN_VERSION; } } public boolean isGreaterOrEqual(final RemoteApiVersion other) { if (major >= other.major && minor >= other.minor) { return true; } return false; } /** * @return String representation of version. i.e. "1.22" */ public String getVersion() { return major + "." + minor; } // CHECKSTYLE:OFF @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; final RemoteApiVersion that = (RemoteApiVersion) o; return Objects.equal(major, that.major) && Objects.equal(minor, that.minor); } // CHECKSTYLE:ON @Override public int hashCode() { return Objects.hashCode(major, minor); } @Override public String toString() { return MoreObjects.toStringHelper(this).add("major", major).add("minor", minor).toString(); } public String asWebPathPart() { return "v" + major + "." + minor; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy