124 return defaultValue; 125 } 126 127 /** 128 * Returns true if the option has been set in any way. Note that this doesn't mean that the 129 * current value is different than the default. 130 */ 131 public boolean hasBeenSet(OptionValues values) { 132 return values.containsKey(this); 133 } 134 135 /** 136 * Gets the value of this option in {@code values}. 137 */ 138 public T getValue(OptionValues values) { 139 assert checkDescriptorExists(); 140 return values.get(this); 141 } 142 143 /** 144 * Sets the value of this option in a given map. The 145 * {@link #onValueUpdate(EconomicMap, Object, Object)} method is called once the value is set. 146 * 147 * @param values map of option values 148 * @param v the value to set for this key in {@code map} 149 */ 150 @SuppressWarnings("unchecked") 151 public void update(EconomicMap<OptionKey<?>, Object> values, Object v) { 152 T oldValue = (T) values.put(this, v); 153 onValueUpdate(values, oldValue, (T) v); 154 } 155 156 /** 157 * Sets the value of this option in a given map if it doesn't already have a value. The 158 * {@link #onValueUpdate(EconomicMap, Object, Object)} method is called once the value is set. 159 * 160 * @param values map of option values 161 * @param v the value to set for this key in {@code map} 162 */ 163 @SuppressWarnings("unchecked") | 124 return defaultValue; 125 } 126 127 /** 128 * Returns true if the option has been set in any way. Note that this doesn't mean that the 129 * current value is different than the default. 130 */ 131 public boolean hasBeenSet(OptionValues values) { 132 return values.containsKey(this); 133 } 134 135 /** 136 * Gets the value of this option in {@code values}. 137 */ 138 public T getValue(OptionValues values) { 139 assert checkDescriptorExists(); 140 return values.get(this); 141 } 142 143 /** 144 * Gets the value of this option in {@code values} if it is present, otherwise 145 * {@link #getDefaultValue()}. 146 */ 147 @SuppressWarnings("unchecked") 148 public T getValueOrDefault(EconomicMap<OptionKey<?>, Object> values) { 149 if (!values.containsKey(this)) { 150 return defaultValue; 151 } 152 return (T) values.get(this); 153 } 154 155 /** 156 * Sets the value of this option in a given map. The 157 * {@link #onValueUpdate(EconomicMap, Object, Object)} method is called once the value is set. 158 * 159 * @param values map of option values 160 * @param v the value to set for this key in {@code map} 161 */ 162 @SuppressWarnings("unchecked") 163 public void update(EconomicMap<OptionKey<?>, Object> values, Object v) { 164 T oldValue = (T) values.put(this, v); 165 onValueUpdate(values, oldValue, (T) v); 166 } 167 168 /** 169 * Sets the value of this option in a given map if it doesn't already have a value. The 170 * {@link #onValueUpdate(EconomicMap, Object, Object)} method is called once the value is set. 171 * 172 * @param values map of option values 173 * @param v the value to set for this key in {@code map} 174 */ 175 @SuppressWarnings("unchecked") |