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