All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.axis2.description.Version Maven / Gradle / Ivy

Go to download

Core Parts of Axis2. This includes Axis2 engine, Client API, Addressing support, etc.,

There is a newer version: 1.8.2
Show newest version
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you 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.
 */

package org.apache.axis2.description;

import java.io.Serializable;
import java.text.ParseException;
import java.util.Arrays;

/**
 * Class representing a version number and implementing a comparison algorithm compatible
 * with Maven. This class is primarily used for module versions.
 */
public class Version implements Serializable, Comparable {
    private static final String S_SNAPSHOT = "SNAPSHOT";
    
    public static final Version SNAPSHOT = new Version(null, S_SNAPSHOT);
    
    private final int[] components;
    private final String qualifier;
    
    /**
     * Constructor.
     * 
     * @param components the numeric components of the version; may be null for SNAPSHOT version
     * @param qualifier the qualifier
     */
    public Version(int[] components, String qualifier) {
        this.components = components == null ? null : components.clone();
        this.qualifier = qualifier;
    }
    
    /**
     * Constructor that parses the version from a string. The version must have the
     * following format:
     * 
     * integer ( "." integer )* ( "-" qualifier )?
     * 
* * @param versionString the string representation of the version * @throws ParseException if the version is not in the correct format */ public Version(String versionString) throws ParseException { if (versionString.equals(S_SNAPSHOT)) { components = null; qualifier = S_SNAPSHOT; } else { int dashIndex = versionString.indexOf('-'); if (dashIndex != -1) { qualifier = versionString.substring(dashIndex + 1); versionString = versionString.substring(0, dashIndex); } else { qualifier = null; } String[] componentStrings = versionString.split("\\."); int l = componentStrings.length; components = new int[l]; for (int i=0; i0) { buffer.append('.'); } buffer.append(components[i]); } } if (qualifier != null) { if (components != null) { buffer.append('-'); } buffer.append(qualifier); } return buffer.toString(); } public int compareTo(Version o) { // components == null means SNAPSHOT and SNAPSHOT is always // assumed to be the most recent version if (components == null && o.components != null) { return 1; } else if (components != null && o.components == null) { return -1; } else if (components == null && o.components == null) { return 0; } // Now compare version components int l = Math.min(components.length, o.components.length); for (int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy