mirror of
https://github.com/apache/commons-collections.git
synced 2025-02-08 02:59:29 +00:00
Privatise key & value; add protected setters (fields were protected)
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1477599 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
63252b4946
commit
5ce18d6487
@ -28,9 +28,9 @@ import org.apache.commons.collections4.KeyValue;
|
||||
public abstract class AbstractKeyValue<K, V> implements KeyValue<K, V> {
|
||||
|
||||
/** The key */
|
||||
protected K key;
|
||||
private K key;
|
||||
/** The value */
|
||||
protected V value;
|
||||
private V value;
|
||||
|
||||
/**
|
||||
* Constructs a new pair with the specified key and given value.
|
||||
@ -53,6 +53,12 @@ public abstract class AbstractKeyValue<K, V> implements KeyValue<K, V> {
|
||||
return key;
|
||||
}
|
||||
|
||||
protected K setKey(K key) {
|
||||
final K old = this.key;
|
||||
this.key = key;
|
||||
return old;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value from the pair.
|
||||
*
|
||||
@ -62,6 +68,12 @@ public abstract class AbstractKeyValue<K, V> implements KeyValue<K, V> {
|
||||
return value;
|
||||
}
|
||||
|
||||
protected V setValue(V value) {
|
||||
final V old = this.value;
|
||||
this.value = value;
|
||||
return old;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a debugging String view of the pair.
|
||||
*
|
||||
|
@ -48,10 +48,9 @@ public abstract class AbstractMapEntry<K, V> extends AbstractKeyValue<K, V> impl
|
||||
* @param value the new value
|
||||
* @return the previous value
|
||||
*/
|
||||
@Override
|
||||
public V setValue(final V value) {
|
||||
final V answer = this.value;
|
||||
this.value = value;
|
||||
return answer;
|
||||
return super.setValue(value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -77,14 +77,13 @@ public class DefaultKeyValue<K, V> extends AbstractKeyValue<K, V> {
|
||||
* @return the old key
|
||||
* @throws IllegalArgumentException if key is this object
|
||||
*/
|
||||
@Override
|
||||
public K setKey(final K key) {
|
||||
if (key == this) {
|
||||
throw new IllegalArgumentException("DefaultKeyValue may not contain itself as a key.");
|
||||
}
|
||||
|
||||
final K old = this.key;
|
||||
this.key = key;
|
||||
return old;
|
||||
return super.setKey(key);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -94,14 +93,13 @@ public class DefaultKeyValue<K, V> extends AbstractKeyValue<K, V> {
|
||||
* @param value the new value
|
||||
* @throws IllegalArgumentException if value is this object
|
||||
*/
|
||||
@Override
|
||||
public V setValue(final V value) {
|
||||
if (value == this) {
|
||||
throw new IllegalArgumentException("DefaultKeyValue may not contain itself as a value.");
|
||||
}
|
||||
|
||||
final V old = this.value;
|
||||
this.value = value;
|
||||
return old;
|
||||
return super.setValue(value);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user