Merging from -r468106:814127 of collections_jdk5_branch - namely where this code was generified; mostly in r738956.

Also see the following revisions:

    ------------------------------------------------------------------------
    r555925 | skestle | 2007-07-13 03:39:24 -0700 (Fri, 13 Jul 2007) | 2 lines
    
    Added Edwin Tellman's patch for COLLECTIONS-243.  
    It all seems pretty reasonable, and it should all be checked again as the project is worked through
    ------------------------------------------------------------------------
    r471202 | scolebourne | 2006-11-04 06:21:44 -0800 (Sat, 04 Nov 2006) | 1 line
    
    Remove getCollection() - use covariant decorated()
    ------------------------------------------------------------------------


git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@815099 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2009-09-15 05:56:42 +00:00
parent 60425a423f
commit c33b575cfc
1 changed files with 22 additions and 21 deletions

View File

@ -40,7 +40,7 @@ import org.apache.commons.collections.Predicate;
* @author Stephen Colebourne
* @author Paul Jack
*/
public class PredicatedSortedSet extends PredicatedSet implements SortedSet {
public class PredicatedSortedSet<E> extends PredicatedSet<E> implements SortedSet<E> {
/** Serialization version */
private static final long serialVersionUID = -9110948148132275052L;
@ -53,11 +53,12 @@ public class PredicatedSortedSet extends PredicatedSet implements SortedSet {
*
* @param set the set to decorate, must not be null
* @param predicate the predicate to use for validation, must not be null
* @return a new predicated sorted set.
* @throws IllegalArgumentException if set or predicate is null
* @throws IllegalArgumentException if the set contains invalid elements
*/
public static SortedSet decorate(SortedSet set, Predicate predicate) {
return new PredicatedSortedSet(set, predicate);
public static <T> SortedSet<T> decorate(SortedSet<T> set, Predicate<? super T> predicate) {
return new PredicatedSortedSet<T>(set, predicate);
}
//-----------------------------------------------------------------------
@ -72,7 +73,7 @@ public class PredicatedSortedSet extends PredicatedSet implements SortedSet {
* @throws IllegalArgumentException if set or predicate is null
* @throws IllegalArgumentException if the set contains invalid elements
*/
protected PredicatedSortedSet(SortedSet set, Predicate predicate) {
protected PredicatedSortedSet(SortedSet<E> set, Predicate<? super E> predicate) {
super(set, predicate);
}
@ -81,36 +82,36 @@ public class PredicatedSortedSet extends PredicatedSet implements SortedSet {
*
* @return the decorated sorted set
*/
private SortedSet getSortedSet() {
return (SortedSet) getCollection();
protected SortedSet<E> decorated() {
return (SortedSet<E>) super.decorated();
}
//-----------------------------------------------------------------------
public SortedSet subSet(Object fromElement, Object toElement) {
SortedSet sub = getSortedSet().subSet(fromElement, toElement);
return new PredicatedSortedSet(sub, predicate);
public Comparator<? super E> comparator() {
return decorated().comparator();
}
public SortedSet headSet(Object toElement) {
SortedSet sub = getSortedSet().headSet(toElement);
return new PredicatedSortedSet(sub, predicate);
public E first() {
return decorated().first();
}
public SortedSet tailSet(Object fromElement) {
SortedSet sub = getSortedSet().tailSet(fromElement);
return new PredicatedSortedSet(sub, predicate);
public E last() {
return decorated().last();
}
public Object first() {
return getSortedSet().first();
public SortedSet<E> subSet(E fromElement, E toElement) {
SortedSet<E> sub = decorated().subSet(fromElement, toElement);
return new PredicatedSortedSet<E>(sub, predicate);
}
public Object last() {
return getSortedSet().last();
public SortedSet<E> headSet(E toElement) {
SortedSet<E> sub = decorated().headSet(toElement);
return new PredicatedSortedSet<E>(sub, predicate);
}
public Comparator comparator() {
return getSortedSet().comparator();
public SortedSet<E> tailSet(E fromElement) {
SortedSet<E> sub = decorated().tailSet(fromElement);
return new PredicatedSortedSet<E>(sub, predicate);
}
}