--- /dev/null
+// © 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();
+ }
+}
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;
// 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()));
}
/**