Java Regex Version Validate parseVersion(String s, String groupId, String artifactId)

Here you can find the source of parseVersion(String s, String groupId, String artifactId)

Description

parse Version

License

Open Source License

Declaration

public static Version parseVersion(String s, String groupId, String artifactId) 

Method Source Code

//package com.java2s;

import java.util.regex.Pattern;
import com.fasterxml.jackson.core.Version;

public class Main {
    private final static Pattern V_SEP = Pattern.compile("[-_./;:]");

    public static Version parseVersion(String s, String groupId, String artifactId) {
        if (s != null && (s = s.trim()).length() > 0) {
            String[] parts = V_SEP.split(s);
            return new Version(parseVersionPart(parts[0]), (parts.length > 1) ? parseVersionPart(parts[1]) : 0,
                    (parts.length > 2) ? parseVersionPart(parts[2]) : 0, (parts.length > 3) ? parts[3] : null,
                    groupId, artifactId);
        }//  w  w w . j  av a  2 s .  c o  m
        return null;
    }

    protected static int parseVersionPart(String s) {
        int number = 0;
        for (int i = 0, len = s.length(); i < len; ++i) {
            char c = s.charAt(i);
            if (c > '9' || c < '0')
                break;
            number = (number * 10) + (c - '0');
        }
        return number;
    }
}

Related

  1. parseVersion(final String versionString)
  2. parseVersion(String version, int defaultRevision)
  3. parseVersion(String version, String currentVersion)
  4. parseVersionNamespace(String versionNamespace)