7 ms·
This code is ugly anyway: private static void rangeCheck(int arrayLen, int fromIndex, int toIndex { if (fromIndex > toIndex) throw n
by CiPHPerCoder 10y ago
This code is ugly anyway:
private static void rangeCheck(int arrayLen, int fromIndex, int toIndex {
if (fromIndex > toIndex)
throw new IllegalArgumentException("fromIndex(" + fromIndex +
") > toIndex(" + toIndex+")");
if (fromIndex < 0)
throw new ArrayIndexOutOfBoundsException(fromIndex);
if (toIndex > arrayLen)
throw new ArrayIndexOutOfBoundsException(toIndex);
}
Missing a closing paren in the function prototype, among other things.
private static void rangeCheck(int arrayLen, int fromIndex, int toIndex)
{
if (fromIndex > toIndex) {
throw new IllegalArgumentException(
String.format("fromIndex(%d) > toIndex(%d)", fromIndex, toIndex)
);
}
if (fromIndex < 0) {
throw new ArrayIndexOutOfBoundsException(fromIndex);
}
if (toIndex > arrayLen) {
throw new ArrayIndexOutOfBoundsException(toIndex);
}
}
There you go Google, Oracle, et al. I release this snippet under MIT / WTFPL / CC0. You're welcome.
- davesque 10y agoCareful, they might sue you.
- CiPHPerCoder 10y agohttps://www.youtube.com/watch?v=MeXQBHLIPcw https://www.youtube.com/watch?v=MeXQBHLIPcw
- nickpsecurity 10y agoThat was good haha. Gotta wonder how many were made up.
- creshal 10y agoI'd use whatever Java's printf equivalent is for the IllegalArgumentException too. Sting concatenation like that is an eyesore.
- CiPHPerCoder 10y agoGood point. Updated.