Coverage Summary for Class: ImmutableMapKeySet (com.google.common.collect)

Class Method, % Line, %
ImmutableMapKeySet 0% (0/8) 0% (0/12)
ImmutableMapKeySet$KeySetSerializedForm 0% (0/2) 0% (0/3)
Total 0% (0/10) 0% (0/15)


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.Spliterator; 25 import java.util.function.Consumer; 26 import org.checkerframework.checker.nullness.qual.Nullable; 27  28 /** 29  * {@code keySet()} implementation for {@link ImmutableMap}. 30  * 31  * @author Jesse Wilson 32  * @author Kevin Bourrillion 33  */ 34 @GwtCompatible(emulated = true) 35 final class ImmutableMapKeySet<K, V> extends IndexedImmutableSet<K> { 36  private final ImmutableMap<K, V> map; 37  38  ImmutableMapKeySet(ImmutableMap<K, V> map) { 39  this.map = map; 40  } 41  42  @Override 43  public int size() { 44  return map.size(); 45  } 46  47  @Override 48  public UnmodifiableIterator<K> iterator() { 49  return map.keyIterator(); 50  } 51  52  @Override 53  public Spliterator<K> spliterator() { 54  return map.keySpliterator(); 55  } 56  57  @Override 58  public boolean contains(@Nullable Object object) { 59  return map.containsKey(object); 60  } 61  62  @Override 63  K get(int index) { 64  return map.entrySet().asList().get(index).getKey(); 65  } 66  67  @Override 68  public void forEach(Consumer<? super K> action) { 69  checkNotNull(action); 70  map.forEach((k, v) -> action.accept(k)); 71  } 72  73  @Override 74  boolean isPartialView() { 75  return true; 76  } 77  78  // No longer used for new writes, but kept so that old data can still be read. 79  @GwtIncompatible // serialization 80  @SuppressWarnings("unused") 81  private static class KeySetSerializedForm<K> implements Serializable { 82  final ImmutableMap<K, ?> map; 83  84  KeySetSerializedForm(ImmutableMap<K, ?> map) { 85  this.map = map; 86  } 87  88  Object readResolve() { 89  return map.keySet(); 90  } 91  92  private static final long serialVersionUID = 0; 93  } 94 }