001 /* 002 * Created on Feb 13, 2009 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 005 * in compliance with the License. You may obtain a copy of the License at 006 * 007 * http://www.apache.org/licenses/LICENSE-2.0 008 * 009 * Unless required by applicable law or agreed to in writing, software distributed under the License 010 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 011 * or implied. See the License for the specific language governing permissions and limitations under 012 * the License. 013 * 014 * Copyright @2009-2010 the original author or authors. 015 */ 016 package org.fest.swing.data; 017 018 import static java.lang.String.valueOf; 019 import static org.fest.util.Objects.HASH_CODE_PRIME; 020 import static org.fest.util.Strings.concat; 021 022 /** 023 * Understands an index. 024 * 025 * @author Alex Ruiz 026 */ 027 public final class Index { 028 029 /** 030 * Creates a new <code>{@link Index}</code>. 031 * @param value the value of the index to create. 032 * @return the created index. 033 */ 034 public static Index atIndex(int value) { 035 return new Index(value); 036 } 037 038 /** The value of this index. */ 039 public final int value; 040 041 private Index(int value) { 042 this.value = value; 043 } 044 045 @Override public boolean equals(Object obj) { 046 if (this == obj) return true; 047 if (obj == null) return false; 048 if (!(obj instanceof Index)) return false; 049 Index other = (Index)obj; 050 return value == other.value; 051 } 052 053 @Override public int hashCode() { 054 int result = 1; 055 result = HASH_CODE_PRIME * result + value; 056 return result; 057 } 058 059 @Override public String toString() { 060 return concat(getClass().getName(), "[value=", valueOf(value), "]"); 061 } 062 }