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> {
|
public abstract class AbstractKeyValue<K, V> implements KeyValue<K, V> {
|
||||||
|
|
||||||
/** The key */
|
/** The key */
|
||||||
protected K key;
|
private K key;
|
||||||
/** The value */
|
/** The value */
|
||||||
protected V value;
|
private V value;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new pair with the specified key and given 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;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected K setKey(K key) {
|
||||||
|
final K old = this.key;
|
||||||
|
this.key = key;
|
||||||
|
return old;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the value from the pair.
|
* Gets the value from the pair.
|
||||||
*
|
*
|
||||||
@ -62,6 +68,12 @@ public abstract class AbstractKeyValue<K, V> implements KeyValue<K, V> {
|
|||||||
return value;
|
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.
|
* 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
|
* @param value the new value
|
||||||
* @return the previous value
|
* @return the previous value
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public V setValue(final V value) {
|
public V setValue(final V value) {
|
||||||
final V answer = this.value;
|
return super.setValue(value);
|
||||||
this.value = value;
|
|
||||||
return answer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -77,14 +77,13 @@ public class DefaultKeyValue<K, V> extends AbstractKeyValue<K, V> {
|
|||||||
* @return the old key
|
* @return the old key
|
||||||
* @throws IllegalArgumentException if key is this object
|
* @throws IllegalArgumentException if key is this object
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public K setKey(final K key) {
|
public K setKey(final K key) {
|
||||||
if (key == this) {
|
if (key == this) {
|
||||||
throw new IllegalArgumentException("DefaultKeyValue may not contain itself as a key.");
|
throw new IllegalArgumentException("DefaultKeyValue may not contain itself as a key.");
|
||||||
}
|
}
|
||||||
|
|
||||||
final K old = this.key;
|
return super.setKey(key);
|
||||||
this.key = key;
|
|
||||||
return old;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -94,14 +93,13 @@ public class DefaultKeyValue<K, V> extends AbstractKeyValue<K, V> {
|
|||||||
* @param value the new value
|
* @param value the new value
|
||||||
* @throws IllegalArgumentException if value is this object
|
* @throws IllegalArgumentException if value is this object
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public V setValue(final V value) {
|
public V setValue(final V value) {
|
||||||
if (value == this) {
|
if (value == this) {
|
||||||
throw new IllegalArgumentException("DefaultKeyValue may not contain itself as a value.");
|
throw new IllegalArgumentException("DefaultKeyValue may not contain itself as a value.");
|
||||||
}
|
}
|
||||||
|
|
||||||
final V old = this.value;
|
return super.setValue(value);
|
||||||
this.value = value;
|
|
||||||
return old;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
Loading…
x
Reference in New Issue
Block a user