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