[BEANUTILS-527] Convert from Collections4 to java.util.function #8.
org.apache.commons.beanutils2.BeanMap.Entry extends
java.util.AbstractMap.SimpleEntry<K, V> instead of
org.apache.commons.collections4.keyvalue.AbstractMapEntry. Also type
keys as Strings instead of Objects.
diff --git a/src/main/java/org/apache/commons/beanutils2/BeanMap.java b/src/main/java/org/apache/commons/beanutils2/BeanMap.java
index 1e06488..337fa96 100644
--- a/src/main/java/org/apache/commons/beanutils2/BeanMap.java
+++ b/src/main/java/org/apache/commons/beanutils2/BeanMap.java
@@ -34,8 +34,6 @@
import java.util.Set;
import java.util.function.Function;
-import org.apache.commons.collections4.keyvalue.AbstractMapEntry;
-
/**
* An implementation of Map for JavaBeans which uses introspection to get and put properties in the bean.
* <p>
@@ -43,7 +41,7 @@
* Map
* </p>
*/
-public class BeanMap extends AbstractMap<Object, Object> implements Cloneable {
+public class BeanMap extends AbstractMap<String, Object> implements Cloneable {
private transient Object bean;
@@ -167,7 +165,7 @@
// copy only properties that are readable and writable. If its
// not readable, we can't get the value from the old map. If
// its not writable, we can't write a value into the new map.
- for (final Object key : readMethods.keySet()) {
+ for (final String key : readMethods.keySet()) {
if (getWriteMethod(key) != null) {
newMap.put(key, get(key));
}
@@ -189,7 +187,7 @@
* @param map the BeanMap whose properties to put
*/
public void putAllWriteable(final BeanMap map) {
- for (final Object key : map.readMethods.keySet()) {
+ for (final String key : map.readMethods.keySet()) {
if (getWriteMethod(key) != null) {
this.put(key, map.get(key));
}
@@ -294,7 +292,7 @@
* @throws ClassCastException if an error occurs creating the method args
*/
@Override
- public Object put(final Object name, final Object value) throws IllegalArgumentException, ClassCastException {
+ public Object put(final String name, final Object value) throws IllegalArgumentException, ClassCastException {
if (bean != null) {
final Object oldValue = get(name);
final Method method = getWriteMethod(name);
@@ -348,7 +346,7 @@
// The set actually contains strings; however, because it cannot be
// modified there is no danger in selling it as Set<Object>
@Override
- public Set<Object> keySet() {
+ public Set<String> keySet() {
return Collections.unmodifiableSet((Set) readMethods.keySet());
}
@@ -360,10 +358,10 @@
* @return the unmodifiable set of mappings
*/
@Override
- public Set<Map.Entry<Object, Object>> entrySet() {
- return Collections.unmodifiableSet(new AbstractSet<Map.Entry<Object, Object>>() {
+ public Set<Map.Entry<String, Object>> entrySet() {
+ return Collections.unmodifiableSet(new AbstractSet<Map.Entry<String, Object>>() {
@Override
- public Iterator<Map.Entry<Object, Object>> iterator() {
+ public Iterator<Map.Entry<String, Object>> iterator() {
return entryIterator();
}
@@ -443,17 +441,17 @@
*
* @return an iterator over the entries
*/
- public Iterator<Map.Entry<Object, Object>> entryIterator() {
+ public Iterator<Map.Entry<String, Object>> entryIterator() {
final Iterator<String> iter = keyIterator();
- return new Iterator<Map.Entry<Object, Object>>() {
+ return new Iterator<Map.Entry<String, Object>>() {
@Override
public boolean hasNext() {
return iter.hasNext();
}
@Override
- public Map.Entry<Object, Object> next() {
- final Object key = iter.next();
+ public Map.Entry<String, Object> next() {
+ final String key = iter.next();
final Object value = get(key);
// This should not cause any problems; the key is actually a
// string, but it does no harm to expose it as Object
@@ -595,7 +593,9 @@
/**
* Map entry used by {@link BeanMap}.
*/
- protected static class Entry extends AbstractMapEntry<Object, Object> {
+ protected static class Entry extends AbstractMap.SimpleEntry<String, Object> {
+
+ private static final long serialVersionUID = 1L;
private final BeanMap owner;
/**
@@ -605,7 +605,7 @@
* @param key the key for this entry
* @param value the value for this entry
*/
- protected Entry(final BeanMap owner, final Object key, final Object value) {
+ protected Entry(final BeanMap owner, final String key, final Object value) {
super(key, value);
this.owner = owner;
}
@@ -618,7 +618,7 @@
*/
@Override
public Object setValue(final Object value) {
- final Object key = getKey();
+ final String key = getKey();
final Object oldValue = owner.get(key);
owner.put(key, value);
diff --git a/src/test/java/org/apache/commons/beanutils2/BeanMapTestCase.java b/src/test/java/org/apache/commons/beanutils2/BeanMapTestCase.java
index e3a1d87..c003c07 100644
--- a/src/test/java/org/apache/commons/beanutils2/BeanMapTestCase.java
+++ b/src/test/java/org/apache/commons/beanutils2/BeanMapTestCase.java
@@ -269,7 +269,7 @@
}
@Override
- public Map<Object, Object> makeFullMap() {
+ public Map<String, Object> makeFullMap() {
// note: These values must match (i.e. .equals() must return true)
// those returned from getSampleValues().
final BeanWithProperties bean = new BeanWithProperties();
@@ -287,7 +287,7 @@
}
@Override
- public Map<Object, Object> makeEmptyMap() {
+ public Map<String, Object> makeEmptyMap() {
return new BeanMap();
}
@@ -466,7 +466,7 @@
}
try {
- final Map<Object, Object> map = new BeanMap(new BeanThrowingExceptions());
+ final Map<String, Object> map = new BeanMap(new BeanThrowingExceptions());
map.put("valueThrowingException", "value");
fail("Setter exception - expected IllegalArgumentException");
} catch (final IllegalArgumentException e) {