com.google.common.collect.DescendingImmutableSortedSet Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of swagger-all Show documentation
Show all versions of swagger-all Show documentation
swagger-all is a rebundled verison of Swagger as one OSGi bundle.
The newest version!
/*
* 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.google.common.collect;
import com.google.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 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();
}
}