Coverage Summary for Class: ImmutableMapEntry (com.google.common.collect)
| Class | Method, % | Line, % |
|---|---|---|
| ImmutableMapEntry | 50% (3/6) | 55.6% (5/9) |
| ImmutableMapEntry$NonTerminalImmutableBiMapEntry | 0% (0/2) | 0% (0/4) |
| ImmutableMapEntry$NonTerminalImmutableMapEntry | 66.7% (2/3) | 80% (4/5) |
| Total | 45.5% (5/11) | 50% (9/18) |
1 /* 2 * Copyright (C) 2013 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.collect.CollectPreconditions.checkEntryNotNull; 20 21 import com.google.common.annotations.GwtIncompatible; 22 import org.checkerframework.checker.nullness.qual.Nullable; 23 24 /** 25 * Implementation of {@code Entry} for {@link ImmutableMap} that adds extra methods to traverse hash 26 * buckets for the key and the value. This allows reuse in {@link RegularImmutableMap} and {@link 27 * RegularImmutableBiMap}, which don't have to recopy the entries created by their {@code Builder} 28 * implementations. 29 * 30 * <p>This base implementation has no key or value pointers, so instances of ImmutableMapEntry (but 31 * not its subclasses) can be reused when copied from one ImmutableMap to another. 32 * 33 * @author Louis Wasserman 34 */ 35 @GwtIncompatible // unnecessary 36 class ImmutableMapEntry<K, V> extends ImmutableEntry<K, V> { 37 /** 38 * Creates an {@code ImmutableMapEntry} array to hold parameterized entries. The result must never 39 * be upcast back to ImmutableMapEntry[] (or Object[], etc.), or allowed to escape the class. 40 */ 41 @SuppressWarnings("unchecked") // Safe as long as the javadocs are followed 42 static <K, V> ImmutableMapEntry<K, V>[] createEntryArray(int size) { 43 return new ImmutableMapEntry[size]; 44 } 45 46 ImmutableMapEntry(K key, V value) { 47 super(key, value); 48 checkEntryNotNull(key, value); 49 } 50 51 ImmutableMapEntry(ImmutableMapEntry<K, V> contents) { 52 super(contents.getKey(), contents.getValue()); 53 // null check would be redundant 54 } 55 56 @Nullable 57 ImmutableMapEntry<K, V> getNextInKeyBucket() { 58 return null; 59 } 60 61 @Nullable 62 ImmutableMapEntry<K, V> getNextInValueBucket() { 63 return null; 64 } 65 66 /** 67 * Returns true if this entry has no bucket links and can safely be reused as a terminal entry in 68 * a bucket in another map. 69 */ 70 boolean isReusable() { 71 return true; 72 } 73 74 static class NonTerminalImmutableMapEntry<K, V> extends ImmutableMapEntry<K, V> { 75 private final transient ImmutableMapEntry<K, V> nextInKeyBucket; 76 77 NonTerminalImmutableMapEntry(K key, V value, ImmutableMapEntry<K, V> nextInKeyBucket) { 78 super(key, value); 79 this.nextInKeyBucket = nextInKeyBucket; 80 } 81 82 @Override 83 final @Nullable ImmutableMapEntry<K, V> getNextInKeyBucket() { 84 return nextInKeyBucket; 85 } 86 87 @Override 88 final boolean isReusable() { 89 return false; 90 } 91 } 92 93 static final class NonTerminalImmutableBiMapEntry<K, V> 94 extends NonTerminalImmutableMapEntry<K, V> { 95 private final transient ImmutableMapEntry<K, V> nextInValueBucket; 96 97 NonTerminalImmutableBiMapEntry( 98 K key, 99 V value, 100 ImmutableMapEntry<K, V> nextInKeyBucket, 101 ImmutableMapEntry<K, V> nextInValueBucket) { 102 super(key, value, nextInKeyBucket); 103 this.nextInValueBucket = nextInValueBucket; 104 } 105 106 @Override 107 @Nullable 108 ImmutableMapEntry<K, V> getNextInValueBucket() { 109 return nextInValueBucket; 110 } 111 } 112 }