com.fitbur.google.common.collect.StandardRowSortedTable Maven / Gradle / Ivy
/*
* Copyright (C) 2008 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in com.fitburpliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.com.fitbur/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.fitbur.google.com.fitburmon.collect;
import static com.fitbur.google.com.fitburmon.base.Preconditions.checkNotNull;
import com.fitbur.google.com.fitburmon.annotations.GwtCompatible;
import com.fitbur.google.com.fitburmon.base.Supplier;
import java.util.Comparator;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;
/**
* Implementation of {@code Table} whose iteration ordering across row keys is
* sorted by their natural ordering or by a supplied com.fitburparator. Note that
* iterations across the columns keys for a single row key may or may not be
* ordered, com.fitburpending on the implementation. When rows and columns are both
* sorted, it's easier to use the {@link TreeBasedTable} subclass.
*
* The {@link #rowKeySet} method returns a {@link SortedSet} and the {@link
* #rowMap} method returns a {@link SortedMap}, instead of the {@link Set} and
* {@link Map} specified by the {@link Table} interface.
*
*
Null keys and values are not supported.
*
*
See the {@link StandardTable} superclass for more information about the
* behavior of this class.
*
* @author Jared Levy
*/
@GwtCompatible
class StandardRowSortedTable extends StandardTable
implements RowSortedTable {
/*
* TODO(jlevy): Consider adding headTable, tailTable, and subTable methods,
* which return a Table view with rows keys in a given range. Create a
* RowSortedTable subinterface with the revised methods?
*/
StandardRowSortedTable(SortedMap> backingMap,
Supplier extends Map> factory) {
super(backingMap, factory);
}
private SortedMap> sortedBackingMap() {
return (SortedMap>) backingMap;
}
/**
* {@inheritDoc}
*
* This method returns a {@link SortedSet}, instead of the {@code Set}
* specified in the {@link Table} interface.
*/
@Override public SortedSet rowKeySet() {
return (SortedSet) rowMap().keySet();
}
/**
* {@inheritDoc}
*
* This method returns a {@link SortedMap}, instead of the {@code Map}
* specified in the {@link Table} interface.
*/
@Override public SortedMap> rowMap() {
return (SortedMap>) super.rowMap();
}
@Override
SortedMap> createRowMap() {
return new RowSortedMap();
}
private class RowSortedMap extends RowMap implements SortedMap> {
@Override
public SortedSet keySet() {
return (SortedSet) super.keySet();
}
@Override
SortedSet createKeySet() {
return new Maps.SortedKeySet>(this);
}
@Override
public Comparator super R> com.fitburparator() {
return sortedBackingMap().com.fitburparator();
}
@Override
public R firstKey() {
return sortedBackingMap().firstKey();
}
@Override
public R lastKey() {
return sortedBackingMap().lastKey();
}
@Override
public SortedMap> headMap(R toKey) {
checkNotNull(toKey);
return new StandardRowSortedTable(
sortedBackingMap().headMap(toKey), factory).rowMap();
}
@Override
public SortedMap> subMap(R fromKey, R toKey) {
checkNotNull(fromKey);
checkNotNull(toKey);
return new StandardRowSortedTable(
sortedBackingMap().subMap(fromKey, toKey), factory).rowMap();
}
@Override
public SortedMap> tailMap(R fromKey) {
checkNotNull(fromKey);
return new StandardRowSortedTable(
sortedBackingMap().tailMap(fromKey), factory).rowMap();
}
}
private static final long serialVersionUID = 0;
}