Package biz.massivedynamics.versioneer.version

Source Code of biz.massivedynamics.versioneer.version.AbstractVersion

/*
* The MIT License
*
* Copyright 2012 Massive Dynamics.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package biz.massivedynamics.versioneer.version;

import biz.massivedynamics.versioneer.version.impl.GenericVersion;

/**
* An abstract class that defines the skeleton of a version
* <br /> <br />
* All version classes must have this class as their parent
*
* @author Cruz Bishop
* @since 0.8.0.0
*/
public abstract class AbstractVersion implements Comparable<AbstractVersion>, Cloneable {
   
    /**
     * Creates a new abstract version
     *
     * @since 0.8.0.0
     */
    public AbstractVersion() {
        this(VersionType.STABLE, "");
    }
   
    /**
     * Creates a new abstract version
     *
     * @param type The version type to use
     * @since 0.8.0.0
     */
    public AbstractVersion(VersionType type) {
        this(type, "");
    }
   
    /**
     * Creates a new abstract version
     *
     * @param type The version type to use
     * @param codeName The code name to use
     * @since 1.1.1.0
     */
    public AbstractVersion(VersionType type, String codeName) {
        this.setType(type);
        this.setCodeName(codeName);
    }
   
    /**
     * The type of this version
     *
     * @since 0.8.0.0
     */
    private VersionType type;
   
    /**
     * Gets this version's type
     *
     * @return The type
     * @since 0.8.0.0
     */
    public final VersionType getType() {
        return this.type;
    }
   
    /**
     * Sets this version's type
     *
     * @param type The type to set
     * @since 0.8.0.0
     */
    public final void setType(VersionType type) {
        this.type = type;
    }
   
    /**
     * The code name of this version
     *
     * @since 1.1.1.0
     */
    private String codeName;
   
    /**
     * Gets the code name of this version
     *
     * @return The code name
     * @since 1.1.1.0
     */
    public final String getCodeName() {
        return this.codeName;
    }
   
    /**
     * Sets the code name of this version
     *
     * @param codeName The code name
     * @since 1.1.1.0
     */
    public final void setCodeName(String codeName) {
        this.codeName = codeName;
    }
   
    /**
     * Converts this abstract version to a generic version
     *
     * @return The generic representation of this version
     * @since 0.8.0.0
     */
    public abstract GenericVersion toGenericVersion();
   
    /**
     * Convert this version to a string
     * Doing this to ensure that it is ALWAYS done!
     *
     * @return A string
     * @since 0.8.0.0
     */
    @Override
    public abstract String toString();

    /**
     * Compares this version with another version for equality
     *
     * @param obj The other object, preferably a version!
     * @return True if equal, otherwise false
     * @since 1.1.1.0
     */
    @Override
    public final boolean equals(Object obj) {
        if (!(obj instanceof AbstractVersion))
            return false;
       
        //Set up the other version
        GenericVersion version = ((AbstractVersion) obj).toGenericVersion();
       
        //And compare
        return ((this.compareTo(version)) == 0);
    }

    /**
     * Gets this version's hashcode
     *
     * @return The hashcode
     * @since 1.1.0.0
     */
    @Override
    public abstract int hashCode();
   
    /**
     * Clones this version
     *
     * @return The clone
     * @since 1.1.0.0
     */
    @Override
    public abstract AbstractVersion clone();
   
}
TOP

Related Classes of biz.massivedynamics.versioneer.version.AbstractVersion

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.