commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject cvs commit: jakarta-commons/collections/src/java/org/apache/commons/collections BoundedFifoBuffer.java
Date Sat, 26 Apr 2003 15:09:48 GMT
scolebourne    2003/04/26 08:09:48

  Modified:    collections/src/java/org/apache/commons/collections
                        BoundedFifoBuffer.java
  Log:
  Minor speed improvement
  Javadoc/copyright
  
  Revision  Changes    Path
  1.7       +19 -17    jakarta-commons/collections/src/java/org/apache/commons/collections/BoundedFifoBuffer.java
  
  Index: BoundedFifoBuffer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/BoundedFifoBuffer.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- BoundedFifoBuffer.java	24 Nov 2002 16:23:21 -0000	1.6
  +++ BoundedFifoBuffer.java	26 Apr 2003 15:09:48 -0000	1.7
  @@ -1,13 +1,10 @@
   /*
    * $Header$
  - * $Revision$
  - * $Date$
  - *
    * ====================================================================
    *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 1999-2002 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
  @@ -65,6 +62,7 @@
   import java.util.Collection;
   import java.util.Iterator;
   import java.util.NoSuchElementException;
  +
   /**
    * The BoundedFifoBuffer is a <strong>very</strong> efficient implementation
of
    * Buffer that does not alter the size of the buffer at runtime.
  @@ -86,18 +84,20 @@
    * This buffer prevents null objects from being added.
    *
    * @since 2.1
  + * @version $Revision$ $Date$
  + * 
    * @author Avalon
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
    * @author Paul Jack
    * @author Stephen Colebourne
    * @author <a href="herve.quiroz@esil.univ-mrs.fr">Herve Quiroz</a>
  - * @version $Id$
    */
   public class BoundedFifoBuffer extends AbstractCollection implements Buffer, BoundedCollection
{
       private final Object[] m_elements;
       private int m_start = 0;
       private int m_end = 0;
       private boolean m_full = false;
  +    private final int maxElements;
   
       /**
        * Constructs a new <code>BoundedFifoBuffer</code> big enough to hold
  @@ -119,6 +119,7 @@
               throw new IllegalArgumentException("The size must be greater than 0");
           }
           m_elements = new Object[size];
  +        maxElements = m_elements.length;
       }
   
       /**
  @@ -126,7 +127,8 @@
        * of the elements in the specified collection. That collection's
        * elements will also be added to the buffer.
        *
  -     * @param coll  the collection whose elements to add
  +     * @param coll  the collection whose elements to add, may not be null
  +     * @throws NullPointerException if the collection is null
        */
       public BoundedFifoBuffer(Collection coll) {
           this(coll.size());
  @@ -142,9 +144,9 @@
           int size = 0;
   
           if (m_end < m_start) {
  -            size = m_elements.length - m_start + m_end;
  +            size = maxElements - m_start + m_end;
           } else if (m_end == m_start) {
  -            size = (m_full ? m_elements.length : 0);
  +            size = (m_full ? maxElements : 0);
           } else {
               size = m_end - m_start;
           }
  @@ -167,7 +169,7 @@
        * @return <code>true</code> if the collection is full
        */
       public boolean isFull() {
  -        return size() == m_elements.length;
  +        return size() == maxElements;
       }
       
       /**
  @@ -176,7 +178,7 @@
        * @return the maximum number of elements the collection can hold
        */
       public int maxSize() {
  -        return m_elements.length;
  +        return maxElements;
       }
       
       /**
  @@ -203,12 +205,12 @@
           }
   
           if (m_full) {
  -            throw new BufferOverflowException("The buffer cannot hold more than " + m_elements.length
+ " objects.");
  +            throw new BufferOverflowException("The buffer cannot hold more than " + maxElements
+ " objects.");
           }
   
           m_elements[m_end++] = element;
   
  -        if (m_end >= m_elements.length) {
  +        if (m_end >= maxElements) {
               m_end = 0;
           }
   
  @@ -249,7 +251,7 @@
           if (null != element) {
               m_elements[m_start++] = null;
   
  -            if (m_start >= m_elements.length) {
  +            if (m_start >= maxElements) {
                   m_start = 0;
               }
   
  @@ -267,7 +269,7 @@
        */
       private int increment(int index) {
           index++; 
  -        if (index >= m_elements.length) {
  +        if (index >= maxElements) {
               index = 0;
           }
           return index;
  @@ -282,7 +284,7 @@
       private int decrement(int index) {
           index--;
           if (index < 0) {
  -            index = m_elements.length - 1;
  +            index = maxElements - 1;
           }
           return index;
       }
  @@ -325,7 +327,7 @@
                   // Other elements require us to shift the subsequent elements
                   int i = lastReturnedIndex + 1;
                   while (i != m_end) {
  -                    if (i >= m_elements.length) {
  +                    if (i >= maxElements) {
                           m_elements[i - 1] = m_elements[0];
                           i = 0;
                       } else {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message