Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (C) 2011 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 sorted multiset which forwards all its method calls to another sorted multiset. Subclasses should override one or more methods to modify the behavior of the backing multiset as desired per the decorator pattern.

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

The standard methods and any 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:
15.0
 
 @GwtCompatible(emulated = true)
 public abstract class ForwardingSortedMultiset<E> extends ForwardingMultiset<E>
     implements SortedMultiset<E> {
  
Constructor for use by subclasses.
 
   protected ForwardingSortedMultiset() {}
 
   @Override
   protected abstract SortedMultiset<E> delegate();
 
   @Override
   public NavigableSet<E> elementSet() {
     return (NavigableSet<E>) super.elementSet();
   }

  
 
   protected class StandardElementSet extends SortedMultisets.NavigableElementSet<E> {
    
Constructor for use by subclasses.
 
     public StandardElementSet() {
       super(ForwardingSortedMultiset.this);
     }
   }
 
   @Override
   public Comparator<? super E> comparator() {
     return delegate().comparator();
   }
 
   @Override
   public SortedMultiset<E> descendingMultiset() {
     return delegate().descendingMultiset();
   }

  
A skeleton implementation of a descending multiset view. Normally, DescendingMultiset.descendingMultiset() will not reflect any changes you make to the behavior of methods such as ForwardingCollection.add(java.lang.Object) or DescendingMultiset.pollFirstEntry(). This skeleton implementation correctly delegates each of its operations to the appropriate methods of this ForwardingSortedMultiset. In many cases, you may wish to override DescendingMultiset.descendingMultiset() to return an instance of a subclass of StandardDescendingMultiset.
 
   protected abstract class StandardDescendingMultiset
       extends DescendingMultiset<E> {
    
Constructor for use by subclasses.
 
     public StandardDescendingMultiset() {}
 
    @Override
      return ForwardingSortedMultiset.this;
    }
  }
  public Entry<E> firstEntry() {
    return delegate().firstEntry();
  }

  
A sensible definition of firstEntry() in terms of entrySet().iterator(). If you override ForwardingMultiset.entrySet(), you may wish to override firstEntry() to forward to this implementation.
  protected Entry<E> standardFirstEntry() {
    Iterator<Entry<E>> entryIterator = entrySet().iterator();
    if (!entryIterator.hasNext()) {
      return null;
    }
    Entry<E> entry = entryIterator.next();
    return Multisets.immutableEntry(entry.getElement(), entry.getCount());
  }
  public Entry<E> lastEntry() {
    return delegate().lastEntry();
  }

  
A sensible definition of lastEntry() in terms of descendingMultiset().entrySet().iterator(). If you override descendingMultiset() or ForwardingMultiset.entrySet(), you may wish to override firstEntry() to forward to this implementation.
  protected Entry<E> standardLastEntry() {
    Iterator<Entry<E>> entryIterator = descendingMultiset()
        .entrySet()
        .iterator();
    if (!entryIterator.hasNext()) {
      return null;
    }
    Entry<E> entry = entryIterator.next();
    return Multisets.immutableEntry(entry.getElement(), entry.getCount());
  }
  public Entry<E> pollFirstEntry() {
    return delegate().pollFirstEntry();
  }

  
A sensible definition of pollFirstEntry() in terms of entrySet().iterator(). If you override ForwardingMultiset.entrySet(), you may wish to override pollFirstEntry() to forward to this implementation.
  protected Entry<E> standardPollFirstEntry() {
    Iterator<Entry<E>> entryIterator = entrySet().iterator();
    if (!entryIterator.hasNext()) {
      return null;
    }
    Entry<E> entry = entryIterator.next();
    entry = Multisets.immutableEntry(entry.getElement(), entry.getCount());
    entryIterator.remove();
    return entry;
  }
  public Entry<E> pollLastEntry() {
    return delegate().pollLastEntry();
  }

  
A sensible definition of pollLastEntry() in terms of descendingMultiset().entrySet().iterator(). If you override descendingMultiset() or ForwardingMultiset.entrySet(), you may wish to override pollLastEntry() to forward to this implementation.
  protected Entry<E> standardPollLastEntry() {
    Iterator<Entry<E>> entryIterator = descendingMultiset()
        .entrySet()
        .iterator();
    if (!entryIterator.hasNext()) {
      return null;
    }
    Entry<E> entry = entryIterator.next();
    entry = Multisets.immutableEntry(entry.getElement(), entry.getCount());
    entryIterator.remove();
    return entry;
  }
  public SortedMultiset<E> headMultiset(E upperBoundBoundType boundType) {
    return delegate().headMultiset(upperBoundboundType);
  }
      E lowerBoundBoundType lowerBoundType, E upperBoundBoundType upperBoundType) {
    return delegate().subMultiset(lowerBoundlowerBoundTypeupperBoundupperBoundType);
  }

  
A sensible definition of subMultiset(java.lang.Object,com.google.common.collect.BoundType,java.lang.Object,com.google.common.collect.BoundType) in terms of headMultiset and tailMultiset. If you override either of these methods, you may wish to override subMultiset(java.lang.Object,com.google.common.collect.BoundType,java.lang.Object,com.google.common.collect.BoundType) to forward to this implementation.
      E lowerBoundBoundType lowerBoundType, E upperBoundBoundType upperBoundType) {
    return tailMultiset(lowerBoundlowerBoundType).headMultiset(upperBoundupperBoundType);
  }
  public SortedMultiset<E> tailMultiset(E lowerBoundBoundType boundType) {
    return delegate().tailMultiset(lowerBoundboundType);
  }
New to GrepCode? Check out our FAQ X