version4j

Library to help compare major.minor.patch versions

Лицензия

Лицензия

Группа

Группа

com.kcthota
Идентификатор

Идентификатор

version4j
Последняя версия

Последняя версия

4.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

version4j
Library to help compare major.minor.patch versions
Ссылка на сайт

Ссылка на сайт

https://github.com/kcthota/version4j
Система контроля версий

Система контроля версий

https://github.com/kcthota/version4j

Скачать version4j

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/com.kcthota/version4j/ -->
<dependency>
    <groupId>com.kcthota</groupId>
    <artifactId>version4j</artifactId>
    <version>4.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.kcthota/version4j/
implementation 'com.kcthota:version4j:4.0'
// https://jarcasting.com/artifacts/com.kcthota/version4j/
implementation ("com.kcthota:version4j:4.0")
'com.kcthota:version4j:jar:4.0'
<dependency org="com.kcthota" name="version4j" rev="4.0">
  <artifact name="version4j" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.kcthota', module='version4j', version='4.0')
)
libraryDependencies += "com.kcthota" % "version4j" % "4.0"
[com.kcthota/version4j "4.0"]

Зависимости

test (2)

Идентификатор библиотеки Тип Версия
junit : junit jar 4.12
org.assertj : assertj-core jar 3.2.0

Модули Проекта

Данный проект не имеет модулей.

version4j

=============

Build Status Coverage Status Maven Central

Library to help compare major.minor.patch versions.

Implements the standard Comparable and Comparator Interfaces.

Usage

Stable:

<dependency>
	<groupId>com.kcthota</groupId>
	<artifactId>version4j</artifactId>
	<version>4.0</version>
</dependency>

Examples

Parse Version

Attempts to parse the String to Version Object. Throws VersionNotValidException if fails to parse the String.

Currently only support major.minor.patch format. And the value of any of these parts cannot be greater than 100000.

Version.parseVersion("1.1.2"); //parsed as 1.1.2

Version.parseVersion("1"); //parsed as 1.0.0

Version.parseVersion("1.2"); //parsed as 1.2.0

Version.parseVersion("1.2.3c"); //parsed as 1.2.3

Version.parseVersion("1.2.3c"); //parsed as 1.2.3

Version.parseVersion("1.2.3.4.5"); //parsed as 1.2.3

Version.parseVersion(" "); //throws VersionNotValidException

Version.parseVersion(null); //throws VersionNotValidException

Version.parseVersion("100001.0.0"); //throws VersionNotValidException

Try Parse

Tries to parse the passed String. Returns true if successfully parses the String or returns false.

This method does not throw an exception.

Version.tryParse("1.1.2"); //true

Version.tryParse("1"); //true

Version.tryParse("1.2"); //true

Version.tryParse("1.2.3c"); //true

Version.tryParse("1.2.3c"); //true

Version.tryParse("1.2.3.4.5"); //true

Version.tryParse(" "); //false

Version.tryParse(null); //false

Version.tryParse("100001.0.0"); //false

CompareTo

Standard Comparable interface

Version v1 = new Version("1.2.3");
		
Version v2 = Version.parseVersion("1.2");
		
v1.compareTo(v2); //1

Greater than

Version v1 = new Version("0.1.9");
		
Version v2 = new Version("0.0.9");
		
v1.greaterThan(v2); //true

Less than

Version v1 = new Version("2.0.9");
		
Version v2 = new Version("10.0.1");
		
v1.lessThan(v2); //true

Sort Versions

Sorts the versions in ascending order

Version v1 = new Version("2.0.0");
Version v2 = new Version("0.095.3");
Version v3 = new Version("10.0.1");
Version v4 = new Version("0.0.1");

List<Version> versions = new ArrayList<Version>();
versions.add(v1);
versions.add(v2);
versions.add(v3);
versions.add(v4);

versions.sort(new VersionComparator());

#License

The MIT License

Copyright 2016 Krishna Chaitanya Thota. All rights reserved.

#References

Inspired by Version class from .NET framework at https://msdn.microsoft.com/en-us/library/system.version(v=vs.100).aspx

Версии библиотеки

Версия
4.0
3.0
2.0
1.0