Giter VIP home page Giter VIP logo

versioning-utils's Introduction

Versioning utils

This tiny library allows you to perform basic operations on Version objects, consisting of three parts, separated by a dot (release, major and minor respectively), for example: 1.12.2. You can check if a given version belongs to a certain range or pattern (e.g. 1.12.x)

Examples

public static void main(String[] args) {
    System.out.println(new Version("1.12.4"));  //Prints "Version: 1.12.4"
    System.out.println(new Version("1.12.4").compareTo(new Version("1.12.6")));  //Prints negative number
    System.out.println(new Version("1.13.1").compareTo(new Version("1.12.6")));  //Prints positive number

    System.out.println(new VersionPattern("1.12.x")); //Prints "VersionPattern: 1.12.x"
    System.out.println(new VersionPattern("1.12.x").test(new Version("1.12.4"))); //Prints "true"
    System.out.println(new VersionPattern("1.12.x").test(new Version("1.12.6"))); //Prints "true"
    System.out.println(new VersionPattern("1.12.x").test(new Version("1.13.1"))); //Prints "false"

    System.out.println(new VersionRange("1.0.0", "1.13.0").test(new Version("1.12.4")));  //Prints "true"
    System.out.println(new VersionRange("1.0.0", "1.13.0").test(new Version("1.12.15")));  //Prints "true"
    System.out.println(new VersionRange("1.0.0", "1.13.0").test(new Version("1.13.2")));  //Prints "false"

    System.out.println(VersionRange.minVersion("1.12.5").test(new Version("1.10.2")));  //Prints "false"
    System.out.println(VersionRange.maxVersion("1.12.5").test(new Version("1.10.2")));  //Prints "true"
    System.out.println(VersionRange.minVersion("1.12.5").test(new Version("1.13.2")));  //Prints "true"
    System.out.println(VersionRange.maxVersion("1.12.5").test(new Version("1.13.2")));  //Prints "false"

    matcherMatches(new VersionPattern("1.x.x"), new Version("1.0.0"));
    matcherMatches(new VersionRange("0.8.0", "2.0.0"), new Version("1.0.0"));
}

//This method was created to show you, that both VersionPattern and VersionRange implements Predicate<Version>
private static boolean matcherMatches(Predicate<Version> matcher, Version version) {
    return matcher.test(version);
}

versioning-utils's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.