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

Class Method, % Line, %
StandardRowSortedTable 50% (3/6) 57.1% (4/7)
StandardRowSortedTable$RowSortedMap 11.1% (1/9) 6.2% (1/16)
Total 26.7% (4/15) 21.7% (5/23)


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.base.Supplier; 23 import com.google.j2objc.annotations.WeakOuter; 24 import java.util.Comparator; 25 import java.util.Map; 26 import java.util.Set; 27 import java.util.SortedMap; 28 import java.util.SortedSet; 29  30 /** 31  * Implementation of {@code Table} whose iteration ordering across row keys is sorted by their 32  * natural ordering or by a supplied comparator. Note that iterations across the columns keys for a 33  * single row key may or may not be ordered, depending on the implementation. When rows and columns 34  * are both sorted, it's easier to use the {@link TreeBasedTable} subclass. 35  * 36  * <p>The {@link #rowKeySet} method returns a {@link SortedSet} and the {@link #rowMap} method 37  * returns a {@link SortedMap}, instead of the {@link Set} and {@link Map} specified by the {@link 38  * Table} interface. 39  * 40  * <p>Null keys and values are not supported. 41  * 42  * <p>See the {@link StandardTable} superclass for more information about the behavior of this 43  * class. 44  * 45  * @author Jared Levy 46  */ 47 @GwtCompatible 48 class StandardRowSortedTable<R, C, V> extends StandardTable<R, C, V> 49  implements RowSortedTable<R, C, V> { 50  /* 51  * TODO(jlevy): Consider adding headTable, tailTable, and subTable methods, 52  * which return a Table view with rows keys in a given range. Create a 53  * RowSortedTable subinterface with the revised methods? 54  */ 55  56  StandardRowSortedTable( 57  SortedMap<R, Map<C, V>> backingMap, Supplier<? extends Map<C, V>> factory) { 58  super(backingMap, factory); 59  } 60  61  private SortedMap<R, Map<C, V>> sortedBackingMap() { 62  return (SortedMap<R, Map<C, V>>) backingMap; 63  } 64  65  /** 66  * {@inheritDoc} 67  * 68  * <p>This method returns a {@link SortedSet}, instead of the {@code Set} specified in the {@link 69  * Table} interface. 70  */ 71  @Override 72  public SortedSet<R> rowKeySet() { 73  return (SortedSet<R>) rowMap().keySet(); 74  } 75  76  /** 77  * {@inheritDoc} 78  * 79  * <p>This method returns a {@link SortedMap}, instead of the {@code Map} specified in the {@link 80  * Table} interface. 81  */ 82  @Override 83  public SortedMap<R, Map<C, V>> rowMap() { 84  return (SortedMap<R, Map<C, V>>) super.rowMap(); 85  } 86  87  @Override 88  SortedMap<R, Map<C, V>> createRowMap() { 89  return new RowSortedMap(); 90  } 91  92  @WeakOuter 93  private class RowSortedMap extends RowMap implements SortedMap<R, Map<C, V>> { 94  @Override 95  public SortedSet<R> keySet() { 96  return (SortedSet<R>) super.keySet(); 97  } 98  99  @Override 100  SortedSet<R> createKeySet() { 101  return new Maps.SortedKeySet<>(this); 102  } 103  104  @Override 105  public Comparator<? super R> comparator() { 106  return sortedBackingMap().comparator(); 107  } 108  109  @Override 110  public R firstKey() { 111  return sortedBackingMap().firstKey(); 112  } 113  114  @Override 115  public R lastKey() { 116  return sortedBackingMap().lastKey(); 117  } 118  119  @Override 120  public SortedMap<R, Map<C, V>> headMap(R toKey) { 121  checkNotNull(toKey); 122  return new StandardRowSortedTable<R, C, V>(sortedBackingMap().headMap(toKey), factory) 123  .rowMap(); 124  } 125  126  @Override 127  public SortedMap<R, Map<C, V>> subMap(R fromKey, R toKey) { 128  checkNotNull(fromKey); 129  checkNotNull(toKey); 130  return new StandardRowSortedTable<R, C, V>(sortedBackingMap().subMap(fromKey, toKey), factory) 131  .rowMap(); 132  } 133  134  @Override 135  public SortedMap<R, Map<C, V>> tailMap(R fromKey) { 136  checkNotNull(fromKey); 137  return new StandardRowSortedTable<R, C, V>(sortedBackingMap().tailMap(fromKey), factory) 138  .rowMap(); 139  } 140  } 141  142  private static final long serialVersionUID = 0; 143 }