Skip to content
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

Simplify utility implementations in spring-core #33903

Closed
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,11 @@ public void write(int datum) throws IOException {
if (this.closed) {
throw new IOException("Stream closed");
}
else {
if (this.buffers.peekLast() == null || this.buffers.getLast().length == this.index) {
addBuffer(1);
}
// store the byte
this.buffers.getLast()[this.index++] = (byte) datum;
if (this.buffers.peekLast() == null || this.buffers.getLast().length == this.index) {
addBuffer(1);
}
// store the byte
this.buffers.getLast()[this.index++] = (byte) datum;
}

@Override
Expand Down Expand Up @@ -384,22 +382,20 @@ public int read() {
// This stream doesn't have any data in it...
return -1;
}
if (this.nextIndexInCurrentBuffer < this.currentBufferLength) {
this.totalBytesRead++;
return this.currentBuffer[this.nextIndexInCurrentBuffer++] & 0xFF;
}
else {
if (this.nextIndexInCurrentBuffer < this.currentBufferLength) {
this.totalBytesRead++;
return this.currentBuffer[this.nextIndexInCurrentBuffer++] & 0xFF;
if (this.buffersIterator.hasNext()) {
this.currentBuffer = this.buffersIterator.next();
updateCurrentBufferLength();
this.nextIndexInCurrentBuffer = 0;
}
else {
if (this.buffersIterator.hasNext()) {
this.currentBuffer = this.buffersIterator.next();
updateCurrentBufferLength();
this.nextIndexInCurrentBuffer = 0;
}
else {
this.currentBuffer = null;
}
return read();
this.currentBuffer = null;
}
return read();
}
}

Expand Down Expand Up @@ -507,8 +503,7 @@ public void updateMessageDigest(MessageDigest messageDigest, int len) {
if (this.currentBuffer == null) {
// This stream doesn't have any data in it...
return;
}
else if (len == 0) {
}else if(len == 0){
KNU-K marked this conversation as resolved.
Show resolved Hide resolved
return;
}
else if (len < 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,12 @@ protected Method findMatchingMethod() {
Method matchingMethod = null;

for (Method candidate : candidates) {
if (candidate.getName().equals(targetMethod)) {
if (candidate.getParameterCount() == argCount) {
Class<?>[] paramTypes = candidate.getParameterTypes();
int typeDiffWeight = getTypeDifferenceWeight(paramTypes, arguments);
if (typeDiffWeight < minTypeDiffWeight) {
minTypeDiffWeight = typeDiffWeight;
matchingMethod = candidate;
}
if (candidate.getName().equals(targetMethod) && candidate.getParameterCount() == argCount) {
Class<?>[] paramTypes = candidate.getParameterTypes();
int typeDiffWeight = getTypeDifferenceWeight(paramTypes, arguments);
if (typeDiffWeight < minTypeDiffWeight) {
minTypeDiffWeight = typeDiffWeight;
matchingMethod = candidate;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,7 @@ private boolean isQuotedString(String s) {
if (s.length() < 2) {
return false;
}
else {
return ((s.startsWith("\"") && s.endsWith("\"")) || (s.startsWith("'") && s.endsWith("'")));
}
return ((s.startsWith("\"") && s.endsWith("\"")) || (s.startsWith("'") && s.endsWith("'")));
}

protected String unquote(String s) {
Expand Down Expand Up @@ -583,7 +581,6 @@ public int compareTo(MimeType other) {
}
}
}

KNU-K marked this conversation as resolved.
Show resolved Hide resolved
return 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,8 @@ else if (BigInteger.class == targetClass) {
// do not lose precision - use BigDecimal's own conversion
return (T) bigDecimal.toBigInteger();
}
else {
// original value is not a Big* number - use standard long conversion
return (T) BigInteger.valueOf(number.longValue());
}
// original value is not a Big* number - use standard long conversion
return (T) BigInteger.valueOf(number.longValue());
}
else if (Float.class == targetClass) {
return (T) Float.valueOf(number.floatValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -702,8 +702,7 @@ public static String nullSafeToString(@Nullable byte[] array) {
if (array == null) {
return NULL_STRING;
}
int length = array.length;
if (length == 0) {
if (array.length == 0) {
return EMPTY_ARRAY;
}
StringJoiner stringJoiner = new StringJoiner(ARRAY_ELEMENT_SEPARATOR, ARRAY_START, ARRAY_END);
Expand All @@ -726,8 +725,7 @@ public static String nullSafeToString(@Nullable char[] array) {
if (array == null) {
return NULL_STRING;
}
int length = array.length;
if (length == 0) {
if (array.length == 0) {
return EMPTY_ARRAY;
}
StringJoiner stringJoiner = new StringJoiner(ARRAY_ELEMENT_SEPARATOR, ARRAY_START, ARRAY_END);
Expand All @@ -750,8 +748,7 @@ public static String nullSafeToString(@Nullable double[] array) {
if (array == null) {
return NULL_STRING;
}
int length = array.length;
if (length == 0) {
if (array.length == 0) {
return EMPTY_ARRAY;
}
StringJoiner stringJoiner = new StringJoiner(ARRAY_ELEMENT_SEPARATOR, ARRAY_START, ARRAY_END);
Expand All @@ -774,8 +771,7 @@ public static String nullSafeToString(@Nullable float[] array) {
if (array == null) {
return NULL_STRING;
}
int length = array.length;
if (length == 0) {
if (array.length == 0) {
return EMPTY_ARRAY;
}
StringJoiner stringJoiner = new StringJoiner(ARRAY_ELEMENT_SEPARATOR, ARRAY_START, ARRAY_END);
Expand All @@ -798,8 +794,7 @@ public static String nullSafeToString(@Nullable int[] array) {
if (array == null) {
return NULL_STRING;
}
int length = array.length;
if (length == 0) {
if (array.length == 0) {
return EMPTY_ARRAY;
}
StringJoiner stringJoiner = new StringJoiner(ARRAY_ELEMENT_SEPARATOR, ARRAY_START, ARRAY_END);
Expand Down Expand Up @@ -846,8 +841,7 @@ public static String nullSafeToString(@Nullable short[] array) {
if (array == null) {
return NULL_STRING;
}
int length = array.length;
if (length == 0) {
if (array.length == 0) {
return EMPTY_ARRAY;
}
StringJoiner stringJoiner = new StringJoiner(ARRAY_ELEMENT_SEPARATOR, ARRAY_START, ARRAY_END);
Expand Down
Loading