Java Version Convert To versionToSegments(String versionString, int idx, int i)

Here you can find the source of versionToSegments(String versionString, int idx, int i)

Description

version To Segments

License

Open Source License

Declaration

private static int[] versionToSegments(String versionString, int idx, int i) 

Method Source Code

//package com.java2s;
/*//from   w w  w. ja v a 2  s.co m
 * JBoss, Home of Professional Open Source.
 * Copyright 2013 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    private static int[] versionToSegments(String versionString, int idx, int i) {
        int c, d, a;
        c = versionString.codePointAt(idx);
        idx = versionString.offsetByCodePoints(idx, 1);
        d = Character.digit(c, 10);
        if (d == -1) {
            throw new IllegalArgumentException("String is not in version format");
        }
        a = d;
        for (;;) {
            c = versionString.codePointAt(idx);
            idx = versionString.offsetByCodePoints(idx, 1);
            if (c == '.') {
                final int[] ints = versionToSegments(versionString, idx + 1, i + 1);
                ints[i] = a;
                return ints;
            }
            d = Character.digit(c, 10);
            if (d == -1) {
                throw new IllegalArgumentException("String is not in version format");
            }
            a = a * 10 + d;
            if (idx == versionString.length()) {
                final int[] ints = new int[i + 1];
                ints[i] = a;
                return ints;
            }
        }
    }

    public static int[] versionToSegments(String versionString) {
        return versionToSegments(versionString, 0, 0);
    }
}

Related

  1. versionStringToInt(String version)
  2. versionStringToInt(String version)
  3. versionStringToNumber(String versionStr)
  4. versionToCode(String version)
  5. versionToString(int version)
  6. versiontostring(int vv)
  7. VersionToString(long uVersion)