Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * 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;
 
 
 
A navigable set which forwards all its method calls to another navigable set. Subclasses should override one or more methods to modify the behavior of the backing set as desired per the decorator pattern.

Warning: The methods of ForwardingNavigableSet forward indiscriminately to the methods of the delegate. For example, overriding ForwardingCollection.add(java.lang.Object) alone will not change the behavior of ForwardingCollection.addAll(java.util.Collection), which can lead to unexpected behavior. In this case, you should override addAll as well, either providing your own implementation, or delegating to the provided standardAddAll method.

Each of the standard methods uses the set's comparator (or the natural ordering of the elements, if there is no comparator) to test element equality. As a result, if the comparator is not consistent with equals, some of the standard implementations may violate the Set contract.

The standard methods and the collection views they return are not guaranteed to be thread-safe, even when all of the methods that they depend on are thread-safe.

Author(s):
Louis Wasserman
Since:
12.0
 
 public abstract class ForwardingNavigableSet<E>
     extends ForwardingSortedSet<E> implements NavigableSet<E> {

  
Constructor for use by subclasses.
 
   protected ForwardingNavigableSet() {}
 
   @Override
   protected abstract NavigableSet<E> delegate();
 
   @Override
   public E lower(E e) {
     return delegate().lower(e);
   }

  
A sensible definition of lower(java.lang.Object) in terms of the descendingIterator method of headSet(java.lang.Object,boolean). If you override headSet(java.lang.Object,boolean), you may wish to override lower(java.lang.Object) to forward to this implementation.
 
   protected E standardLower(E e) {
     return Iterators.getNext(headSet(efalse).descendingIterator(), null);
   }
 
   @Override
   public E floor(E e) {
     return delegate().floor(e);
   }

  
A sensible definition of floor(java.lang.Object) in terms of the descendingIterator method of headSet(java.lang.Object,boolean). If you override headSet(java.lang.Object,boolean), you may wish to override floor(java.lang.Object) to forward to this implementation.
 
   protected E standardFloor(E e) {
     return Iterators.getNext(headSet(etrue).descendingIterator(), null);
   }
 
   @Override
   public E ceiling(E e) {
     return delegate().ceiling(e);
   }

  
A sensible definition of ceiling(java.lang.Object) in terms of the iterator method of tailSet(java.lang.Object,boolean). If you override tailSet(java.lang.Object,boolean), you may wish to override ceiling(java.lang.Object) to forward to this implementation.
 
   protected E standardCeiling(E e) {
     return Iterators.getNext(tailSet(etrue).iterator(), null);
   }
  public E higher(E e) {
    return delegate().higher(e);
  }

  
A sensible definition of higher(java.lang.Object) in terms of the iterator method of tailSet(java.lang.Object,boolean). If you override tailSet(java.lang.Object,boolean), you may wish to override higher(java.lang.Object) to forward to this implementation.
  protected E standardHigher(E e) {
    return Iterators.getNext(tailSet(efalse).iterator(), null);
  }
  public E pollFirst() {
    return delegate().pollFirst();
  }

  
A sensible definition of pollFirst() in terms of the iterator method. If you override ForwardingCollection.iterator() you may wish to override pollFirst() to forward to this implementation.
  protected E standardPollFirst() {
    return poll(iterator());
  }
  public E pollLast() {
    return delegate().pollLast();
  }

  
A sensible definition of pollLast() in terms of the descendingIterator method. If you override descendingIterator() you may wish to override pollLast() to forward to this implementation.
  protected E standardPollLast() {
    return poll(delegate().descendingIterator());
  }
  protected E standardFirst() {
    return iterator().next();
  }
  protected E standardLast() {
    return descendingIterator().next();
  }
  public NavigableSet<E> descendingSet() {
    return delegate().descendingSet();
  }

  
A sensible implementation of java.util.NavigableSet.descendingSet() in terms of the other methods of java.util.NavigableSet, notably including java.util.NavigableSet.descendingIterator().

In many cases, you may wish to override ForwardingNavigableSet.descendingSet() to forward to this implementation or a subclass thereof.

Since:
12.0
  @Beta
  protected class StandardDescendingSet extends Sets.DescendingSet<E> {
    
Constructor for use by subclasses.
    public StandardDescendingSet() {
      super(ForwardingNavigableSet.this);
    }
  }
  public Iterator<E> descendingIterator() {
    return delegate().descendingIterator();
  }
  public NavigableSet<E> subSet(
      E fromElement,
      boolean fromInclusive,
      E toElement,
      boolean toInclusive) {
    return delegate().subSet(fromElementfromInclusivetoElementtoInclusive);
  }

  
A sensible definition of subSet(java.lang.Object,boolean,java.lang.Object,boolean) in terms of the headSet and tailSet methods. In many cases, you may wish to override subSet(java.lang.Object,boolean,java.lang.Object,boolean) to forward to this implementation.
  protected NavigableSet<E> standardSubSet(
      E fromElement,
      boolean fromInclusive,
      E toElement,
      boolean toInclusive) {
    return tailSet(fromElementfromInclusive).headSet(toElementtoInclusive);
  }

  
  protected SortedSet<E> standardSubSet(E fromElement, E toElement) {
    return subSet(fromElementtruetoElementfalse);
  }
  public NavigableSet<E> headSet(E toElementboolean inclusive) {
    return delegate().headSet(toElementinclusive);
  }

  
A sensible definition of ForwardingSortedSet.headSet(java.lang.Object) in terms of the headSet(java.lang.Object,boolean) method. If you override headSet(java.lang.Object,boolean), you may wish to override ForwardingSortedSet.headSet(java.lang.Object) to forward to this implementation.
  protected SortedSet<E> standardHeadSet(E toElement) {
    return headSet(toElementfalse);
  }
  public NavigableSet<E> tailSet(E fromElementboolean inclusive) {
    return delegate().tailSet(fromElementinclusive);
  }

  
A sensible definition of ForwardingSortedSet.tailSet(java.lang.Object) in terms of the tailSet(java.lang.Object,boolean) method. If you override tailSet(java.lang.Object,boolean), you may wish to override ForwardingSortedSet.tailSet(java.lang.Object) to forward to this implementation.
  protected SortedSet<E> standardTailSet(E fromElement) {
    return tailSet(fromElementtrue);
  }
  private E poll(Iterator<E> iterator) {
    if (iterator.hasNext()) {
      E result = iterator.next();
      iterator.remove();
      return result;
    }
    return null;
  }
New to GrepCode? Check out our FAQ X