You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sc...@apache.org on 2003/02/21 00:14:03 UTC
cvs commit: jakarta-commons/collections/src/java/org/apache/commons/collections BagUtils.java
scolebourne 2003/02/20 15:14:03
Modified: collections/src/java/org/apache/commons/collections
BagUtils.java
Log:
Use correct internal method, from Andrew Freeman
Update licence and javadoc
Revision Changes Path
1.8 +62 -47 jakarta-commons/collections/src/java/org/apache/commons/collections/BagUtils.java
Index: BagUtils.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/BagUtils.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- BagUtils.java 13 Oct 2002 00:38:36 -0000 1.7
+++ BagUtils.java 20 Feb 2003 23:14:03 -0000 1.8
@@ -1,13 +1,10 @@
/*
* $Header$
- * $Revision$
- * $Date$
- *
* ====================================================================
*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999-2001 The Apache Software Foundation. All rights
+ * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -23,11 +20,11 @@
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
+ * any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements normally appear.
+ * 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
@@ -36,7 +33,7 @@
*
* 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 Group.
+ * 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
@@ -62,24 +59,30 @@
import java.util.Comparator;
import java.util.Set;
+
/**
* Provides utility methods and decorators for {@link Bag}
- * and {@link SortedBag} instances.<P>
+ * and {@link SortedBag} instances.
*
+ * @since Commons Collections 2.1
+ * @version $Revision$ $Date$
+ *
* @author Paul Jack
* @author Stephen Colebourne
- * @version $Id$
- * @since 2.1
+ * @author Andrew Freeman
*/
public class BagUtils {
/**
- * Prevents instantiation.
+ * Instantiation of BagUtils is not intended or required.
+ * However, some tools require an instance to operate.
*/
- private BagUtils() {
+ public BagUtils() {
}
-
+ /**
+ * Implementation of a Bag that validates elements before they are added.
+ */
static class PredicatedBag
extends CollectionUtils.PredicatedCollection
implements Bag {
@@ -106,72 +109,80 @@
}
private Bag getBag() {
- return (Bag)collection;
+ return (Bag) collection;
}
}
- static class UnmodifiableBag
- extends CollectionUtils.UnmodifiableCollection
+ /**
+ * Implementation of a Bag that is synchronized.
+ */
+ static class SynchronizedBag
+ extends CollectionUtils.SynchronizedCollection
implements Bag {
- public UnmodifiableBag(Bag bag) {
+ public SynchronizedBag(Bag bag) {
super(bag);
}
- private Bag getBag() {
- return (Bag)collection;
+ public synchronized boolean add(Object o, int count) {
+ return getBag().add(o, count);
}
- public boolean add(Object o, int count) {
- throw new UnsupportedOperationException();
+ public synchronized boolean remove(Object o, int count) {
+ return getBag().remove(o, count);
}
- public boolean remove(Object o, int count) {
- throw new UnsupportedOperationException();
+ public synchronized Set uniqueSet() {
+ return getBag().uniqueSet();
}
- public Set uniqueSet() {
- return ((Bag)collection).uniqueSet();
+ public synchronized int getCount(Object o) {
+ return getBag().getCount(o);
}
- public int getCount(Object o) {
- return ((Bag)collection).getCount(o);
+ private Bag getBag() {
+ return (Bag) collection;
}
}
- static class SynchronizedBag
- extends CollectionUtils.SynchronizedCollection
+ /**
+ * Implementation of a Bag that is unmodifiable.
+ */
+ static class UnmodifiableBag
+ extends CollectionUtils.UnmodifiableCollection
implements Bag {
- public SynchronizedBag(Bag bag) {
+ public UnmodifiableBag(Bag bag) {
super(bag);
}
- public synchronized boolean add(Object o, int count) {
- return getBag().add(o, count);
+ public boolean add(Object o, int count) {
+ throw new UnsupportedOperationException();
}
- public synchronized boolean remove(Object o, int count) {
- return getBag().remove(o, count);
+ public boolean remove(Object o, int count) {
+ throw new UnsupportedOperationException();
}
- public synchronized Set uniqueSet() {
+ public Set uniqueSet() {
return getBag().uniqueSet();
}
- public synchronized int getCount(Object o) {
+ public int getCount(Object o) {
return getBag().getCount(o);
}
-
+
private Bag getBag() {
- return (Bag)collection;
+ return (Bag) collection;
}
-
}
+ /**
+ * Implementation of a SortedBag that validates elements before they are added.
+ */
static class PredicatedSortedBag
extends PredicatedBag
implements SortedBag {
@@ -193,11 +204,14 @@
}
private SortedBag getSortedBag() {
- return (SortedBag)collection;
+ return (SortedBag) collection;
}
}
+ /**
+ * Implementation of a SortedBag that is synchronized.
+ */
static class SynchronizedSortedBag
extends SynchronizedBag
implements SortedBag {
@@ -219,13 +233,15 @@
}
private SortedBag getSortedBag() {
- return (SortedBag)collection;
+ return (SortedBag) collection;
}
-
}
- static class UnmodifiableSortedBag
+ /**
+ * Implementation of a SortedBag that is unmodifiable.
+ */
+ static class UnmodifiableSortedBag
extends UnmodifiableBag
implements SortedBag {
@@ -246,9 +262,8 @@
}
private SortedBag getSortedBag() {
- return (SortedBag)collection;
+ return (SortedBag) collection;
}
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org