本文整理了Java中org.apache.sis.util.Version
类的一些代码示例,展示了Version
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Version
类的具体详情如下:
包路径:org.apache.sis.util.Version
类名称:Version
[英]Holds a version number as a sequence of strings separated by either a dot or a dash. The first three strings, usually numbers, are called respectively #getMajor(), #getMinor() and #getRevision(). For example a version code such as "6.11.2" will have major number 6, minor number 11 and revision number 2. Alternatively a version code such as "3.18-SNAPSHOT"will have major version number 3, minor version number 18 and revision string "SNAPSHOT".
This class provides methods for performing comparisons of Version objects where major, minor and revision parts are compared as numbers when possible, or as strings otherwise.
Immutability and thread safety This class is immutable and thus inherently thread-safe. Subclasses may or may not be immutable, at implementation choice. But implementors are encouraged to make sure that subclasses remain immutable for more predictable behavior.
[中]将版本号保存为由点或破折号分隔的字符串序列。前三个字符串通常是数字,分别被称为#getMajor()、#getMinor()和#getRevision()。例如,“6.11.2”等版本代码将包含主要编号6、次要编号11和修订编号2。或者,诸如“3.18-SNAPSHOT”之类的版本代码将包含主版本号3、次版本号18和修订字符串“SNAPSHOT”。
此类提供了执行版本对象比较的方法,其中主要、次要和修订部分尽可能作为数字或字符串进行比较。
不变性和线程安全这个类是不可变的,因此本质上是线程安全的。子类可能是不变的,也可能不是不变的,这取决于实现的选择。但鼓励实现者确保子类对于更可预测的行为保持不变。
代码示例来源:origin: apache/sis
/**
* Compares this version with an other version object. This method performs the same
* comparison than {@link #compareTo(Version, int)} with no limit.
*
* @param other the other version object to compare with.
* @return a negative value if this version is lower than the supplied version,
* a positive value if it is higher, or 0 if they are equal.
*/
@Override
public int compareTo(final Version other) {
return compareTo(other, Integer.MAX_VALUE);
}
代码示例来源:origin: Geomatys/geotoolkit
/**
* Build a new exception report.
*
* @param version The version of the web service in which the error occured.
* @param details The reasons for the failure.
*/
public ServiceExceptionReport(final Version version, final ServiceExceptionType... details) {
for (final ServiceExceptionType element : details) {
serviceExceptions.add(element);
}
this.version = (version != null) ? version.toString() : null;
}
代码示例来源:origin: org.apache.sis.core/sis-utility
/**
* Returns the major version number. This method returns an {@link Integer} if possible,
* or a {@link String} otherwise.
*
* @return the major version number.
*/
public Comparable<?> getMajor() {
return getComponent(0);
}
代码示例来源:origin: apache/sis
/**
* Tests a numeric-only version.
*/
@Test
public void testNumeric() {
final Version version = new Version("6.11.2");
assertEquals("6.11.2", version.toString());
assertEquals( 6, version.getMajor());
assertEquals(11, version.getMinor());
assertEquals( 2, version.getRevision());
assertSame(version.getRevision(), version.getComponent(2));
assertNull(version.getComponent(3));
assertTrue(version.compareTo(new Version("6.11.2")) == 0);
assertTrue(version.compareTo(new Version("6.8" )) > 0);
assertTrue(version.compareTo(new Version("6.12.0")) < 0);
assertTrue(version.compareTo(new Version("6.11" )) > 0);
}
代码示例来源:origin: Geomatys/geotoolkit
/**
* inherited method from AbstractGetCapabilties
*/
@Override
public Version getVersion() {
if (acceptVersions!= null && !acceptVersions.getVersion().isEmpty()) {
return new Version(acceptVersions.getVersion().get(0));
} return null;
}
代码示例来源:origin: Geomatys/geotoolkit
Version candidate = new Version(buffer.toString());
if (max == null || max.compareTo(candidate) <= 0) {
max = candidate;
selected = version;
代码示例来源:origin: apache/sis
if (s > 0) {
fmtEnum = format.substring(0, s);
version = new Version(format.substring(s+1).trim());
case WKT: {
if (convention == null) {
if (version == null || version.equals(Version.valueOf(2))) {
convention = Convention.WKT2;
} else {
convention = Convention.WKT1;
isVersionSupported = version.equals(Version.valueOf(1));
代码示例来源:origin: apache/sis
/**
* Tests the {@link Version#valueOf(int[])} method.
*/
@Test
public void testValueOf() {
Version version = Version.valueOf(1);
assertEquals("1", version.toString());
assertEquals( 1, version.getMajor());
assertNull ( version.getMinor());
assertNull ( version.getRevision());
version = Version.valueOf(10);
assertEquals("10", version.toString());
assertEquals( 10, version.getMajor());
assertNull ( version.getMinor());
assertNull ( version.getRevision());
version = Version.valueOf(0, 4);
assertEquals("0.4", version.toString());
assertEquals( 0, version.getMajor());
assertEquals( 4, version.getMinor());
assertNull ( version.getRevision());
version = Version.valueOf(6, 11, 2);
assertEquals("6.11.2", version.toString());
assertEquals( 6, version.getMajor());
assertEquals( 11, version.getMinor());
assertEquals( 2, version.getRevision());
}
代码示例来源:origin: apache/sis
/**
* Tests the cached values of {@link Version#valueOf(int[])}.
*/
@Test
@DependsOnMethod("testValueOf")
public void testCachedValueOf() {
for (int major=1; major<=2; major++) {
final Version version = Version.valueOf(major);
assertSame(version.toString(), version, Version.valueOf(major));
}
}
代码示例来源:origin: apache/sis
/**
* Returns the value to be returned by {@link StoreProvider#probeContent(StorageConnector)}
* for the given WKT keyword. This method changes the case to match the one used in the keywords map,
* then verify if the keyword that we found is one of the known WKT keywords. Keywords with the "CRS"
* suffix are WKT 2 while keywords with the "CS" suffix are WKT 1.
*/
@Override
protected ProbeResult forKeyword(final char[] keyword, final int length) {
if (length >= MIN_LENGTH) {
int pos = length;
int version = 1;
keyword[ 0] &= ~0x20; // Make upper-case (valid only for characters in the a-z range).
keyword[--pos] &= ~0x20;
if ((keyword[--pos] &= ~0x20) == 'R') {
keyword[--pos] &= ~0x20; // Make "CRS" suffix in upper case (otherwise, was "CS" suffix)
version = 2;
}
while (--pos != 0) {
if (keyword[pos] != '_') {
keyword[pos] |= 0x20; // Make lower-case.
}
}
if (keywords.contains(String.valueOf(keyword, 0, length))) {
return new ProbeResult(true, MIME_TYPE, Version.valueOf(version));
}
}
return ProbeResult.UNSUPPORTED_STORAGE;
}
}
代码示例来源:origin: apache/sis
/**
* Tests {@link NetcdfStore#getConventionVersion()}.
*
* @throws DataStoreException if an error occurred while reading the netCDF file.
*/
@Test
public void testGetConventionVersion() throws DataStoreException {
final Version version;
try (NetcdfStore store = create(TestData.NETCDF_2D_GEOGRAPHIC)) {
version = store.getConventionVersion();
}
assertEquals("major", 1, version.getMajor());
assertEquals("minor", 4, version.getMinor());
}
}
代码示例来源:origin: org.apache.sis.core/sis-utility
ArgumentChecks.ensurePositive("limit", limit);
for (int i=0; i<limit; i++) {
final Comparable<?> v1 = this.getComponent(i);
final Comparable<?> v2 = other.getComponent(i);
if (v1 == null) {
return (v2 == null) ? 0 : -1;
return +1;
final int dr = getTypeRank(v1) - getTypeRank(v2);
if (dr != 0) {
代码示例来源:origin: apache/sis
/**
* Implementation of {@link #testProbeContentFromReader()}.
*/
private static void testProbeContentFromReader(final boolean isSupported, final int version,
final StoreProvider p, final String wkt) throws DataStoreException
{
final StorageConnector c = new StorageConnector(new StringReader(wkt));
final ProbeResult r = p.probeContent(c);
c.closeAllExcept(null);
assertEquals("isSupported", isSupported, r.isSupported());
if (isSupported) {
assertEquals("mimeType", "application/wkt", r.getMimeType());
assertEquals("version", version, r.getVersion().getMajor());
}
}
}
代码示例来源:origin: apache/sis
/**
* Tests a alpha-numeric version.
*/
@Test
@DependsOnMethod("testNumeric")
public void testAlphaNumeric() {
final Version version = new Version("1.6.b2");
assertEquals("1.6.b2", version.toString());
assertEquals( 1, version.getMajor());
assertEquals( 6, version.getMinor());
assertEquals("b2", version.getRevision());
assertSame(version.getRevision(), version.getComponent(2));
assertNull(version.getComponent(3));
assertTrue(version.compareTo(new Version("1.6.b2")) == 0);
assertTrue(version.compareTo(new Version("1.6.b1")) > 0);
assertTrue(version.compareTo(new Version("1.07.b1")) < 0);
}
代码示例来源:origin: Geomatys/geotoolkit
/**
* inherited method from AbstractGetCapabilties
*/
@Override
public Version getVersion() {
if (acceptVersions!= null && !acceptVersions.getVersion().isEmpty()) {
return new Version(acceptVersions.getVersion().get(0));
} return null;
}
代码示例来源:origin: apache/sis
/**
* Tests {@link Version#compareTo(Version, int)} with version numbers needed by our GML support.
*/
@Test
public void testGML() {
final Version V3_0 = new Version("3.0"),
V3_2 = new Version("3.2"),
V3_2_1 = new Version("3.2.1");
assertTrue(V3_2.compareTo(V3_2_1, 2) == 0);
assertTrue(V3_2.compareTo(V3_2_1 ) < 0);
assertTrue(V3_0.compareTo(V3_2_1 ) < 0);
assertTrue(V3_0.compareTo(V3_2_1, 2) < 0);
assertTrue(V3_0.compareTo(V3_2_1, 1) == 0);
assertTrue(V3_0.compareTo(V3_2 ) < 0);
assertTrue(V3_0.compareTo(V3_2, 2) < 0);
assertTrue(V3_0.compareTo(V3_2, 1) == 0);
}
代码示例来源:origin: org.apache.sis.storage/sis-storage
/**
* Returns the value to be returned by {@link StoreProvider#probeContent(StorageConnector)}
* for the given WKT keyword. This method changes the case to match the one used in the keywords map,
* then verify if the keyword that we found is one of the known WKT keywords. Keywords with the "CRS"
* suffix are WKT 2 while keywords with the "CS" suffix are WKT 1.
*/
@Override
protected ProbeResult forKeyword(final char[] keyword, final int length) {
if (length >= MIN_LENGTH) {
int pos = length;
int version = 1;
keyword[ 0] &= ~0x20; // Make upper-case (valid only for characters in the a-z range).
keyword[--pos] &= ~0x20;
if ((keyword[--pos] &= ~0x20) == 'R') {
keyword[--pos] &= ~0x20; // Make "CRS" suffix in upper case (otherwise, was "CS" suffix)
version = 2;
}
while (--pos != 0) {
if (keyword[pos] != '_') {
keyword[pos] |= 0x20; // Make lower-case.
}
}
if (keywords.contains(String.valueOf(keyword, 0, length))) {
return new ProbeResult(true, MIME_TYPE, Version.valueOf(version));
}
}
return ProbeResult.UNSUPPORTED_STORAGE;
}
}
代码示例来源:origin: apache/sis
ArgumentChecks.ensurePositive("limit", limit);
for (int i=0; i<limit; i++) {
final Comparable<?> v1 = this.getComponent(i);
final Comparable<?> v2 = other.getComponent(i);
if (v1 == null) {
return (v2 == null) ? 0 : -1;
return +1;
final int dr = getTypeRank(v1) - getTypeRank(v2);
if (dr != 0) {
代码示例来源:origin: Geomatys/geotoolkit
/**
* inherited method from AbstractGetCapabilties
*/
@Override
public Version getVersion() {
if (acceptVersions!= null && !acceptVersions.getVersion().isEmpty()) {
return new Version(acceptVersions.getVersion().get(0));
} return null;
}
代码示例来源:origin: apache/sis
Version version = null;
if (ver != null) {
version = new Version(ver);
if (version.compareTo(StoreProvider.V1_0, 2) < 0 ||
version.compareTo(StoreProvider.V1_1, 2) > 0)
内容来源于网络,如有侵权,请联系作者删除!