hchar 2005/03/14 03:01:50
Modified: src/java/org/apache/jcs/utils/struct
SortedPreferentialArray.java
Log:
1) No need to check for num < 0 in getLargest(), for it would fail anyway had
curSize is zero.
2) Throw IndexOutOfBoundException if invalid position passed to remove()
3) simplify + speed up remove()
Revision Changes Path
1.5 +10 -22
jakarta-turbine-jcs/src/java/org/apache/jcs/utils/struct/SortedPreferentialArray.java
Index: SortedPreferentialArray.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-jcs/src/java/org/apache/jcs/utils/struct/SortedPreferentialArray.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SortedPreferentialArray.java 14 Mar 2005 08:37:29 -0000 1.4
+++ SortedPreferentialArray.java 14 Mar 2005 11:01:50 -0000 1.5
@@ -93,7 +93,6 @@
}
}
else
- if (!preferLarge)
{
Comparable lar = getLargest();
// insert if obj is smaller than the largest
@@ -120,12 +119,7 @@
*/
public Comparable getLargest()
{
- int num = curSize - 1;
- if (num < 0)
- {
- num = 0;
- }
- return array[num];
+ return array[curSize-1];
}
/**
@@ -558,24 +552,18 @@
* Removes the item from the array at the specified position. The
remaining
* items to the right are shifted left.
* @param position int
+ * @throw IndexOutOfBoundsException if position is out of range.
*/
private void remove(int position)
{
- try
- {
- // suffle left from removal point
- int end = curSize - 1;
- for (int i = position; i < end; i++)
- {
- array[i] = array[i + 1];
- }
- curSize--;
- }
- catch (Exception e)
- {
- log.error("Remove problem" + this.dumpArray(), e);
- }
-
+ if (position >= curSize || position < 0)
+ throw new IndexOutOfBoundsException("position="+position
+ + " must be less than curSize="+curSize);
+ curSize--;
+
+ if (position < curSize)
+ System.arraycopy(array, position+1, array, position, curSize);
+ return;
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]