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

Class Method, % Line, %
AbstractNavigableMap 0% (0/22) 0% (0/28)
AbstractNavigableMap$DescendingMap 0% (0/3) 0% (0/3)
Total 0% (0/25) 0% (0/31)


1 /* 2  * Copyright (C) 2012 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.GwtIncompatible; 20 import com.google.common.collect.Maps.IteratorBasedAbstractMap; 21 import java.util.Iterator; 22 import java.util.NavigableMap; 23 import java.util.NavigableSet; 24 import java.util.NoSuchElementException; 25 import java.util.Set; 26 import java.util.SortedMap; 27 import org.checkerframework.checker.nullness.qual.Nullable; 28  29 /** 30  * Skeletal implementation of {@link NavigableMap}. 31  * 32  * @author Louis Wasserman 33  */ 34 @GwtIncompatible 35 abstract class AbstractNavigableMap<K, V> extends IteratorBasedAbstractMap<K, V> 36  implements NavigableMap<K, V> { 37  38  @Override 39  public abstract @Nullable V get(@Nullable Object key); 40  41  @Override 42  public @Nullable Entry<K, V> firstEntry() { 43  return Iterators.getNext(entryIterator(), null); 44  } 45  46  @Override 47  public @Nullable Entry<K, V> lastEntry() { 48  return Iterators.getNext(descendingEntryIterator(), null); 49  } 50  51  @Override 52  public @Nullable Entry<K, V> pollFirstEntry() { 53  return Iterators.pollNext(entryIterator()); 54  } 55  56  @Override 57  public @Nullable Entry<K, V> pollLastEntry() { 58  return Iterators.pollNext(descendingEntryIterator()); 59  } 60  61  @Override 62  public K firstKey() { 63  Entry<K, V> entry = firstEntry(); 64  if (entry == null) { 65  throw new NoSuchElementException(); 66  } else { 67  return entry.getKey(); 68  } 69  } 70  71  @Override 72  public K lastKey() { 73  Entry<K, V> entry = lastEntry(); 74  if (entry == null) { 75  throw new NoSuchElementException(); 76  } else { 77  return entry.getKey(); 78  } 79  } 80  81  @Override 82  public @Nullable Entry<K, V> lowerEntry(K key) { 83  return headMap(key, false).lastEntry(); 84  } 85  86  @Override 87  public @Nullable Entry<K, V> floorEntry(K key) { 88  return headMap(key, true).lastEntry(); 89  } 90  91  @Override 92  public @Nullable Entry<K, V> ceilingEntry(K key) { 93  return tailMap(key, true).firstEntry(); 94  } 95  96  @Override 97  public @Nullable Entry<K, V> higherEntry(K key) { 98  return tailMap(key, false).firstEntry(); 99  } 100  101  @Override 102  public K lowerKey(K key) { 103  return Maps.keyOrNull(lowerEntry(key)); 104  } 105  106  @Override 107  public K floorKey(K key) { 108  return Maps.keyOrNull(floorEntry(key)); 109  } 110  111  @Override 112  public K ceilingKey(K key) { 113  return Maps.keyOrNull(ceilingEntry(key)); 114  } 115  116  @Override 117  public K higherKey(K key) { 118  return Maps.keyOrNull(higherEntry(key)); 119  } 120  121  abstract Iterator<Entry<K, V>> descendingEntryIterator(); 122  123  @Override 124  public SortedMap<K, V> subMap(K fromKey, K toKey) { 125  return subMap(fromKey, true, toKey, false); 126  } 127  128  @Override 129  public SortedMap<K, V> headMap(K toKey) { 130  return headMap(toKey, false); 131  } 132  133  @Override 134  public SortedMap<K, V> tailMap(K fromKey) { 135  return tailMap(fromKey, true); 136  } 137  138  @Override 139  public NavigableSet<K> navigableKeySet() { 140  return new Maps.NavigableKeySet<>(this); 141  } 142  143  @Override 144  public Set<K> keySet() { 145  return navigableKeySet(); 146  } 147  148  @Override 149  public NavigableSet<K> descendingKeySet() { 150  return descendingMap().navigableKeySet(); 151  } 152  153  @Override 154  public NavigableMap<K, V> descendingMap() { 155  return new DescendingMap(); 156  } 157  158  private final class DescendingMap extends Maps.DescendingMap<K, V> { 159  @Override 160  NavigableMap<K, V> forward() { 161  return AbstractNavigableMap.this; 162  } 163  164  @Override 165  Iterator<Entry<K, V>> entryIterator() { 166  return descendingEntryIterator(); 167  } 168  } 169 }