< prev index next >

src/java.base/share/classes/java/util/ImmutableCollections.java

Print this page

        

*** 93,102 **** --- 93,107 ---- } else { return (List<E>)List.of(coll.toArray()); } } + @SuppressWarnings("unchecked") + static <E> List<E> emptyList() { + return (List<E>) ListN.EMPTY_LIST; + } + static abstract class AbstractImmutableList<E> extends AbstractImmutableCollection<E> implements List<E>, RandomAccess { // all mutating methods throw UnsupportedOperationException @Override public void add(int index, E element) { throw uoe(); }
*** 402,416 **** public int size() { return e1 != null ? 2 : 1; } @Override - public boolean isEmpty() { - return false; - } - - @Override public E get(int index) { if (index == 0) { return e0; } else if (index == 1 && e1 != null) { return e1; --- 407,416 ----
*** 483,493 **** elements = tmp; } @Override public boolean isEmpty() { ! return elements.length == 0; } @Override public int size() { return elements.length; --- 483,493 ---- elements = tmp; } @Override public boolean isEmpty() { ! return size() == 0; } @Override public int size() { return elements.length;
*** 554,563 **** --- 554,568 ---- @Override public abstract int hashCode(); } + @SuppressWarnings("unchecked") + static <E> Set<E> emptySet() { + return (Set<E>) SetN.EMPTY_SET; + } + static final class Set12<E> extends AbstractImmutableSet<E> implements Serializable { @Stable final E e0;
*** 582,596 **** public int size() { return (e1 == null) ? 1 : 2; } @Override - public boolean isEmpty() { - return false; - } - - @Override public boolean contains(Object o) { return o.equals(e0) || o.equals(e1); // implicit nullcheck of o } @Override --- 587,596 ----
*** 714,728 **** public int size() { return size; } @Override - public boolean isEmpty() { - return size == 0; - } - - @Override public boolean contains(Object o) { Objects.requireNonNull(o); return size > 0 && probe(o) >= 0; } --- 714,723 ----
*** 847,856 **** --- 842,856 ---- } } // ---------- Map Implementations ---------- + @SuppressWarnings("unchecked") + static <K,V> Map<K,V> emptyMap() { + return (Map<K,V>) MapN.EMPTY_MAP; + } + abstract static class AbstractImmutableMap<K,V> extends AbstractMap<K,V> implements Serializable { @Override public void clear() { throw uoe(); } @Override public V compute(K key, BiFunction<? super K,? super V,? extends V> rf) { throw uoe(); } @Override public V computeIfAbsent(K key, Function<? super K,? extends V> mf) { throw uoe(); } @Override public V computeIfPresent(K key, BiFunction<? super K,? super V,? extends V> rf) { throw uoe(); }
*** 880,913 **** public Set<Map.Entry<K,V>> entrySet() { return Set.of(new KeyValueHolder<>(k0, v0)); } @Override - public V get(Object o) { - return o.equals(k0) ? v0 : null; // implicit nullcheck of o - } - - @Override public boolean containsKey(Object o) { return o.equals(k0); // implicit nullcheck of o } @Override public boolean containsValue(Object o) { return o.equals(v0); // implicit nullcheck of o } - @Override - public int size() { - return 1; - } - - @Override - public boolean isEmpty() { - return false; - } - private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { throw new InvalidObjectException("not serial proxy"); } private Object writeReplace() { --- 880,898 ----
*** 1021,1035 **** @Override public int size() { return size; } - @Override - public boolean isEmpty() { - return size == 0; - } - class MapNIterator implements Iterator<Map.Entry<K,V>> { private int remaining; private int idx; --- 1006,1015 ----
*** 1266,1276 **** return List.of(array); case IMM_SET: return Set.of(array); case IMM_MAP: if (array.length == 0) { ! return ImmutableCollections.MapN.EMPTY_MAP; } else if (array.length == 2) { return new ImmutableCollections.Map1<>(array[0], array[1]); } else { return new ImmutableCollections.MapN<>(array); } --- 1246,1256 ---- return List.of(array); case IMM_SET: return Set.of(array); case IMM_MAP: if (array.length == 0) { ! return ImmutableCollections.emptyMap(); } else if (array.length == 2) { return new ImmutableCollections.Map1<>(array[0], array[1]); } else { return new ImmutableCollections.MapN<>(array); }
< prev index next >