001package org.eclipse.aether.internal.test.util;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 * 
012 *  http://www.apache.org/licenses/LICENSE-2.0
013 * 
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import org.eclipse.aether.version.Version;
023
024/**
025 * Version ordering by {@link String#compareToIgnoreCase(String)}.
026 */
027public final class TestVersion
028    implements Version
029{
030
031    private final String version;
032
033    public TestVersion( String version )
034    {
035        this.version = version == null ? "" : version;
036    }
037
038    public int compareTo( Version o )
039    {
040        return version.compareTo( o.toString() );
041    }
042
043    @Override
044    public int hashCode()
045    {
046        final int prime = 31;
047        int result = 1;
048        result = prime * result + ( ( version == null ) ? 0 : version.hashCode() );
049        return result;
050    }
051
052    @Override
053    public boolean equals( Object obj )
054    {
055        if ( this == obj )
056        {
057            return true;
058        }
059        if ( obj == null )
060        {
061            return false;
062        }
063        if ( getClass() != obj.getClass() )
064        {
065            return false;
066        }
067        TestVersion other = (TestVersion) obj;
068        if ( version == null )
069        {
070            if ( other.version != null )
071            {
072                return false;
073            }
074        }
075        else if ( !version.equals( other.version ) )
076        {
077            return false;
078        }
079        return true;
080    }
081
082    @Override
083    public String toString()
084    {
085        return version;
086    }
087
088}