Skip to content

Navigation Menu

Sign in
Sign up

Rename Error message methods in Preconditions to describe their action #8490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ArthurVCristiano wants to merge 1 commit into google:master
base: master
Choose a base branch
Loading
from ArthurVCristiano:patch-4
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions guava/src/com/google/common/base/Preconditions.java
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -1444,12 +1444,12 @@ public static int checkElementIndex(int index, int size) {
public static int checkElementIndex(int index, int size, String desc) {
// Carefully optimized for execution by hotspot (explanatory comment above)
if (index < 0 || index >= size) {
throw new IndexOutOfBoundsException(badElementIndex(index, size, desc));
throw new IndexOutOfBoundsException(formatElementIndexMessage(index, size, desc));
}
return index;
}

private static String badElementIndex(int index, int size, String desc) {
private static String formatElementIndexMessage(int index, int size, String desc) {
if (index < 0) {
return lenientFormat("%s (%s) must not be negative", desc, index);
} else if (size < 0) {
Expand Down Expand Up @@ -1493,12 +1493,12 @@ public static int checkPositionIndex(int index, int size) {
public static int checkPositionIndex(int index, int size, String desc) {
// Carefully optimized for execution by hotspot (explanatory comment above)
if (index < 0 || index > size) {
throw new IndexOutOfBoundsException(badPositionIndex(index, size, desc));
throw new IndexOutOfBoundsException(formatPositionIndexMessage(index, size, desc));
}
return index;
}

private static String badPositionIndex(int index, int size, String desc) {
private static String formatPositionIndexMessage(int index, int size, String desc) {
if (index < 0) {
return lenientFormat("%s (%s) must not be negative", desc, index);
} else if (size < 0) {
Expand All @@ -1523,16 +1523,16 @@ private static String badPositionIndex(int index, int size, String desc) {
public static void checkPositionIndexes(int start, int end, int size) {
// Carefully optimized for execution by hotspot (explanatory comment above)
if (start < 0 || end < start || end > size) {
throw new IndexOutOfBoundsException(badPositionIndexes(start, end, size));
throw new IndexOutOfBoundsException(formatPositionIndexMessagees(start, end, size));
}
}

private static String badPositionIndexes(int start, int end, int size) {
private static String formatPositionIndexMessagees(int start, int end, int size) {
if (start < 0 || start > size) {
return badPositionIndex(start, size, "start index");
return formatPositionIndexMessage(start, size, "start index");
}
if (end < 0 || end > size) {
return badPositionIndex(end, size, "end index");
return formatPositionIndexMessage(end, size, "end index");
}
// end < start
return lenientFormat("end index (%s) must not be less than start index (%s)", end, start);
Expand Down

AltStyle によって変換されたページ (->オリジナル) /