diff --git a/src/java/org/apache/commons/collections/decorators/AbstractSetDecorator.java b/src/java/org/apache/commons/collections/decorators/AbstractSetDecorator.java new file mode 100644 index 000000000..c160f3c4f --- /dev/null +++ b/src/java/org/apache/commons/collections/decorators/AbstractSetDecorator.java @@ -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 + * . + * + */ +package org.apache.commons.collections.decorators; + +import java.util.Set; + +/** + * AbstractSetDecorator decorates another Set. + *

+ * 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(); + } + +} diff --git a/src/java/org/apache/commons/collections/decorators/AbstractSortedSetDecorator.java b/src/java/org/apache/commons/collections/decorators/AbstractSortedSetDecorator.java new file mode 100644 index 000000000..9a2813ff2 --- /dev/null +++ b/src/java/org/apache/commons/collections/decorators/AbstractSortedSetDecorator.java @@ -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 + * . + * + */ +package org.apache.commons.collections.decorators; + +import java.util.Comparator; +import java.util.Set; +import java.util.SortedSet; + +/** + * AbstractSortedSetDecorator decorates another SortedSet. + *

+ * 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(); + } + +} diff --git a/src/java/org/apache/commons/collections/decorators/PredicatedSet.java b/src/java/org/apache/commons/collections/decorators/PredicatedSet.java new file mode 100644 index 000000000..681d98d52 --- /dev/null +++ b/src/java/org/apache/commons/collections/decorators/PredicatedSet.java @@ -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 + * . + * + */ +package org.apache.commons.collections.decorators; + +import java.util.Set; + +import org.apache.commons.collections.Predicate; + +/** + * PredicatedSet decorates another Set + * to validate additions match a specified predicate. + *

+ * 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. + *

+ * 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). + *

+ * 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(); + } + +} diff --git a/src/java/org/apache/commons/collections/decorators/PredicatedSortedSet.java b/src/java/org/apache/commons/collections/decorators/PredicatedSortedSet.java new file mode 100644 index 000000000..f93336fbf --- /dev/null +++ b/src/java/org/apache/commons/collections/decorators/PredicatedSortedSet.java @@ -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 + * . + * + */ +package org.apache.commons.collections.decorators; + +import java.util.Comparator; +import java.util.SortedSet; + +import org.apache.commons.collections.Predicate; + +/** + * PredicatedSortedSet decorates another SortedSet + * to validate additions match a specified predicate. + *

+ * 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. + *

+ * 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). + *

+ * 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(); + } + +} diff --git a/src/java/org/apache/commons/collections/decorators/SynchronizedSet.java b/src/java/org/apache/commons/collections/decorators/SynchronizedSet.java new file mode 100644 index 000000000..1dc0579f9 --- /dev/null +++ b/src/java/org/apache/commons/collections/decorators/SynchronizedSet.java @@ -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 + * . + * + */ +package org.apache.commons.collections.decorators; + +import java.util.Set; + +/** + * SynchronizedSet decorates another Set. + *

+ * 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; + } + +} diff --git a/src/java/org/apache/commons/collections/decorators/SynchronizedSortedSet.java b/src/java/org/apache/commons/collections/decorators/SynchronizedSortedSet.java new file mode 100644 index 000000000..3c5f0a61c --- /dev/null +++ b/src/java/org/apache/commons/collections/decorators/SynchronizedSortedSet.java @@ -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 + * . + * + */ +package org.apache.commons.collections.decorators; + +import java.util.Comparator; +import java.util.SortedSet; + +/** + * SynchronizedSortedSet decorates another SortedSet. + *

+ * 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(); + } + } + +} diff --git a/src/java/org/apache/commons/collections/decorators/TypedSet.java b/src/java/org/apache/commons/collections/decorators/TypedSet.java new file mode 100644 index 000000000..a48840fd4 --- /dev/null +++ b/src/java/org/apache/commons/collections/decorators/TypedSet.java @@ -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 + * . + * + */ +package org.apache.commons.collections.decorators; + +import java.util.Set; + +/** + * TypedSet decorates another Set + * to validate that elements added are of a specific type. + *

+ * The validation of additions is performed via an instanceof test against + * a specified Class. 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. + *

+ * 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). + *

+ * 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)); + } + +} diff --git a/src/java/org/apache/commons/collections/decorators/TypedSortedSet.java b/src/java/org/apache/commons/collections/decorators/TypedSortedSet.java new file mode 100644 index 000000000..050f5baf0 --- /dev/null +++ b/src/java/org/apache/commons/collections/decorators/TypedSortedSet.java @@ -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 + * . + * + */ +package org.apache.commons.collections.decorators; + +import java.util.SortedSet; + +/** + * TypedSortedSet decorates another Set + * to validate that elements added are of a specific type. + *

+ * The validation of additions is performed via an instanceof test against + * a specified Class. 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. + *

+ * 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). + *

+ * 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)); + } + +} diff --git a/src/java/org/apache/commons/collections/decorators/UnmodifiableSet.java b/src/java/org/apache/commons/collections/decorators/UnmodifiableSet.java new file mode 100644 index 000000000..cd45a4081 --- /dev/null +++ b/src/java/org/apache/commons/collections/decorators/UnmodifiableSet.java @@ -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 + * . + * + */ +package org.apache.commons.collections.decorators; + +import java.util.Set; + +/** + * UnmodifiableSet decorates another Set 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(); + } + +} diff --git a/src/java/org/apache/commons/collections/decorators/UnmodifiableSortedSet.java b/src/java/org/apache/commons/collections/decorators/UnmodifiableSortedSet.java new file mode 100644 index 000000000..0b3e6f0d4 --- /dev/null +++ b/src/java/org/apache/commons/collections/decorators/UnmodifiableSortedSet.java @@ -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 + * . + * + */ +package org.apache.commons.collections.decorators; + +import java.util.Comparator; +import java.util.SortedSet; + +/** + * UnmodifiableSortedSet decorates another SortedSet + * 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(); + } + +}