Coverage Summary for Class: ImmutableMapEntrySet (com.google.common.collect)
| Class | Method, % | Line, % |
|---|---|---|
| ImmutableMapEntrySet | 85.7% (6/7) | 81.8% (9/11) |
| ImmutableMapEntrySet$EntrySetSerializedForm | 100% (2/2) | 100% (4/4) |
| ImmutableMapEntrySet$RegularEntrySet | 50% (4/8) | 61.5% (8/13) |
| Total | 70.6% (12/17) | 75% (21/28) |
1 /* 2 * Copyright (C) 2008 The Guava Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.google.common.collect; 18 19 import com.google.common.annotations.GwtCompatible; 20 import com.google.common.annotations.GwtIncompatible; 21 import java.io.Serializable; 22 import java.util.Map.Entry; 23 import java.util.Spliterator; 24 import java.util.function.Consumer; 25 import org.checkerframework.checker.nullness.qual.Nullable; 26 27 /** 28 * {@code entrySet()} implementation for {@link ImmutableMap}. 29 * 30 * @author Jesse Wilson 31 * @author Kevin Bourrillion 32 */ 33 @GwtCompatible(emulated = true) 34 abstract class ImmutableMapEntrySet<K, V> extends ImmutableSet<Entry<K, V>> { 35 static final class RegularEntrySet<K, V> extends ImmutableMapEntrySet<K, V> { 36 private final transient ImmutableMap<K, V> map; 37 private final transient ImmutableList<Entry<K, V>> entries; 38 39 RegularEntrySet(ImmutableMap<K, V> map, Entry<K, V>[] entries) { 40 this(map, ImmutableList.<Entry<K, V>>asImmutableList(entries)); 41 } 42 43 RegularEntrySet(ImmutableMap<K, V> map, ImmutableList<Entry<K, V>> entries) { 44 this.map = map; 45 this.entries = entries; 46 } 47 48 @Override 49 ImmutableMap<K, V> map() { 50 return map; 51 } 52 53 @Override 54 @GwtIncompatible("not used in GWT") 55 int copyIntoArray(Object[] dst, int offset) { 56 return entries.copyIntoArray(dst, offset); 57 } 58 59 @Override 60 public UnmodifiableIterator<Entry<K, V>> iterator() { 61 return entries.iterator(); 62 } 63 64 @Override 65 public Spliterator<Entry<K, V>> spliterator() { 66 return entries.spliterator(); 67 } 68 69 @Override 70 public void forEach(Consumer<? super Entry<K, V>> action) { 71 entries.forEach(action); 72 } 73 74 @Override 75 ImmutableList<Entry<K, V>> createAsList() { 76 return new RegularImmutableAsList<>(this, entries); 77 } 78 } 79 80 ImmutableMapEntrySet() {} 81 82 abstract ImmutableMap<K, V> map(); 83 84 @Override 85 public int size() { 86 return map().size(); 87 } 88 89 @Override 90 public boolean contains(@Nullable Object object) { 91 if (object instanceof Entry) { 92 Entry<?, ?> entry = (Entry<?, ?>) object; 93 V value = map().get(entry.getKey()); 94 return value != null && value.equals(entry.getValue()); 95 } 96 return false; 97 } 98 99 @Override 100 boolean isPartialView() { 101 return map().isPartialView(); 102 } 103 104 @Override 105 @GwtIncompatible // not used in GWT 106 boolean isHashCodeFast() { 107 return map().isHashCodeFast(); 108 } 109 110 @Override 111 public int hashCode() { 112 return map().hashCode(); 113 } 114 115 @GwtIncompatible // serialization 116 @Override 117 Object writeReplace() { 118 return new EntrySetSerializedForm<>(map()); 119 } 120 121 @GwtIncompatible // serialization 122 private static class EntrySetSerializedForm<K, V> implements Serializable { 123 final ImmutableMap<K, V> map; 124 125 EntrySetSerializedForm(ImmutableMap<K, V> map) { 126 this.map = map; 127 } 128 129 Object readResolve() { 130 return map.entrySet(); 131 } 132 133 private static final long serialVersionUID = 0; 134 } 135 }