Looks okay to me, assuming that your array does not contain null values.
Carlos
2010-09-11 15:30:32
Looks okay to me, assuming that your array does not contain null values.
Why don't just iterate it in it's natural order, i mean you don't have to compare it with the next array, just compare it with the previous one.
If max_lines
is equal to lines_array.length
, then it will work perfectly fine. Just add a one-line comment to clarify things (although the name of the variable makes it pretty clear)
current_line + 1 >= maxLines
makes sure you don't get an ArrayIndexOutOfBounds
.
Perhaps it is worth noting that there must be no null
entries in the array, otherwise you risk a NullPointerException
. So in order not to clutter your code, you can make a private method:
private boolean itemsDiffer(String current, String next) {
if (current == null && next == null {
return false; // or true, if that's your semantics
} else {
return current == null || current.equalsIgnoreCase(next);
}
}
And then have:
boolean nextLineIsDifferentOrThereIsNoNextLine =
(current_line + 1 >= max_lines) ? true :
itemsDifferent(linesArray[current_line], linesArray[current_line + 1];