Add Set and SortedSet collection decorators
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@131044 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ddfce4943f
commit
655ef653bc
|
@ -0,0 +1,93 @@
|
||||||
|
/*
|
||||||
|
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/decorators/Attic/AbstractSetDecorator.java,v 1.1 2003/05/07 11:19:46 scolebourne Exp $
|
||||||
|
* ====================================================================
|
||||||
|
*
|
||||||
|
* The Apache Software License, Version 1.1
|
||||||
|
*
|
||||||
|
* Copyright (c) 2003 The Apache Software Foundation. All rights
|
||||||
|
* reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
* 3. The end-user documentation included with the redistribution, if
|
||||||
|
* any, must include the following acknowledgment:
|
||||||
|
* "This product includes software developed by the
|
||||||
|
* Apache Software Foundation (http://www.apache.org/)."
|
||||||
|
* Alternately, this acknowledgment may appear in the software itself,
|
||||||
|
* if and wherever such third-party acknowledgments normally appear.
|
||||||
|
*
|
||||||
|
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
|
||||||
|
* Foundation" must not be used to endorse or promote products derived
|
||||||
|
* from this software without prior written permission. For written
|
||||||
|
* permission, please contact apache@apache.org.
|
||||||
|
*
|
||||||
|
* 5. Products derived from this software may not be called "Apache"
|
||||||
|
* nor may "Apache" appear in their names without prior written
|
||||||
|
* permission of the Apache Software Foundation.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
||||||
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||||
|
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
* ====================================================================
|
||||||
|
*
|
||||||
|
* This software consists of voluntary contributions made by many
|
||||||
|
* individuals on behalf of the Apache Software Foundation. For more
|
||||||
|
* information on the Apache Software Foundation, please see
|
||||||
|
* <http://www.apache.org/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.apache.commons.collections.decorators;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <code>AbstractSetDecorator</code> decorates another <code>Set</code>.
|
||||||
|
* <p>
|
||||||
|
* Methods are forwarded directly to the decorated set.
|
||||||
|
*
|
||||||
|
* @since Commons Collections 3.0
|
||||||
|
* @version $Revision: 1.1 $ $Date: 2003/05/07 11:19:46 $
|
||||||
|
*
|
||||||
|
* @author Stephen Colebourne
|
||||||
|
*/
|
||||||
|
public abstract class AbstractSetDecorator extends AbstractCollectionDecorator implements Set {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor that wraps (not copies).
|
||||||
|
*
|
||||||
|
* @param set the set to decorate, must not be null
|
||||||
|
* @throws IllegalArgumentException if set is null
|
||||||
|
*/
|
||||||
|
protected AbstractSetDecorator(Set set) {
|
||||||
|
super(set);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the set being decorated.
|
||||||
|
*
|
||||||
|
* @return the decorated set
|
||||||
|
*/
|
||||||
|
protected Set getSet() {
|
||||||
|
return (Set) getCollection();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,120 @@
|
||||||
|
/*
|
||||||
|
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/decorators/Attic/AbstractSortedSetDecorator.java,v 1.1 2003/05/07 11:19:46 scolebourne Exp $
|
||||||
|
* ====================================================================
|
||||||
|
*
|
||||||
|
* The Apache Software License, Version 1.1
|
||||||
|
*
|
||||||
|
* Copyright (c) 2003 The Apache Software Foundation. All rights
|
||||||
|
* reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
* 3. The end-user documentation included with the redistribution, if
|
||||||
|
* any, must include the following acknowledgment:
|
||||||
|
* "This product includes software developed by the
|
||||||
|
* Apache Software Foundation (http://www.apache.org/)."
|
||||||
|
* Alternately, this acknowledgment may appear in the software itself,
|
||||||
|
* if and wherever such third-party acknowledgments normally appear.
|
||||||
|
*
|
||||||
|
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
|
||||||
|
* Foundation" must not be used to endorse or promote products derived
|
||||||
|
* from this software without prior written permission. For written
|
||||||
|
* permission, please contact apache@apache.org.
|
||||||
|
*
|
||||||
|
* 5. Products derived from this software may not be called "Apache"
|
||||||
|
* nor may "Apache" appear in their names without prior written
|
||||||
|
* permission of the Apache Software Foundation.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
||||||
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||||
|
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
* ====================================================================
|
||||||
|
*
|
||||||
|
* This software consists of voluntary contributions made by many
|
||||||
|
* individuals on behalf of the Apache Software Foundation. For more
|
||||||
|
* information on the Apache Software Foundation, please see
|
||||||
|
* <http://www.apache.org/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.apache.commons.collections.decorators;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.SortedSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <code>AbstractSortedSetDecorator</code> decorates another <code>SortedSet</code>.
|
||||||
|
* <p>
|
||||||
|
* Methods are forwarded directly to the decorated set.
|
||||||
|
*
|
||||||
|
* @since Commons Collections 3.0
|
||||||
|
* @version $Revision: 1.1 $ $Date: 2003/05/07 11:19:46 $
|
||||||
|
*
|
||||||
|
* @author Stephen Colebourne
|
||||||
|
*/
|
||||||
|
public abstract class AbstractSortedSetDecorator extends AbstractSetDecorator implements SortedSet {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor that wraps (not copies).
|
||||||
|
*
|
||||||
|
* @param set the set to decorate, must not be null
|
||||||
|
* @throws IllegalArgumentException if set is null
|
||||||
|
*/
|
||||||
|
protected AbstractSortedSetDecorator(Set set) {
|
||||||
|
super(set);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the sorted set being decorated.
|
||||||
|
*
|
||||||
|
* @return the decorated set
|
||||||
|
*/
|
||||||
|
protected SortedSet getSortedSet() {
|
||||||
|
return (SortedSet) getCollection();
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------
|
||||||
|
public SortedSet subSet(Object fromElement, Object toElement) {
|
||||||
|
return getSortedSet().subSet(fromElement, toElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SortedSet headSet(Object toElement) {
|
||||||
|
return getSortedSet().headSet(toElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SortedSet tailSet(Object fromElement) {
|
||||||
|
return getSortedSet().tailSet(fromElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object first() {
|
||||||
|
return getSortedSet().first();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object last() {
|
||||||
|
return getSortedSet().last();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Comparator comparator() {
|
||||||
|
return getSortedSet().comparator();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,118 @@
|
||||||
|
/*
|
||||||
|
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/decorators/Attic/PredicatedSet.java,v 1.1 2003/05/07 11:19:46 scolebourne Exp $
|
||||||
|
* ====================================================================
|
||||||
|
*
|
||||||
|
* The Apache Software License, Version 1.1
|
||||||
|
*
|
||||||
|
* Copyright (c) 2003 The Apache Software Foundation. All rights
|
||||||
|
* reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
* 3. The end-user documentation included with the redistribution, if
|
||||||
|
* any, must include the following acknowledgment:
|
||||||
|
* "This product includes software developed by the
|
||||||
|
* Apache Software Foundation (http://www.apache.org/)."
|
||||||
|
* Alternately, this acknowledgment may appear in the software itself,
|
||||||
|
* if and wherever such third-party acknowledgments normally appear.
|
||||||
|
*
|
||||||
|
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
|
||||||
|
* Foundation" must not be used to endorse or promote products derived
|
||||||
|
* from this software without prior written permission. For written
|
||||||
|
* permission, please contact apache@apache.org.
|
||||||
|
*
|
||||||
|
* 5. Products derived from this software may not be called "Apache"
|
||||||
|
* nor may "Apache" appear in their names without prior written
|
||||||
|
* permission of the Apache Software Foundation.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
||||||
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||||
|
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
* ====================================================================
|
||||||
|
*
|
||||||
|
* This software consists of voluntary contributions made by many
|
||||||
|
* individuals on behalf of the Apache Software Foundation. For more
|
||||||
|
* information on the Apache Software Foundation, please see
|
||||||
|
* <http://www.apache.org/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.apache.commons.collections.decorators;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.apache.commons.collections.Predicate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <code>PredicatedSet</code> decorates another <code>Set</code>
|
||||||
|
* to validate additions match a specified predicate.
|
||||||
|
* <p>
|
||||||
|
* If an object cannot be addded to the set, an IllegalArgumentException
|
||||||
|
* is thrown.
|
||||||
|
*
|
||||||
|
* @since Commons Collections 3.0
|
||||||
|
* @version $Revision: 1.1 $ $Date: 2003/05/07 11:19:46 $
|
||||||
|
*
|
||||||
|
* @author Stephen Colebourne
|
||||||
|
* @author Paul Jack
|
||||||
|
*/
|
||||||
|
public class PredicatedSet extends PredicatedCollection implements Set {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory method to create a predicated (validating) set.
|
||||||
|
* <p>
|
||||||
|
* If there are any elements already in the set being decorated, they
|
||||||
|
* are validated.
|
||||||
|
*
|
||||||
|
* @param set the set to decorate, must not be null
|
||||||
|
* @param predicate the predicate to use for validation, must not be null
|
||||||
|
* @throws IllegalArgumentException if set or predicate is null
|
||||||
|
* @throws IllegalArgumentException if the set contains invalid elements
|
||||||
|
*/
|
||||||
|
public static Set decorate(Set set, Predicate predicate) {
|
||||||
|
return new PredicatedSet(set, predicate);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor that wraps (not copies).
|
||||||
|
* <p>
|
||||||
|
* If there are any elements already in the set being decorated, they
|
||||||
|
* are validated.
|
||||||
|
*
|
||||||
|
* @param set the set to decorate, must not be null
|
||||||
|
* @param predicate the predicate to use for validation, must not be null
|
||||||
|
* @throws IllegalArgumentException if set or predicate is null
|
||||||
|
* @throws IllegalArgumentException if the set contains invalid elements
|
||||||
|
*/
|
||||||
|
protected PredicatedSet(Set set, Predicate predicate) {
|
||||||
|
super(set, predicate);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the set being decorated.
|
||||||
|
*
|
||||||
|
* @return the decorated set
|
||||||
|
*/
|
||||||
|
protected Set getSet() {
|
||||||
|
return (Set) getCollection();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,147 @@
|
||||||
|
/*
|
||||||
|
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/decorators/Attic/PredicatedSortedSet.java,v 1.1 2003/05/07 11:19:46 scolebourne Exp $
|
||||||
|
* ====================================================================
|
||||||
|
*
|
||||||
|
* The Apache Software License, Version 1.1
|
||||||
|
*
|
||||||
|
* Copyright (c) 2003 The Apache Software Foundation. All rights
|
||||||
|
* reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
* 3. The end-user documentation included with the redistribution, if
|
||||||
|
* any, must include the following acknowledgment:
|
||||||
|
* "This product includes software developed by the
|
||||||
|
* Apache Software Foundation (http://www.apache.org/)."
|
||||||
|
* Alternately, this acknowledgment may appear in the software itself,
|
||||||
|
* if and wherever such third-party acknowledgments normally appear.
|
||||||
|
*
|
||||||
|
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
|
||||||
|
* Foundation" must not be used to endorse or promote products derived
|
||||||
|
* from this software without prior written permission. For written
|
||||||
|
* permission, please contact apache@apache.org.
|
||||||
|
*
|
||||||
|
* 5. Products derived from this software may not be called "Apache"
|
||||||
|
* nor may "Apache" appear in their names without prior written
|
||||||
|
* permission of the Apache Software Foundation.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
||||||
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||||
|
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
* ====================================================================
|
||||||
|
*
|
||||||
|
* This software consists of voluntary contributions made by many
|
||||||
|
* individuals on behalf of the Apache Software Foundation. For more
|
||||||
|
* information on the Apache Software Foundation, please see
|
||||||
|
* <http://www.apache.org/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.apache.commons.collections.decorators;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.SortedSet;
|
||||||
|
|
||||||
|
import org.apache.commons.collections.Predicate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <code>PredicatedSortedSet</code> decorates another <code>SortedSet</code>
|
||||||
|
* to validate additions match a specified predicate.
|
||||||
|
* <p>
|
||||||
|
* If an object cannot be addded to the set, an IllegalArgumentException
|
||||||
|
* is thrown.
|
||||||
|
*
|
||||||
|
* @since Commons Collections 3.0
|
||||||
|
* @version $Revision: 1.1 $ $Date: 2003/05/07 11:19:46 $
|
||||||
|
*
|
||||||
|
* @author Stephen Colebourne
|
||||||
|
* @author Paul Jack
|
||||||
|
*/
|
||||||
|
public class PredicatedSortedSet extends PredicatedSet implements SortedSet {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory method to create a predicated (validating) sorted set.
|
||||||
|
* <p>
|
||||||
|
* If there are any elements already in the set being decorated, they
|
||||||
|
* are validated.
|
||||||
|
*
|
||||||
|
* @param set the set to decorate, must not be null
|
||||||
|
* @param predicate the predicate to use for validation, must not be null
|
||||||
|
* @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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor that wraps (not copies).
|
||||||
|
* <p>
|
||||||
|
* If there are any elements already in the set being decorated, they
|
||||||
|
* are validated.
|
||||||
|
*
|
||||||
|
* @param set the set to decorate, must not be null
|
||||||
|
* @param predicate the predicate to use for validation, must not be null
|
||||||
|
* @throws IllegalArgumentException if set or predicate is null
|
||||||
|
* @throws IllegalArgumentException if the set contains invalid elements
|
||||||
|
*/
|
||||||
|
protected PredicatedSortedSet(SortedSet set, Predicate predicate) {
|
||||||
|
super(set, predicate);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the sorted set being decorated.
|
||||||
|
*
|
||||||
|
* @return the decorated sorted set
|
||||||
|
*/
|
||||||
|
private SortedSet getSortedSet() {
|
||||||
|
return (SortedSet) getCollection();
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------
|
||||||
|
public SortedSet subSet(Object fromElement, Object toElement) {
|
||||||
|
SortedSet sub = getSortedSet().subSet(fromElement, toElement);
|
||||||
|
return new PredicatedSortedSet(sub, predicate);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SortedSet headSet(Object toElement) {
|
||||||
|
SortedSet sub = getSortedSet().headSet(toElement);
|
||||||
|
return new PredicatedSortedSet(sub, predicate);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SortedSet tailSet(Object fromElement) {
|
||||||
|
SortedSet sub = getSortedSet().tailSet(fromElement);
|
||||||
|
return new PredicatedSortedSet(sub, predicate);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object first() {
|
||||||
|
return getSortedSet().first();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object last() {
|
||||||
|
return getSortedSet().last();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Comparator comparator() {
|
||||||
|
return getSortedSet().comparator();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,114 @@
|
||||||
|
/*
|
||||||
|
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/decorators/Attic/SynchronizedSet.java,v 1.1 2003/05/07 11:19:46 scolebourne Exp $
|
||||||
|
* ====================================================================
|
||||||
|
*
|
||||||
|
* The Apache Software License, Version 1.1
|
||||||
|
*
|
||||||
|
* Copyright (c) 2003 The Apache Software Foundation. All rights
|
||||||
|
* reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
* 3. The end-user documentation included with the redistribution, if
|
||||||
|
* any, must include the following acknowledgment:
|
||||||
|
* "This product includes software developed by the
|
||||||
|
* Apache Software Foundation (http://www.apache.org/)."
|
||||||
|
* Alternately, this acknowledgment may appear in the software itself,
|
||||||
|
* if and wherever such third-party acknowledgments normally appear.
|
||||||
|
*
|
||||||
|
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
|
||||||
|
* Foundation" must not be used to endorse or promote products derived
|
||||||
|
* from this software without prior written permission. For written
|
||||||
|
* permission, please contact apache@apache.org.
|
||||||
|
*
|
||||||
|
* 5. Products derived from this software may not be called "Apache"
|
||||||
|
* nor may "Apache" appear in their names without prior written
|
||||||
|
* permission of the Apache Software Foundation.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
||||||
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||||
|
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
* ====================================================================
|
||||||
|
*
|
||||||
|
* This software consists of voluntary contributions made by many
|
||||||
|
* individuals on behalf of the Apache Software Foundation. For more
|
||||||
|
* information on the Apache Software Foundation, please see
|
||||||
|
* <http://www.apache.org/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.apache.commons.collections.decorators;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <code>SynchronizedSet</code> decorates another <code>Set</code>.
|
||||||
|
* <p>
|
||||||
|
* Methods are synchronized, then forwarded to the decorated set.
|
||||||
|
*
|
||||||
|
* @since Commons Collections 3.0
|
||||||
|
* @version $Revision: 1.1 $ $Date: 2003/05/07 11:19:46 $
|
||||||
|
*
|
||||||
|
* @author Stephen Colebourne
|
||||||
|
*/
|
||||||
|
public class SynchronizedSet extends SynchronizedCollection implements Set {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory method to create a synchronized set.
|
||||||
|
*
|
||||||
|
* @param set the set to decorate, must not be null
|
||||||
|
* @throws IllegalArgumentException if set is null
|
||||||
|
*/
|
||||||
|
public static Set decorate(Set set) {
|
||||||
|
return new SynchronizedSet(set);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor that wraps (not copies).
|
||||||
|
*
|
||||||
|
* @param set the set to decorate, must not be null
|
||||||
|
* @throws IllegalArgumentException if set is null
|
||||||
|
*/
|
||||||
|
protected SynchronizedSet(Set set) {
|
||||||
|
super(set);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor that wraps (not copies).
|
||||||
|
*
|
||||||
|
* @param set the set to decorate, must not be null
|
||||||
|
* @param lock the lock object to use, must not be null
|
||||||
|
* @throws IllegalArgumentException if set is null
|
||||||
|
*/
|
||||||
|
protected SynchronizedSet(Set set, Object lock) {
|
||||||
|
super(set, lock);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the decorated set.
|
||||||
|
*
|
||||||
|
* @return the decorated set
|
||||||
|
*/
|
||||||
|
protected Set getSet() {
|
||||||
|
return (Set) collection;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,161 @@
|
||||||
|
/*
|
||||||
|
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/decorators/Attic/SynchronizedSortedSet.java,v 1.1 2003/05/07 11:19:46 scolebourne Exp $
|
||||||
|
* ====================================================================
|
||||||
|
*
|
||||||
|
* The Apache Software License, Version 1.1
|
||||||
|
*
|
||||||
|
* Copyright (c) 2003 The Apache Software Foundation. All rights
|
||||||
|
* reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
* 3. The end-user documentation included with the redistribution, if
|
||||||
|
* any, must include the following acknowledgment:
|
||||||
|
* "This product includes software developed by the
|
||||||
|
* Apache Software Foundation (http://www.apache.org/)."
|
||||||
|
* Alternately, this acknowledgment may appear in the software itself,
|
||||||
|
* if and wherever such third-party acknowledgments normally appear.
|
||||||
|
*
|
||||||
|
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
|
||||||
|
* Foundation" must not be used to endorse or promote products derived
|
||||||
|
* from this software without prior written permission. For written
|
||||||
|
* permission, please contact apache@apache.org.
|
||||||
|
*
|
||||||
|
* 5. Products derived from this software may not be called "Apache"
|
||||||
|
* nor may "Apache" appear in their names without prior written
|
||||||
|
* permission of the Apache Software Foundation.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
||||||
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||||
|
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
* ====================================================================
|
||||||
|
*
|
||||||
|
* This software consists of voluntary contributions made by many
|
||||||
|
* individuals on behalf of the Apache Software Foundation. For more
|
||||||
|
* information on the Apache Software Foundation, please see
|
||||||
|
* <http://www.apache.org/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.apache.commons.collections.decorators;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.SortedSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <code>SynchronizedSortedSet</code> decorates another <code>SortedSet</code>.
|
||||||
|
* <p>
|
||||||
|
* Methods are synchronized, then forwarded to the decorated set.
|
||||||
|
*
|
||||||
|
* @since Commons Collections 3.0
|
||||||
|
* @version $Revision: 1.1 $ $Date: 2003/05/07 11:19:46 $
|
||||||
|
*
|
||||||
|
* @author Stephen Colebourne
|
||||||
|
*/
|
||||||
|
public class SynchronizedSortedSet extends SynchronizedCollection implements SortedSet {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory method to create a synchronized set.
|
||||||
|
*
|
||||||
|
* @param set the set to decorate, must not be null
|
||||||
|
* @throws IllegalArgumentException if set is null
|
||||||
|
*/
|
||||||
|
public static SortedSet decorate(SortedSet set) {
|
||||||
|
return new SynchronizedSortedSet(set);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor that wraps (not copies).
|
||||||
|
*
|
||||||
|
* @param set the set to decorate, must not be null
|
||||||
|
* @throws IllegalArgumentException if set is null
|
||||||
|
*/
|
||||||
|
protected SynchronizedSortedSet(SortedSet set) {
|
||||||
|
super(set);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor that wraps (not copies).
|
||||||
|
*
|
||||||
|
* @param set the set to decorate, must not be null
|
||||||
|
* @param lock the lock object to use, must not be null
|
||||||
|
* @throws IllegalArgumentException if set is null
|
||||||
|
*/
|
||||||
|
protected SynchronizedSortedSet(SortedSet set, Object lock) {
|
||||||
|
super(set, lock);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the decorated set.
|
||||||
|
*
|
||||||
|
* @return the decorated set
|
||||||
|
*/
|
||||||
|
protected SortedSet getSortedSet() {
|
||||||
|
return (SortedSet) collection;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------
|
||||||
|
public SortedSet subSet(Object fromElement, Object toElement) {
|
||||||
|
synchronized (lock) {
|
||||||
|
SortedSet set = getSortedSet().subSet(fromElement, toElement);
|
||||||
|
// the lock is passed into the constructor here to ensure that the
|
||||||
|
// subset is synchronized on the same lock as the parent
|
||||||
|
return new SynchronizedSortedSet(set, lock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public SortedSet headSet(Object toElement) {
|
||||||
|
synchronized (lock) {
|
||||||
|
SortedSet set = getSortedSet().headSet(toElement);
|
||||||
|
// the lock is passed into the constructor here to ensure that the
|
||||||
|
// headset is synchronized on the same lock as the parent
|
||||||
|
return new SynchronizedSortedSet(set, lock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public SortedSet tailSet(Object fromElement) {
|
||||||
|
synchronized (lock) {
|
||||||
|
SortedSet set = getSortedSet().tailSet(fromElement);
|
||||||
|
// the lock is passed into the constructor here to ensure that the
|
||||||
|
// tailset is synchronized on the same lock as the parent
|
||||||
|
return new SynchronizedSortedSet(set, lock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object first() {
|
||||||
|
synchronized (lock) {
|
||||||
|
return getSortedSet().first();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object last() {
|
||||||
|
synchronized (lock) {
|
||||||
|
return getSortedSet().last();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Comparator comparator() {
|
||||||
|
synchronized (lock) {
|
||||||
|
return getSortedSet().comparator();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,108 @@
|
||||||
|
/*
|
||||||
|
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/decorators/Attic/TypedSet.java,v 1.1 2003/05/07 11:19:46 scolebourne Exp $
|
||||||
|
* ====================================================================
|
||||||
|
*
|
||||||
|
* The Apache Software License, Version 1.1
|
||||||
|
*
|
||||||
|
* Copyright (c) 2003 The Apache Software Foundation. All rights
|
||||||
|
* reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
* 3. The end-user documentation included with the redistribution, if
|
||||||
|
* any, must include the following acknowledgment:
|
||||||
|
* "This product includes software developed by the
|
||||||
|
* Apache Software Foundation (http://www.apache.org/)."
|
||||||
|
* Alternately, this acknowledgment may appear in the software itself,
|
||||||
|
* if and wherever such third-party acknowledgments normally appear.
|
||||||
|
*
|
||||||
|
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
|
||||||
|
* Foundation" must not be used to endorse or promote products derived
|
||||||
|
* from this software without prior written permission. For written
|
||||||
|
* permission, please contact apache@apache.org.
|
||||||
|
*
|
||||||
|
* 5. Products derived from this software may not be called "Apache"
|
||||||
|
* nor may "Apache" appear in their names without prior written
|
||||||
|
* permission of the Apache Software Foundation.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
||||||
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||||
|
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
* ====================================================================
|
||||||
|
*
|
||||||
|
* This software consists of voluntary contributions made by many
|
||||||
|
* individuals on behalf of the Apache Software Foundation. For more
|
||||||
|
* information on the Apache Software Foundation, please see
|
||||||
|
* <http://www.apache.org/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.apache.commons.collections.decorators;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <code>TypedSet</code> decorates another <code>Set</code>
|
||||||
|
* to validate that elements added are of a specific type.
|
||||||
|
* <p>
|
||||||
|
* The validation of additions is performed via an instanceof test against
|
||||||
|
* a specified <code>Class</code>. If an object cannot be addded to the
|
||||||
|
* collection, an IllegalArgumentException is thrown.
|
||||||
|
*
|
||||||
|
* @since Commons Collections 3.0
|
||||||
|
* @version $Revision: 1.1 $ $Date: 2003/05/07 11:19:46 $
|
||||||
|
*
|
||||||
|
* @author Stephen Colebourne
|
||||||
|
* @author Matthew Hawthorne
|
||||||
|
*/
|
||||||
|
public class TypedSet extends PredicatedSet {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory method to create a typed set.
|
||||||
|
* <p>
|
||||||
|
* If there are any elements already in the set being decorated, they
|
||||||
|
* are validated.
|
||||||
|
*
|
||||||
|
* @param set the set to decorate, must not be null
|
||||||
|
* @param type the type to allow into the collection, must not be null
|
||||||
|
* @throws IllegalArgumentException if set or type is null
|
||||||
|
* @throws IllegalArgumentException if the set contains invalid elements
|
||||||
|
*/
|
||||||
|
public static Set decorate(Set set, Class type) {
|
||||||
|
return new TypedSet(set, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor that wraps (not copies).
|
||||||
|
* <p>
|
||||||
|
* If there are any elements already in the collection being decorated, they
|
||||||
|
* are validated.
|
||||||
|
*
|
||||||
|
* @param set the set to decorate, must not be null
|
||||||
|
* @param type the type to allow into the collection, must not be null
|
||||||
|
* @throws IllegalArgumentException if set or type is null
|
||||||
|
* @throws IllegalArgumentException if the set contains invalid elements
|
||||||
|
*/
|
||||||
|
protected TypedSet(Set set, Class type) {
|
||||||
|
super(set, TypedCollection.getPredicate(type));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,108 @@
|
||||||
|
/*
|
||||||
|
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/decorators/Attic/TypedSortedSet.java,v 1.1 2003/05/07 11:19:46 scolebourne Exp $
|
||||||
|
* ====================================================================
|
||||||
|
*
|
||||||
|
* The Apache Software License, Version 1.1
|
||||||
|
*
|
||||||
|
* Copyright (c) 2003 The Apache Software Foundation. All rights
|
||||||
|
* reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
* 3. The end-user documentation included with the redistribution, if
|
||||||
|
* any, must include the following acknowledgment:
|
||||||
|
* "This product includes software developed by the
|
||||||
|
* Apache Software Foundation (http://www.apache.org/)."
|
||||||
|
* Alternately, this acknowledgment may appear in the software itself,
|
||||||
|
* if and wherever such third-party acknowledgments normally appear.
|
||||||
|
*
|
||||||
|
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
|
||||||
|
* Foundation" must not be used to endorse or promote products derived
|
||||||
|
* from this software without prior written permission. For written
|
||||||
|
* permission, please contact apache@apache.org.
|
||||||
|
*
|
||||||
|
* 5. Products derived from this software may not be called "Apache"
|
||||||
|
* nor may "Apache" appear in their names without prior written
|
||||||
|
* permission of the Apache Software Foundation.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
||||||
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||||
|
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
* ====================================================================
|
||||||
|
*
|
||||||
|
* This software consists of voluntary contributions made by many
|
||||||
|
* individuals on behalf of the Apache Software Foundation. For more
|
||||||
|
* information on the Apache Software Foundation, please see
|
||||||
|
* <http://www.apache.org/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.apache.commons.collections.decorators;
|
||||||
|
|
||||||
|
import java.util.SortedSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <code>TypedSortedSet</code> decorates another <code>Set</code>
|
||||||
|
* to validate that elements added are of a specific type.
|
||||||
|
* <p>
|
||||||
|
* The validation of additions is performed via an instanceof test against
|
||||||
|
* a specified <code>Class</code>. If an object cannot be addded to the
|
||||||
|
* collection, an IllegalArgumentException is thrown.
|
||||||
|
*
|
||||||
|
* @since Commons Collections 3.0
|
||||||
|
* @version $Revision: 1.1 $ $Date: 2003/05/07 11:19:46 $
|
||||||
|
*
|
||||||
|
* @author Stephen Colebourne
|
||||||
|
* @author Matthew Hawthorne
|
||||||
|
*/
|
||||||
|
public class TypedSortedSet extends PredicatedSortedSet {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory method to create a typed sorted set.
|
||||||
|
* <p>
|
||||||
|
* If there are any elements already in the set being decorated, they
|
||||||
|
* are validated.
|
||||||
|
*
|
||||||
|
* @param set the set to decorate, must not be null
|
||||||
|
* @param type the type to allow into the collection, must not be null
|
||||||
|
* @throws IllegalArgumentException if set or type is null
|
||||||
|
* @throws IllegalArgumentException if the set contains invalid elements
|
||||||
|
*/
|
||||||
|
public static SortedSet decorate(SortedSet set, Class type) {
|
||||||
|
return new TypedSortedSet(set, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor that wraps (not copies).
|
||||||
|
* <p>
|
||||||
|
* If there are any elements already in the collection being decorated, they
|
||||||
|
* are validated.
|
||||||
|
*
|
||||||
|
* @param set the set to decorate, must not be null
|
||||||
|
* @param type the type to allow into the collection, must not be null
|
||||||
|
* @throws IllegalArgumentException if set or type is null
|
||||||
|
* @throws IllegalArgumentException if the set contains invalid elements
|
||||||
|
*/
|
||||||
|
protected TypedSortedSet(SortedSet set, Class type) {
|
||||||
|
super(set, TypedCollection.getPredicate(type));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,102 @@
|
||||||
|
/*
|
||||||
|
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/decorators/Attic/UnmodifiableSet.java,v 1.1 2003/05/07 11:19:46 scolebourne Exp $
|
||||||
|
* ====================================================================
|
||||||
|
*
|
||||||
|
* The Apache Software License, Version 1.1
|
||||||
|
*
|
||||||
|
* Copyright (c) 2003 The Apache Software Foundation. All rights
|
||||||
|
* reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
* 3. The end-user documentation included with the redistribution, if
|
||||||
|
* any, must include the following acknowledgment:
|
||||||
|
* "This product includes software developed by the
|
||||||
|
* Apache Software Foundation (http://www.apache.org/)."
|
||||||
|
* Alternately, this acknowledgment may appear in the software itself,
|
||||||
|
* if and wherever such third-party acknowledgments normally appear.
|
||||||
|
*
|
||||||
|
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
|
||||||
|
* Foundation" must not be used to endorse or promote products derived
|
||||||
|
* from this software without prior written permission. For written
|
||||||
|
* permission, please contact apache@apache.org.
|
||||||
|
*
|
||||||
|
* 5. Products derived from this software may not be called "Apache"
|
||||||
|
* nor may "Apache" appear in their names without prior written
|
||||||
|
* permission of the Apache Software Foundation.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
||||||
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||||
|
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
* ====================================================================
|
||||||
|
*
|
||||||
|
* This software consists of voluntary contributions made by many
|
||||||
|
* individuals on behalf of the Apache Software Foundation. For more
|
||||||
|
* information on the Apache Software Foundation, please see
|
||||||
|
* <http://www.apache.org/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.apache.commons.collections.decorators;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <code>UnmodifiableSet</code> decorates another <code>Set</code> to
|
||||||
|
* ensure it can't be altered.
|
||||||
|
*
|
||||||
|
* @since Commons Collections 3.0
|
||||||
|
* @version $Revision: 1.1 $ $Date: 2003/05/07 11:19:46 $
|
||||||
|
*
|
||||||
|
* @author Stephen Colebourne
|
||||||
|
*/
|
||||||
|
public class UnmodifiableSet extends UnmodifiableCollection implements Set {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory method to create an unmodifiable set.
|
||||||
|
*
|
||||||
|
* @param set the set to decorate, must not be null
|
||||||
|
* @throws IllegalArgumentException if set is null
|
||||||
|
*/
|
||||||
|
public static Set decorate(Set set) {
|
||||||
|
return new UnmodifiableSet(set);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor that wraps (not copies).
|
||||||
|
*
|
||||||
|
* @param set the set to decorate, must not be null
|
||||||
|
* @throws IllegalArgumentException if set is null
|
||||||
|
*/
|
||||||
|
protected UnmodifiableSet(Set set) {
|
||||||
|
super(set);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the set being decorated.
|
||||||
|
*
|
||||||
|
* @return the decorated set
|
||||||
|
*/
|
||||||
|
protected Set getSet() {
|
||||||
|
return (Set) getCollection();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,131 @@
|
||||||
|
/*
|
||||||
|
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/decorators/Attic/UnmodifiableSortedSet.java,v 1.1 2003/05/07 11:19:46 scolebourne Exp $
|
||||||
|
* ====================================================================
|
||||||
|
*
|
||||||
|
* The Apache Software License, Version 1.1
|
||||||
|
*
|
||||||
|
* Copyright (c) 2003 The Apache Software Foundation. All rights
|
||||||
|
* reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
* 3. The end-user documentation included with the redistribution, if
|
||||||
|
* any, must include the following acknowledgment:
|
||||||
|
* "This product includes software developed by the
|
||||||
|
* Apache Software Foundation (http://www.apache.org/)."
|
||||||
|
* Alternately, this acknowledgment may appear in the software itself,
|
||||||
|
* if and wherever such third-party acknowledgments normally appear.
|
||||||
|
*
|
||||||
|
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
|
||||||
|
* Foundation" must not be used to endorse or promote products derived
|
||||||
|
* from this software without prior written permission. For written
|
||||||
|
* permission, please contact apache@apache.org.
|
||||||
|
*
|
||||||
|
* 5. Products derived from this software may not be called "Apache"
|
||||||
|
* nor may "Apache" appear in their names without prior written
|
||||||
|
* permission of the Apache Software Foundation.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
||||||
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||||
|
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
* ====================================================================
|
||||||
|
*
|
||||||
|
* This software consists of voluntary contributions made by many
|
||||||
|
* individuals on behalf of the Apache Software Foundation. For more
|
||||||
|
* information on the Apache Software Foundation, please see
|
||||||
|
* <http://www.apache.org/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.apache.commons.collections.decorators;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.SortedSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <code>UnmodifiableSortedSet</code> decorates another <code>SortedSet</code>
|
||||||
|
* to ensure it can't be altered.
|
||||||
|
*
|
||||||
|
* @since Commons Collections 3.0
|
||||||
|
* @version $Revision: 1.1 $ $Date: 2003/05/07 11:19:46 $
|
||||||
|
*
|
||||||
|
* @author Stephen Colebourne
|
||||||
|
*/
|
||||||
|
public class UnmodifiableSortedSet extends UnmodifiableSet implements SortedSet {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory method to create an unmodifiable set.
|
||||||
|
*
|
||||||
|
* @param set the set to decorate, must not be null
|
||||||
|
* @throws IllegalArgumentException if set is null
|
||||||
|
*/
|
||||||
|
public static SortedSet decorate(SortedSet set) {
|
||||||
|
return new UnmodifiableSortedSet(set);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor that wraps (not copies).
|
||||||
|
*
|
||||||
|
* @param set the set to decorate, must not be null
|
||||||
|
* @throws IllegalArgumentException if set is null
|
||||||
|
*/
|
||||||
|
protected UnmodifiableSortedSet(SortedSet set) {
|
||||||
|
super(set);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the set being decorated.
|
||||||
|
*
|
||||||
|
* @return the decorated set
|
||||||
|
*/
|
||||||
|
protected SortedSet getSortedSet() {
|
||||||
|
return (SortedSet) getCollection();
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------
|
||||||
|
public SortedSet subSet(Object fromElement, Object toElement) {
|
||||||
|
SortedSet sub = getSortedSet().subSet(fromElement, toElement);
|
||||||
|
return new UnmodifiableSortedSet(sub);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SortedSet headSet(Object toElement) {
|
||||||
|
SortedSet sub = getSortedSet().headSet(toElement);
|
||||||
|
return new UnmodifiableSortedSet(sub);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SortedSet tailSet(Object fromElement) {
|
||||||
|
SortedSet sub = getSortedSet().tailSet(fromElement);
|
||||||
|
return new UnmodifiableSortedSet(sub);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object first() {
|
||||||
|
return getSortedSet().first();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object last() {
|
||||||
|
return getSortedSet().last();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Comparator comparator() {
|
||||||
|
return getSortedSet().comparator();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue