Author: scolebourne
Date: Mon Feb 13 14:38:20 2006
New Revision: 377517
URL: http://svn.apache.org/viewcvs?rev=377517&view=rev
Log:
Implement BoundedCollection, Add javadoc
rfe 37473
Modified:
jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/buffer/BoundedBuffer.java
(contents, props changed)
jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestAll.java
jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestBoundedBuffer.java
Modified:
jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/buffer/BoundedBuffer.java
URL:
http://svn.apache.org/viewcvs/jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/buffer/BoundedBuffer.java?rev=377517&r1=377516&r2=377517&view=diff
==============================================================================
---
jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/buffer/BoundedBuffer.java
(original)
+++
jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/buffer/BoundedBuffer.java
Mon Feb 13 14:38:20 2006
@@ -1,5 +1,5 @@
/*
- * Copyright 2005 The Apache Software Foundation
+ * Copyright 2005-2006 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,24 +15,33 @@
*/
package org.apache.commons.collections.buffer;
-import org.apache.commons.collections.Buffer;
-import org.apache.commons.collections.BufferOverflowException;
-import org.apache.commons.collections.BufferUnderflowException;
-import org.apache.commons.collections.iterators.AbstractIteratorDecorator;
-
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Collection;
import java.util.Iterator;
+import org.apache.commons.collections.BoundedCollection;
+import org.apache.commons.collections.Buffer;
+import org.apache.commons.collections.BufferOverflowException;
+import org.apache.commons.collections.BufferUnderflowException;
+import org.apache.commons.collections.iterators.AbstractIteratorDecorator;
+
/**
- * A wrapper class for buffers which makes them bounded.
+ * Decorates another <code>Buffer</code> to ensure a fixed maximum size.
+ * <p>
+ * Note: This class should only be used if you need to add bounded
+ * behaviour to another buffer. If you just want a bounded buffer then
+ * you should use [EMAIL PROTECTED] BoundedFifoBuffer} or [EMAIL PROTECTED]
CircularFifoBuffer}.
+ * <p>
+ * The decoration methods allow you to specify a timeout value, which
+ * causes the add methods to wait for up to the specified wait period.
*
* @author James Carman
- * @version $Revision: $ $Date: $
+ * @author Stephen Colebourne
+ * @version $Revision$ $Date$
* @since Commons Collections 3.2
*/
-public class BoundedBuffer extends SynchronizedBuffer {
+public class BoundedBuffer extends SynchronizedBuffer implements
BoundedCollection {
/** The serialization version. */
private static final long serialVersionUID = 1536432911093974264L;
@@ -132,6 +141,14 @@
throw new BufferOverflowException("Timeout expired");
}
}
+ }
+
+ public boolean isFull() {
+ return (collection.size() == maxSize());
+ }
+
+ public int maxSize() {
+ return maximumSize;
}
//-----------------------------------------------------------------------
Propchange:
jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/buffer/BoundedBuffer.java
------------------------------------------------------------------------------
--- svn:keywords (original)
+++ svn:keywords Mon Feb 13 14:38:20 2006
@@ -1 +1 @@
-Id
+Date Author Id Revision HeadURL
Modified:
jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestAll.java
URL:
http://svn.apache.org/viewcvs/jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestAll.java?rev=377517&r1=377516&r2=377517&view=diff
==============================================================================
---
jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestAll.java
(original)
+++
jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestAll.java
Mon Feb 13 14:38:20 2006
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2004 The Apache Software Foundation
+ * Copyright 2003-2004,2006 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -48,6 +48,7 @@
suite.addTest(TestUnboundedFifoBuffer.suite());
suite.addTest(TestBlockingBuffer.suite());
+ suite.addTest(TestBoundedBuffer.suite());
suite.addTest(TestPredicatedBuffer.suite());
suite.addTest(TestSynchronizedBuffer.suite());
suite.addTest(TestTransformedBuffer.suite());
Modified:
jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestBoundedBuffer.java
URL:
http://svn.apache.org/viewcvs/jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestBoundedBuffer.java?rev=377517&r1=377516&r2=377517&view=diff
==============================================================================
---
jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestBoundedBuffer.java
(original)
+++
jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestBoundedBuffer.java
Mon Feb 13 14:38:20 2006
@@ -1,5 +1,5 @@
/*
- * Copyright 2005 The Apache Software Foundation
+ * Copyright 2005-2006 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
package org.apache.commons.collections.buffer;
import org.apache.commons.collections.AbstractTestObject;
+import org.apache.commons.collections.BoundedCollection;
import org.apache.commons.collections.Buffer;
import org.apache.commons.collections.BufferOverflowException;
@@ -23,12 +24,24 @@
import java.util.Collections;
import java.util.Arrays;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
public class TestBoundedBuffer extends AbstractTestObject {
public TestBoundedBuffer(String testName) {
super(testName);
}
+ public static Test suite() {
+ return new TestSuite(TestBoundedBuffer.class);
+ }
+
+ public static void main(String args[]) {
+ String[] testCaseName = { TestBoundedBuffer.class.getName() };
+ junit.textui.TestRunner.main(testCaseName);
+ }
+
public String getCompatibilityVersion() {
return "3.2";
}
@@ -39,6 +52,20 @@
public Object makeObject() {
return BoundedBuffer.decorate(new UnboundedFifoBuffer(), 1);
+ }
+
+ //-----------------------------------------------------------------------
+ public void testMaxSize() {
+ final Buffer bounded = BoundedBuffer.decorate(new
UnboundedFifoBuffer(), 2, 500);
+ BoundedCollection bc = (BoundedCollection) bounded;
+ assertEquals(2, bc.maxSize());
+ assertEquals(false, bc.isFull());
+ bounded.add("A");
+ assertEquals(false, bc.isFull());
+ bounded.add("B");
+ assertEquals(true, bc.isFull());
+ bounded.remove();
+ assertEquals(false, bc.isFull());
}
public void testAddToFullBufferNoTimeout() {
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]