    001/*
    002 * Forge Mod Loader
    003 * Copyright (c) 2012-2013 cpw.
    004 * All rights reserved. This program and the accompanying materials
    005 * are made available under the terms of the GNU Lesser Public License v2.1
    006 * which accompanies this distribution, and is available at
    007 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
    008 *
    009 * Contributors:
    010 *     cpw - implementation
    011 */
    012
    013package cpw.mods.fml.common.versioning;
    014
    015public class DefaultArtifactVersion implements ArtifactVersion
    016{
    017
    018    private ComparableVersion comparableVersion;
    019    private String label;
    020    private boolean unbounded;
    021    private VersionRange range;
    022
    023    public DefaultArtifactVersion(String versionNumber)
    024    {
    025        comparableVersion = new ComparableVersion(versionNumber);
    026        range = VersionRange.createFromVersion(versionNumber, this);
    027    }
    028
    029    public DefaultArtifactVersion(String label, VersionRange range)
    030    {
    031        this.label = label;
    032        this.range = range;
    033    }
    034    public DefaultArtifactVersion(String label, String version)
    035    {
    036        this(version);
    037        this.label = label;
    038    }
    039
    040    public DefaultArtifactVersion(String string, boolean unbounded)
    041    {
    042        this.label = string;
    043        this.unbounded = true;
    044    }
    045
    046    @Override
    047    public boolean equals(Object obj)
    048    {
    049        return ((DefaultArtifactVersion)obj).containsVersion(this);
    050    }
    051
    052    @Override
    053    public int compareTo(ArtifactVersion o)
    054    {
    055        return unbounded ? 0 : this.comparableVersion.compareTo(((DefaultArtifactVersion)o).comparableVersion);
    056    }
    057
    058    @Override
    059    public String getLabel()
    060    {
    061        return label;
    062    }
    063
    064    @Override
    065    public boolean containsVersion(ArtifactVersion source)
    066    {
    067        if (!source.getLabel().equals(getLabel()))
    068        {
    069            return false;
    070        }
    071        if (unbounded)
    072        {
    073            return true;
    074        }
    075        if (range != null)
    076        {
    077            return range.containsVersion(source);
    078        }
    079        else
    080        {
    081            return false;
    082        }
    083    }
    084
    085    @Override
    086    public String getVersionString()
    087    {
    088        return comparableVersion == null ? "unknown" : comparableVersion.toString();
    089    }
    090
    091    @Override
    092    public String getRangeString()
    093    {
    094        return range == null ? "any" : range.toString();
    095    }
    096    @Override
    097    public String toString()
    098    {
    099        return label == null ? comparableVersion.toString() : label + ( unbounded ? "" : "@" + range);
    100    }
    101
    102    public VersionRange getRange()
    103    {
    104        return range;
    105    }
    106}