com.fitbur.guava.common.collect.DescendingImmutableSortedSet Maven / Gradle / Ivy
/*
* Copyright (C) 2012 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/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.guava.common.collect;
import com.fitbur.guava.common.annotations.GwtIncompatible;
import javax.annotation.Nullable;
/**
* Skeletal implementation of {@link ImmutableSortedSet#descendingSet()}.
*
* @author Louis Wasserman
*/
class DescendingImmutableSortedSet extends ImmutableSortedSet {
private final ImmutableSortedSet forward;
DescendingImmutableSortedSet(ImmutableSortedSet forward) {
super(Ordering.from(forward.comparator()).reverse());
this.forward = forward;
}
@Override
public boolean contains(@Nullable Object object) {
return forward.contains(object);
}
@Override
public int size() {
return forward.size();
}
@Override
public UnmodifiableIterator iterator() {
return forward.descendingIterator();
}
@Override
ImmutableSortedSet headSetImpl(E toElement, boolean inclusive) {
return forward.tailSet(toElement, inclusive).descendingSet();
}
@Override
ImmutableSortedSet subSetImpl(
E fromElement, boolean fromInclusive, E toElement, boolean toInclusive) {
return forward.subSet(toElement, toInclusive, fromElement, fromInclusive).descendingSet();
}
@Override
ImmutableSortedSet tailSetImpl(E fromElement, boolean inclusive) {
return forward.headSet(fromElement, inclusive).descendingSet();
}
@Override
@GwtIncompatible("NavigableSet")
public ImmutableSortedSet descendingSet() {
return forward;
}
@Override
@GwtIncompatible("NavigableSet")
public UnmodifiableIterator descendingIterator() {
return forward.iterator();
}
@Override
@GwtIncompatible("NavigableSet")
ImmutableSortedSet createDescendingSet() {
throw new AssertionError("should never be called");
}
@Override
public E lower(E element) {
return forward.higher(element);
}
@Override
public E floor(E element) {
return forward.ceiling(element);
}
@Override
public E ceiling(E element) {
return forward.floor(element);
}
@Override
public E higher(E element) {
return forward.lower(element);
}
@Override
int indexOf(@Nullable Object target) {
int index = forward.indexOf(target);
if (index == -1) {
return index;
} else {
return size() - 1 - index;
}
}
@Override
boolean isPartialView() {
return forward.isPartialView();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy