|
|
4799b2 |
From 066f654cd6a1b9d3bfd54565af1d618dada2deb4 Mon Sep 17 00:00:00 2001
|
|
|
4799b2 |
From: Michael Simacek <msimacek@redhat.com>
|
|
|
4799b2 |
Date: Tue, 17 Nov 2015 01:02:55 +0100
|
|
|
4799b2 |
Subject: [PATCH] Port to Java 8
|
|
|
4799b2 |
|
|
|
4799b2 |
---
|
|
|
4799b2 |
src/java/org/apache/commons/collections/MultiHashMap.java | 8 ++++----
|
|
|
4799b2 |
src/java/org/apache/commons/collections/MultiMap.java | 4 ++--
|
|
|
4799b2 |
src/java/org/apache/commons/collections/map/MultiKeyMap.java | 8 +++++---
|
|
|
4799b2 |
src/java/org/apache/commons/collections/map/MultiValueMap.java | 8 ++++----
|
|
|
4799b2 |
src/test/org/apache/commons/collections/TestMultiHashMap.java | 10 +++++-----
|
|
|
4799b2 |
.../org/apache/commons/collections/map/TestMultiKeyMap.java | 4 ++--
|
|
|
4799b2 |
6 files changed, 22 insertions(+), 20 deletions(-)
|
|
|
4799b2 |
|
|
|
4799b2 |
diff --git a/src/java/org/apache/commons/collections/MultiHashMap.java b/src/java/org/apache/commons/collections/MultiHashMap.java
|
|
|
4799b2 |
index 7fec9af..bcb4a11 100644
|
|
|
4799b2 |
--- a/src/java/org/apache/commons/collections/MultiHashMap.java
|
|
|
4799b2 |
+++ b/src/java/org/apache/commons/collections/MultiHashMap.java
|
|
|
4799b2 |
@@ -331,21 +331,21 @@ public class MultiHashMap extends HashMap implements MultiMap {
|
|
|
4799b2 |
* @param item the value to remove
|
|
|
4799b2 |
* @return the value removed (which was passed in), null if nothing removed
|
|
|
4799b2 |
*/
|
|
|
4799b2 |
- public Object remove(Object key, Object item) {
|
|
|
4799b2 |
+ public boolean remove(Object key, Object item) {
|
|
|
4799b2 |
Collection valuesForKey = getCollection(key);
|
|
|
4799b2 |
if (valuesForKey == null) {
|
|
|
4799b2 |
- return null;
|
|
|
4799b2 |
+ return false;
|
|
|
4799b2 |
}
|
|
|
4799b2 |
boolean removed = valuesForKey.remove(item);
|
|
|
4799b2 |
if (removed == false) {
|
|
|
4799b2 |
- return null;
|
|
|
4799b2 |
+ return false;
|
|
|
4799b2 |
}
|
|
|
4799b2 |
// remove the list if it is now empty
|
|
|
4799b2 |
// (saves space, and allows equals to work)
|
|
|
4799b2 |
if (valuesForKey.isEmpty()){
|
|
|
4799b2 |
remove(key);
|
|
|
4799b2 |
}
|
|
|
4799b2 |
- return item;
|
|
|
4799b2 |
+ return true;
|
|
|
4799b2 |
}
|
|
|
4799b2 |
|
|
|
4799b2 |
/**
|
|
|
4799b2 |
diff --git a/src/java/org/apache/commons/collections/MultiMap.java b/src/java/org/apache/commons/collections/MultiMap.java
|
|
|
4799b2 |
index be9455b..4d9cc7d 100644
|
|
|
4799b2 |
--- a/src/java/org/apache/commons/collections/MultiMap.java
|
|
|
4799b2 |
+++ b/src/java/org/apache/commons/collections/MultiMap.java
|
|
|
4799b2 |
@@ -66,7 +66,7 @@ public interface MultiMap extends Map {
|
|
|
4799b2 |
* @throws ClassCastException if the key or value is of an invalid type
|
|
|
4799b2 |
* @throws NullPointerException if the key or value is null and null is invalid
|
|
|
4799b2 |
*/
|
|
|
4799b2 |
- public Object remove(Object key, Object item);
|
|
|
4799b2 |
+ public boolean remove(Object key, Object item);
|
|
|
4799b2 |
|
|
|
4799b2 |
//-----------------------------------------------------------------------
|
|
|
4799b2 |
/**
|
|
|
4799b2 |
@@ -144,7 +144,7 @@ public interface MultiMap extends Map {
|
|
|
4799b2 |
* @throws ClassCastException if the key is of an invalid type
|
|
|
4799b2 |
* @throws NullPointerException if the key is null and null keys are invalid
|
|
|
4799b2 |
*/
|
|
|
4799b2 |
- Object remove(Object key);
|
|
|
4799b2 |
+ //boolean remove(Object key);
|
|
|
4799b2 |
|
|
|
4799b2 |
/**
|
|
|
4799b2 |
* Gets a collection containing all the values in the map.
|
|
|
4799b2 |
diff --git a/src/java/org/apache/commons/collections/map/MultiKeyMap.java b/src/java/org/apache/commons/collections/map/MultiKeyMap.java
|
|
|
4799b2 |
index 9e3e02d..969d11e 100644
|
|
|
4799b2 |
--- a/src/java/org/apache/commons/collections/map/MultiKeyMap.java
|
|
|
4799b2 |
+++ b/src/java/org/apache/commons/collections/map/MultiKeyMap.java
|
|
|
4799b2 |
@@ -197,7 +197,7 @@ public class MultiKeyMap
|
|
|
4799b2 |
* @param key2 the second key
|
|
|
4799b2 |
* @return the value mapped to the removed key, null if key not in map
|
|
|
4799b2 |
*/
|
|
|
4799b2 |
- public Object remove(Object key1, Object key2) {
|
|
|
4799b2 |
+ public boolean remove(Object key1, Object key2) {
|
|
|
4799b2 |
int hashCode = hash(key1, key2);
|
|
|
4799b2 |
int index = map.hashIndex(hashCode, map.data.length);
|
|
|
4799b2 |
AbstractHashedMap.HashEntry entry = map.data[index];
|
|
|
4799b2 |
@@ -206,12 +206,14 @@ public class MultiKeyMap
|
|
|
4799b2 |
if (entry.hashCode == hashCode && isEqualKey(entry, key1, key2)) {
|
|
|
4799b2 |
Object oldValue = entry.getValue();
|
|
|
4799b2 |
map.removeMapping(entry, index, previous);
|
|
|
4799b2 |
- return oldValue;
|
|
|
4799b2 |
+ //return oldValue;
|
|
|
4799b2 |
+ return true;
|
|
|
4799b2 |
}
|
|
|
4799b2 |
previous = entry;
|
|
|
4799b2 |
entry = entry.next;
|
|
|
4799b2 |
}
|
|
|
4799b2 |
- return null;
|
|
|
4799b2 |
+ //return null;
|
|
|
4799b2 |
+ return false;
|
|
|
4799b2 |
}
|
|
|
4799b2 |
|
|
|
4799b2 |
/**
|
|
|
4799b2 |
diff --git a/src/java/org/apache/commons/collections/map/MultiValueMap.java b/src/java/org/apache/commons/collections/map/MultiValueMap.java
|
|
|
4799b2 |
index f44999b..79938dc 100644
|
|
|
4799b2 |
--- a/src/java/org/apache/commons/collections/map/MultiValueMap.java
|
|
|
4799b2 |
+++ b/src/java/org/apache/commons/collections/map/MultiValueMap.java
|
|
|
4799b2 |
@@ -153,19 +153,19 @@ public class MultiValueMap extends AbstractMapDecorator implements MultiMap {
|
|
|
4799b2 |
* @param value the value to remove
|
|
|
4799b2 |
* @return the value removed (which was passed in), null if nothing removed
|
|
|
4799b2 |
*/
|
|
|
4799b2 |
- public Object remove(Object key, Object value) {
|
|
|
4799b2 |
+ public boolean remove(Object key, Object value) {
|
|
|
4799b2 |
Collection valuesForKey = getCollection(key);
|
|
|
4799b2 |
if (valuesForKey == null) {
|
|
|
4799b2 |
- return null;
|
|
|
4799b2 |
+ return false;
|
|
|
4799b2 |
}
|
|
|
4799b2 |
boolean removed = valuesForKey.remove(value);
|
|
|
4799b2 |
if (removed == false) {
|
|
|
4799b2 |
- return null;
|
|
|
4799b2 |
+ return false;
|
|
|
4799b2 |
}
|
|
|
4799b2 |
if (valuesForKey.isEmpty()) {
|
|
|
4799b2 |
remove(key);
|
|
|
4799b2 |
}
|
|
|
4799b2 |
- return value;
|
|
|
4799b2 |
+ return true;
|
|
|
4799b2 |
}
|
|
|
4799b2 |
|
|
|
4799b2 |
/**
|
|
|
4799b2 |
diff --git a/src/test/org/apache/commons/collections/TestMultiHashMap.java b/src/test/org/apache/commons/collections/TestMultiHashMap.java
|
|
|
4799b2 |
index eca833a..f47c6f9 100644
|
|
|
4799b2 |
--- a/src/test/org/apache/commons/collections/TestMultiHashMap.java
|
|
|
4799b2 |
+++ b/src/test/org/apache/commons/collections/TestMultiHashMap.java
|
|
|
4799b2 |
@@ -464,11 +464,11 @@ public class TestMultiHashMap extends AbstractTestMap {
|
|
|
4799b2 |
map.put("A", "AA");
|
|
|
4799b2 |
map.put("A", "AB");
|
|
|
4799b2 |
map.put("A", "AC");
|
|
|
4799b2 |
- assertEquals(null, map.remove("C", "CA"));
|
|
|
4799b2 |
- assertEquals(null, map.remove("A", "AD"));
|
|
|
4799b2 |
- assertEquals("AC", map.remove("A", "AC"));
|
|
|
4799b2 |
- assertEquals("AB", map.remove("A", "AB"));
|
|
|
4799b2 |
- assertEquals("AA", map.remove("A", "AA"));
|
|
|
4799b2 |
+ assertEquals(false, map.remove("C", "CA"));
|
|
|
4799b2 |
+ assertEquals(false, map.remove("A", "AD"));
|
|
|
4799b2 |
+ assertEquals(true, map.remove("A", "AC"));
|
|
|
4799b2 |
+ assertEquals(true, map.remove("A", "AB"));
|
|
|
4799b2 |
+ assertEquals(true, map.remove("A", "AA"));
|
|
|
4799b2 |
assertEquals(new MultiHashMap(), map);
|
|
|
4799b2 |
}
|
|
|
4799b2 |
|
|
|
4799b2 |
diff --git a/src/test/org/apache/commons/collections/map/TestMultiKeyMap.java b/src/test/org/apache/commons/collections/map/TestMultiKeyMap.java
|
|
|
4799b2 |
index b1ee3d0..66fcade 100644
|
|
|
4799b2 |
--- a/src/test/org/apache/commons/collections/map/TestMultiKeyMap.java
|
|
|
4799b2 |
+++ b/src/test/org/apache/commons/collections/map/TestMultiKeyMap.java
|
|
|
4799b2 |
@@ -315,10 +315,10 @@ public class TestMultiKeyMap extends AbstractTestIterableMap {
|
|
|
4799b2 |
switch (key.size()) {
|
|
|
4799b2 |
case 2:
|
|
|
4799b2 |
assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1)));
|
|
|
4799b2 |
- assertEquals(value, multimap.remove(key.getKey(0), key.getKey(1)));
|
|
|
4799b2 |
+ assertEquals(true, multimap.remove(key.getKey(0), key.getKey(1)));
|
|
|
4799b2 |
assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1)));
|
|
|
4799b2 |
assertEquals(size - 1, multimap.size());
|
|
|
4799b2 |
- assertEquals(null, multimap.remove(key.getKey(0), key.getKey(1)));
|
|
|
4799b2 |
+ assertEquals(false, multimap.remove(key.getKey(0), key.getKey(1)));
|
|
|
4799b2 |
assertEquals(false, multimap.containsKey(key.getKey(0), key.getKey(1)));
|
|
|
4799b2 |
break;
|
|
|
4799b2 |
case 3:
|
|
|
4799b2 |
--
|
|
|
4799b2 |
2.5.0
|
|
|
4799b2 |
|