Coverage Summary for Class: ImmutableMapValues (com.google.common.collect)
| Class | Method, % | Line, % |
|---|---|---|
| ImmutableMapValues | 0% (0/9) | 0% (0/14) |
| ImmutableMapValues$1 | 0% (0/3) | 0% (0/4) |
| ImmutableMapValues$2 | 0% (0/3) | 0% (0/3) |
| ImmutableMapValues$SerializedForm | 0% (0/2) | 0% (0/3) |
| Total | 0% (0/17) | 0% (0/24) |
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 static com.google.common.base.Preconditions.checkNotNull; 20 21 import com.google.common.annotations.GwtCompatible; 22 import com.google.common.annotations.GwtIncompatible; 23 import java.io.Serializable; 24 import java.util.Map.Entry; 25 import java.util.Spliterator; 26 import java.util.function.Consumer; 27 import org.checkerframework.checker.nullness.qual.Nullable; 28 29 /** 30 * {@code values()} implementation for {@link ImmutableMap}. 31 * 32 * @author Jesse Wilson 33 * @author Kevin Bourrillion 34 */ 35 @GwtCompatible(emulated = true) 36 final class ImmutableMapValues<K, V> extends ImmutableCollection<V> { 37 private final ImmutableMap<K, V> map; 38 39 ImmutableMapValues(ImmutableMap<K, V> map) { 40 this.map = map; 41 } 42 43 @Override 44 public int size() { 45 return map.size(); 46 } 47 48 @Override 49 public UnmodifiableIterator<V> iterator() { 50 return new UnmodifiableIterator<V>() { 51 final UnmodifiableIterator<Entry<K, V>> entryItr = map.entrySet().iterator(); 52 53 @Override 54 public boolean hasNext() { 55 return entryItr.hasNext(); 56 } 57 58 @Override 59 public V next() { 60 return entryItr.next().getValue(); 61 } 62 }; 63 } 64 65 @Override 66 public Spliterator<V> spliterator() { 67 return CollectSpliterators.map(map.entrySet().spliterator(), Entry::getValue); 68 } 69 70 @Override 71 public boolean contains(@Nullable Object object) { 72 return object != null && Iterators.contains(iterator(), object); 73 } 74 75 @Override 76 boolean isPartialView() { 77 return true; 78 } 79 80 @Override 81 public ImmutableList<V> asList() { 82 final ImmutableList<Entry<K, V>> entryList = map.entrySet().asList(); 83 return new ImmutableAsList<V>() { 84 @Override 85 public V get(int index) { 86 return entryList.get(index).getValue(); 87 } 88 89 @Override 90 ImmutableCollection<V> delegateCollection() { 91 return ImmutableMapValues.this; 92 } 93 }; 94 } 95 96 @GwtIncompatible // serialization 97 @Override 98 public void forEach(Consumer<? super V> action) { 99 checkNotNull(action); 100 map.forEach((k, v) -> action.accept(v)); 101 } 102 103 // No longer used for new writes, but kept so that old data can still be read. 104 @GwtIncompatible // serialization 105 @SuppressWarnings("unused") 106 private static class SerializedForm<V> implements Serializable { 107 final ImmutableMap<?, V> map; 108 109 SerializedForm(ImmutableMap<?, V> map) { 110 this.map = map; 111 } 112 113 Object readResolve() { 114 return map.values(); 115 } 116 117 private static final long serialVersionUID = 0; 118 } 119 }