Our old pal Occam did a bit of shaving around some of the bushier methods:
they can be implemented in terms of some of the other methods. (For example, contains() now calls indexOf() instead of nearly duplicating it.) git-svn-id: https://samskivert.googlecode.com/svn/trunk@1772 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -106,7 +106,7 @@ public class ListUtil
|
|||||||
}
|
}
|
||||||
|
|
||||||
// expand the list if necessary
|
// expand the list if necessary
|
||||||
if (index >= list.length) {
|
if (index >= llength) {
|
||||||
list = accomodate(list, index);
|
list = accomodate(list, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,7 +226,7 @@ public class ListUtil
|
|||||||
}
|
}
|
||||||
|
|
||||||
// expand the list if necessary
|
// expand the list if necessary
|
||||||
if (index >= list.length) {
|
if (index >= llength) {
|
||||||
list = accomodate(list, index);
|
list = accomodate(list, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,22 +262,7 @@ public class ListUtil
|
|||||||
protected static boolean contains (
|
protected static boolean contains (
|
||||||
EqualityComparator eqc, Object[] list, Object element)
|
EqualityComparator eqc, Object[] list, Object element)
|
||||||
{
|
{
|
||||||
if (element == null) {
|
return (-1 != indexOf(eqc, list, element));
|
||||||
throw NPE();
|
|
||||||
}
|
|
||||||
if (list == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int llength = list.length; // no optimizing bastards
|
|
||||||
for (int i = 0; i < llength; i++) {
|
|
||||||
Object elem = list[i];
|
|
||||||
if (eqc.equals(elem, element)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -329,11 +314,9 @@ public class ListUtil
|
|||||||
throw NPE();
|
throw NPE();
|
||||||
}
|
}
|
||||||
if (list != null) {
|
if (list != null) {
|
||||||
int llength = list.length; // no optimizing bastards
|
for (int ii = 0, nn = list.length; ii < nn; ii++) {
|
||||||
for (int i = 0; i < llength; i++) {
|
if (eqc.equals(list[ii], element)) {
|
||||||
Object elem = list[i];
|
return ii;
|
||||||
if (eqc.equals(elem, element)) {
|
|
||||||
return i;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -367,23 +350,13 @@ public class ListUtil
|
|||||||
protected static Object clear (
|
protected static Object clear (
|
||||||
EqualityComparator eqc, Object[] list, Object element)
|
EqualityComparator eqc, Object[] list, Object element)
|
||||||
{
|
{
|
||||||
if (element == null) {
|
int dex = indexOf(eqc, list, element);
|
||||||
throw NPE();
|
if (dex == -1) {
|
||||||
}
|
|
||||||
// nothing to clear from an empty list
|
|
||||||
if (list == null) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Object elem = list[dex];
|
||||||
int llength = list.length; // no optimizing bastards
|
list[dex] = null;
|
||||||
for (int i = 0; i < llength; i++) {
|
return elem;
|
||||||
Object elem = list[i];
|
|
||||||
if (eqc.equals(elem, element)) {
|
|
||||||
list[i] = null;
|
|
||||||
return elem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -418,24 +391,7 @@ public class ListUtil
|
|||||||
protected static Object remove (
|
protected static Object remove (
|
||||||
EqualityComparator eqc, Object[] list, Object element)
|
EqualityComparator eqc, Object[] list, Object element)
|
||||||
{
|
{
|
||||||
if (element == null) {
|
return remove(list, indexOf(eqc, list, element));
|
||||||
throw NPE();
|
|
||||||
}
|
|
||||||
// nothing to remove from an empty list
|
|
||||||
if (list == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
int llength = list.length; // no optimizing bastards
|
|
||||||
for (int i = 0; i < llength; i++) {
|
|
||||||
Object elem = list[i];
|
|
||||||
if (eqc.equals(elem, element)) {
|
|
||||||
System.arraycopy(list, i+1, list, i, llength-(i+1));
|
|
||||||
list[llength-1] = null;
|
|
||||||
return elem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -451,7 +407,7 @@ public class ListUtil
|
|||||||
public static Object remove (Object[] list, int index)
|
public static Object remove (Object[] list, int index)
|
||||||
{
|
{
|
||||||
int llength = list.length;
|
int llength = list.length;
|
||||||
if (list == null || llength <= index) {
|
if (list == null || llength <= index || index < 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user