Rename Pair to KeyValue
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@131195 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
007d3e3702
commit
aaa866d0d6
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/pairs/Attic/AbstractPair.java,v 1.1 2003/09/25 22:47:49 scolebourne Exp $
|
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/pairs/Attic/AbstractKeyValue.java,v 1.1 2003/09/27 10:33:34 scolebourne Exp $
|
||||||
* ====================================================================
|
* ====================================================================
|
||||||
*
|
*
|
||||||
* The Apache Software License, Version 1.1
|
* The Apache Software License, Version 1.1
|
||||||
|
@ -58,17 +58,17 @@
|
||||||
package org.apache.commons.collections.pairs;
|
package org.apache.commons.collections.pairs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract Pair class to assist with creating Pair and Map Entry implementations.
|
* Abstract pair class to assist with creating KeyValue and MapEntry implementations.
|
||||||
*
|
*
|
||||||
* @since Commons Collections 3.0
|
* @since Commons Collections 3.0
|
||||||
* @version $Revision: 1.1 $ $Date: 2003/09/25 22:47:49 $
|
* @version $Revision: 1.1 $ $Date: 2003/09/27 10:33:34 $
|
||||||
*
|
*
|
||||||
* @author James Strachan
|
* @author James Strachan
|
||||||
* @author Michael A. Smith
|
* @author Michael A. Smith
|
||||||
* @author Neil O'Toole
|
* @author Neil O'Toole
|
||||||
* @author Stephen Colebourne
|
* @author Stephen Colebourne
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractPair {
|
public abstract class AbstractKeyValue implements KeyValue {
|
||||||
|
|
||||||
/** The key */
|
/** The key */
|
||||||
protected Object key;
|
protected Object key;
|
||||||
|
@ -81,7 +81,7 @@ public abstract class AbstractPair {
|
||||||
* @param key the key for the entry, may be null
|
* @param key the key for the entry, may be null
|
||||||
* @param value the value for the entry, may be null
|
* @param value the value for the entry, may be null
|
||||||
*/
|
*/
|
||||||
protected AbstractPair(Object key, Object value) {
|
protected AbstractKeyValue(Object key, Object value) {
|
||||||
super();
|
super();
|
||||||
this.key = key;
|
this.key = key;
|
||||||
this.value = value;
|
this.value = value;
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/pairs/Attic/AbstractMapEntry.java,v 1.1 2003/09/25 22:47:49 scolebourne Exp $
|
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/pairs/Attic/AbstractMapEntry.java,v 1.2 2003/09/27 10:33:34 scolebourne Exp $
|
||||||
* ====================================================================
|
* ====================================================================
|
||||||
*
|
*
|
||||||
* The Apache Software License, Version 1.1
|
* The Apache Software License, Version 1.1
|
||||||
|
@ -63,14 +63,14 @@ import java.util.Map;
|
||||||
* Abstract Pair class to assist with creating correct Map Entry implementations.
|
* Abstract Pair class to assist with creating correct Map Entry implementations.
|
||||||
*
|
*
|
||||||
* @since Commons Collections 3.0
|
* @since Commons Collections 3.0
|
||||||
* @version $Revision: 1.1 $ $Date: 2003/09/25 22:47:49 $
|
* @version $Revision: 1.2 $ $Date: 2003/09/27 10:33:34 $
|
||||||
*
|
*
|
||||||
* @author James Strachan
|
* @author James Strachan
|
||||||
* @author Michael A. Smith
|
* @author Michael A. Smith
|
||||||
* @author Neil O'Toole
|
* @author Neil O'Toole
|
||||||
* @author Stephen Colebourne
|
* @author Stephen Colebourne
|
||||||
*/
|
*/
|
||||||
public class AbstractMapEntry extends AbstractPair implements Map.Entry {
|
public class AbstractMapEntry extends AbstractKeyValue implements Map.Entry {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new entry with the given key and given value.
|
* Constructs a new entry with the given key and given value.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/pairs/Attic/KeyValuePair.java,v 1.1 2003/09/25 22:47:49 scolebourne Exp $
|
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/pairs/Attic/DefaultKeyValue.java,v 1.1 2003/09/27 10:33:34 scolebourne Exp $
|
||||||
* ====================================================================
|
* ====================================================================
|
||||||
*
|
*
|
||||||
* The Apache Software License, Version 1.1
|
* The Apache Software License, Version 1.1
|
||||||
|
@ -60,25 +60,25 @@ package org.apache.commons.collections.pairs;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A mutable key-value pair that does not implement Map Entry.
|
* A mutable KeyValue pair that does not implement MapEntry.
|
||||||
* <p>
|
* <p>
|
||||||
* Note that a <code>KeyValuePair</code> instance may not contain
|
* Note that a <code>DefaultKeyValue</code> instance may not contain
|
||||||
* itself as a key or value.
|
* itself as a key or value.
|
||||||
*
|
*
|
||||||
* @since Commons Collections 3.0
|
* @since Commons Collections 3.0
|
||||||
* @version $Revision: 1.1 $ $Date: 2003/09/25 22:47:49 $
|
* @version $Revision: 1.1 $ $Date: 2003/09/27 10:33:34 $
|
||||||
*
|
*
|
||||||
* @author James Strachan
|
* @author James Strachan
|
||||||
* @author Michael A. Smith
|
* @author Michael A. Smith
|
||||||
* @author Neil O'Toole
|
* @author Neil O'Toole
|
||||||
* @author Stephen Colebourne
|
* @author Stephen Colebourne
|
||||||
*/
|
*/
|
||||||
public class KeyValuePair extends AbstractPair {
|
public class DefaultKeyValue extends AbstractKeyValue {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new pair with a null key and null value.
|
* Constructs a new pair with a null key and null value.
|
||||||
*/
|
*/
|
||||||
public KeyValuePair() {
|
public DefaultKeyValue() {
|
||||||
super(null, null);
|
super(null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,27 +88,27 @@ public class KeyValuePair extends AbstractPair {
|
||||||
* @param key the key for the entry, may be null
|
* @param key the key for the entry, may be null
|
||||||
* @param value the value for the entry, may be null
|
* @param value the value for the entry, may be null
|
||||||
*/
|
*/
|
||||||
public KeyValuePair(final Object key, final Object value) {
|
public DefaultKeyValue(final Object key, final Object value) {
|
||||||
super(key, value);
|
super(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new pair from the specified Pair.
|
* Constructs a new pair from the specified KeyValue.
|
||||||
*
|
*
|
||||||
* @param pair the pair to copy, must not be null
|
* @param pair the pair to copy, must not be null
|
||||||
* @throws NullPointerException if the entry is null
|
* @throws NullPointerException if the entry is null
|
||||||
*/
|
*/
|
||||||
public KeyValuePair(final Pair pair) {
|
public DefaultKeyValue(final KeyValue pair) {
|
||||||
super(pair.getKey(), pair.getValue());
|
super(pair.getKey(), pair.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new pair from the specified Map Entry.
|
* Constructs a new pair from the specified MapEntry.
|
||||||
*
|
*
|
||||||
* @param entry the entry to copy, must not be null
|
* @param entry the entry to copy, must not be null
|
||||||
* @throws NullPointerException if the entry is null
|
* @throws NullPointerException if the entry is null
|
||||||
*/
|
*/
|
||||||
public KeyValuePair(final Map.Entry entry) {
|
public DefaultKeyValue(final Map.Entry entry) {
|
||||||
super(entry.getKey(), entry.getValue());
|
super(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ public class KeyValuePair extends AbstractPair {
|
||||||
*/
|
*/
|
||||||
public Object setKey(final Object key) {
|
public Object setKey(final Object key) {
|
||||||
if (key == this) {
|
if (key == this) {
|
||||||
throw new IllegalArgumentException("A KeyValuePair may not contain itself as a key.");
|
throw new IllegalArgumentException("DefaultKeyValue may not contain itself as a key.");
|
||||||
}
|
}
|
||||||
|
|
||||||
final Object old = this.key;
|
final Object old = this.key;
|
||||||
|
@ -139,7 +139,7 @@ public class KeyValuePair extends AbstractPair {
|
||||||
*/
|
*/
|
||||||
public Object setValue(final Object value) {
|
public Object setValue(final Object value) {
|
||||||
if (value == this) {
|
if (value == this) {
|
||||||
throw new IllegalArgumentException("A KeyValuePair may not contain itself as a value.");
|
throw new IllegalArgumentException("DefaultKeyValue may not contain itself as a value.");
|
||||||
}
|
}
|
||||||
|
|
||||||
final Object old = this.value;
|
final Object old = this.value;
|
||||||
|
@ -149,17 +149,19 @@ public class KeyValuePair extends AbstractPair {
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* Returns a new <code>Map.Entry</code> object with key and value from this <code>KeyValuePair</code>.
|
* Returns a new <code>Map.Entry</code> object with key and value from this pair.
|
||||||
|
*
|
||||||
|
* @return a MapEntry instance
|
||||||
*/
|
*/
|
||||||
public Map.Entry toMapEntry() {
|
public Map.Entry toMapEntry() {
|
||||||
return new DefaultMapEntry(this.getKey(), this.getValue());
|
return new DefaultMapEntry(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* Compares this Map Entry with another Map Entry.
|
* Compares this Map Entry with another Map Entry.
|
||||||
* <p>
|
* <p>
|
||||||
* Returns true if the compared object is also a <code>KeyValuePair</code>,
|
* Returns true if the compared object is also a <code>DefaultKeyValue</code>,
|
||||||
* and its key and value are equal to this object's key and value.
|
* and its key and value are equal to this object's key and value.
|
||||||
*
|
*
|
||||||
* @param obj the object to compare to
|
* @param obj the object to compare to
|
||||||
|
@ -169,11 +171,11 @@ public class KeyValuePair extends AbstractPair {
|
||||||
if (obj == this) {
|
if (obj == this) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (obj instanceof KeyValuePair == false) {
|
if (obj instanceof DefaultKeyValue == false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyValuePair other = (KeyValuePair) obj;
|
DefaultKeyValue other = (DefaultKeyValue) obj;
|
||||||
return
|
return
|
||||||
(getKey() == null ? other.getKey() == null : getKey().equals(other.getKey())) &&
|
(getKey() == null ? other.getKey() == null : getKey().equals(other.getKey())) &&
|
||||||
(getValue() == null ? other.getValue() == null : getValue().equals(other.getValue()));
|
(getValue() == null ? other.getValue() == null : getValue().equals(other.getValue()));
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/pairs/Attic/DefaultMapEntry.java,v 1.1 2003/09/25 22:47:49 scolebourne Exp $
|
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/pairs/Attic/DefaultMapEntry.java,v 1.2 2003/09/27 10:33:34 scolebourne Exp $
|
||||||
* ====================================================================
|
* ====================================================================
|
||||||
*
|
*
|
||||||
* The Apache Software License, Version 1.1
|
* The Apache Software License, Version 1.1
|
||||||
|
@ -61,10 +61,10 @@ import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A restricted implementation of {@link java.util.Map.Entry} that prevents
|
* A restricted implementation of {@link java.util.Map.Entry} that prevents
|
||||||
* the Map Entry contract from being broken.
|
* the MapEntry contract from being broken.
|
||||||
*
|
*
|
||||||
* @since Commons Collections 3.0
|
* @since Commons Collections 3.0
|
||||||
* @version $Revision: 1.1 $ $Date: 2003/09/25 22:47:49 $
|
* @version $Revision: 1.2 $ $Date: 2003/09/27 10:33:34 $
|
||||||
*
|
*
|
||||||
* @author James Strachan
|
* @author James Strachan
|
||||||
* @author Michael A. Smith
|
* @author Michael A. Smith
|
||||||
|
@ -84,17 +84,17 @@ public final class DefaultMapEntry extends AbstractMapEntry {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new entry from the specified Pair.
|
* Constructs a new entry from the specified KeyValue.
|
||||||
*
|
*
|
||||||
* @param pair the pair to copy, must not be null
|
* @param pair the pair to copy, must not be null
|
||||||
* @throws NullPointerException if the entry is null
|
* @throws NullPointerException if the entry is null
|
||||||
*/
|
*/
|
||||||
public DefaultMapEntry(final Pair pair) {
|
public DefaultMapEntry(final KeyValue pair) {
|
||||||
super(pair.getKey(), pair.getValue());
|
super(pair.getKey(), pair.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new entry from the specified Map Entry.
|
* Constructs a new entry from the specified MapEntry.
|
||||||
*
|
*
|
||||||
* @param entry the entry to copy, must not be null
|
* @param entry the entry to copy, must not be null
|
||||||
* @throws NullPointerException if the entry is null
|
* @throws NullPointerException if the entry is null
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/pairs/Attic/Pair.java,v 1.1 2003/09/25 22:47:49 scolebourne Exp $
|
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/pairs/Attic/KeyValue.java,v 1.1 2003/09/27 10:33:34 scolebourne Exp $
|
||||||
* ====================================================================
|
* ====================================================================
|
||||||
*
|
*
|
||||||
* The Apache Software License, Version 1.1
|
* The Apache Software License, Version 1.1
|
||||||
|
@ -58,14 +58,14 @@
|
||||||
package org.apache.commons.collections.pairs;
|
package org.apache.commons.collections.pairs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines a simple key value Pair.
|
* Defines a simple key value pair.
|
||||||
*
|
*
|
||||||
* @since Commons Collections 3.0
|
* @since Commons Collections 3.0
|
||||||
* @version $Revision: 1.1 $ $Date: 2003/09/25 22:47:49 $
|
* @version $Revision: 1.1 $ $Date: 2003/09/27 10:33:34 $
|
||||||
*
|
*
|
||||||
* @author Stephen Colebourne
|
* @author Stephen Colebourne
|
||||||
*/
|
*/
|
||||||
public interface Pair {
|
public interface KeyValue {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the key from the pair.
|
* Gets the key from the pair.
|
Loading…
Reference in New Issue