]> granicus.if.org Git - icu/commitdiff
ICU-13620 Making MeasureUnit.getAvailable(type) return a Collection-based instead...
authorShane Carr <shane@unicode.org>
Sat, 3 Mar 2018 05:25:58 +0000 (05:25 +0000)
committerShane Carr <shane@unicode.org>
Sat, 3 Mar 2018 05:25:58 +0000 (05:25 +0000)
X-SVN-Rev: 41055

icu4j/main/classes/core/src/com/ibm/icu/impl/CollectionSet.java [new file with mode: 0644]
icu4j/main/classes/core/src/com/ibm/icu/util/MeasureUnit.java

diff --git a/icu4j/main/classes/core/src/com/ibm/icu/impl/CollectionSet.java b/icu4j/main/classes/core/src/com/ibm/icu/impl/CollectionSet.java
new file mode 100644 (file)
index 0000000..94e4a98
--- /dev/null
@@ -0,0 +1,85 @@
+// © 2018 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html#License
+package com.ibm.icu.impl;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Set;
+
+/**
+ * A wrapper around java.util.CollectionSet that implements java.util.Set. This class keeps a pointer to
+ * the CollectionSet and does not persist any data on its own.
+ */
+public class CollectionSet<E> implements Set<E> {
+
+    private final Collection<E> data;
+
+    public CollectionSet(Collection<E> data) {
+        this.data = data;
+    }
+
+    @Override
+    public int size() {
+        return data.size();
+    }
+
+    @Override
+    public boolean isEmpty() {
+        return data.isEmpty();
+    }
+
+    @Override
+    public boolean contains(Object o) {
+        return data.contains(o);
+    }
+
+    @Override
+    public Iterator<E> iterator() {
+        return data.iterator();
+    }
+
+    @Override
+    public Object[] toArray() {
+        return data.toArray();
+    }
+
+    @Override
+    public <T> T[] toArray(T[] a) {
+        return data.toArray(a);
+    }
+
+    @Override
+    public boolean add(E e) {
+        return data.add(e);
+    }
+
+    @Override
+    public boolean remove(Object o) {
+        return data.remove(o);
+    }
+
+    @Override
+    public boolean containsAll(Collection<?> c) {
+        return data.containsAll(c);
+    }
+
+    @Override
+    public boolean addAll(Collection<? extends E> c) {
+        return data.addAll(c);
+    }
+
+    @Override
+    public boolean retainAll(Collection<?> c) {
+        return data.retainAll(c);
+    }
+
+    @Override
+    public boolean removeAll(Collection<?> c) {
+        return data.removeAll(c);
+    }
+
+    @Override
+    public void clear() {
+        data.clear();
+    }
+}
index 50ebcc1e6300bcf771b1b6235f28222e903ef0da..d35c8dd8c0d4db494fda31c6c5aa0ac5dc247fff 100644 (file)
@@ -20,6 +20,7 @@ import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
+import com.ibm.icu.impl.CollectionSet;
 import com.ibm.icu.impl.ICUData;
 import com.ibm.icu.impl.ICUResourceBundle;
 import com.ibm.icu.impl.Pair;
@@ -150,7 +151,7 @@ public class MeasureUnit implements Serializable {
         // Train users not to modify returned set from the start giving us more
         // flexibility for implementation.
         return units == null ? Collections.<MeasureUnit>emptySet()
-                : Collections.unmodifiableSet(new HashSet<MeasureUnit>(units.values()));
+                : Collections.unmodifiableSet(new CollectionSet<MeasureUnit>(units.values()));
     }
 
     /**