1 11 12 package org.eclipse.core.commands; 13 14 import java.util.Iterator ; 15 import java.util.Map ; 16 17 import org.eclipse.core.internal.commands.util.Util; 18 19 28 public final class Parameterization { 29 30 34 private static final int HASH_CODE_NOT_COMPUTED = -1; 35 36 39 private static final int HASH_FACTOR = 89; 40 41 44 private static final int HASH_INITIAL = Parameterization.class.getName() 45 .hashCode(); 46 47 51 private transient int hashCode = HASH_CODE_NOT_COMPUTED; 52 53 57 private final IParameter parameter; 58 59 63 private final String value; 64 65 74 public Parameterization(final IParameter parameter, final String value) { 75 if (parameter == null) { 76 throw new NullPointerException ( 77 "You cannot parameterize a null parameter"); } 79 80 this.parameter = parameter; 81 this.value = value; 82 } 83 84 87 public final boolean equals(final Object object) { 88 if (this == object) { 89 return true; 90 } 91 92 if (!(object instanceof Parameterization)) { 93 return false; 94 } 95 96 final Parameterization parameterization = (Parameterization) object; 97 if (!(Util.equals(this.parameter.getId(), parameterization.parameter 98 .getId()))) { 99 return false; 100 } 101 102 return Util.equals(this.value, parameterization.value); 103 } 104 105 110 public final IParameter getParameter() { 111 return parameter; 112 } 113 114 119 public final String getValue() { 120 return value; 121 } 122 123 132 public final String getValueName() throws ParameterValuesException { 133 final Map parameterValues = parameter.getValues().getParameterValues(); 134 final Iterator parameterValueItr = parameterValues.entrySet() 135 .iterator(); 136 String returnValue = null; 137 while (parameterValueItr.hasNext()) { 138 final Map.Entry entry = (Map.Entry ) parameterValueItr.next(); 139 final String currentValue = (String ) entry.getValue(); 140 if (Util.equals(value, currentValue)) { 141 returnValue = (String ) entry.getKey(); 142 break; 143 } 144 } 145 146 if (returnValue == null) { 147 return Util.ZERO_LENGTH_STRING; 148 } 149 150 return returnValue; 151 } 152 153 156 public final int hashCode() { 157 if (hashCode == HASH_CODE_NOT_COMPUTED) { 158 hashCode = HASH_INITIAL * HASH_FACTOR + Util.hashCode(parameter); 159 hashCode = hashCode * HASH_FACTOR + Util.hashCode(value); 160 if (hashCode == HASH_CODE_NOT_COMPUTED) { 161 hashCode++; 162 } 163 } 164 return hashCode; 165 166 } 167 } 168 | Popular Tags |