Skip to content

Commit 5beaae6

Browse files
Reduce else if condition
1 parent 0f25c75 commit 5beaae6

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

spring-core/src/main/java/org/springframework/util/FastByteArrayOutputStream.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -508,30 +508,31 @@ public void updateMessageDigest(MessageDigest messageDigest, int len) {
508508
// This stream doesn't have any data in it...
509509
return;
510510
}
511-
else if (len == 0) {
511+
512+
if (len == 0) {
512513
return;
513514
}
514-
else if (len < 0) {
515+
516+
if (len < 0) {
515517
throw new IllegalArgumentException("len must be 0 or greater: " + len);
516518
}
519+
520+
if (this.nextIndexInCurrentBuffer < this.currentBufferLength) {
521+
int bytesToCopy = Math.min(len, this.currentBufferLength - this.nextIndexInCurrentBuffer);
522+
messageDigest.update(this.currentBuffer, this.nextIndexInCurrentBuffer, bytesToCopy);
523+
this.nextIndexInCurrentBuffer += bytesToCopy;
524+
updateMessageDigest(messageDigest, len - bytesToCopy);
525+
}
517526
else {
518-
if (this.nextIndexInCurrentBuffer < this.currentBufferLength) {
519-
int bytesToCopy = Math.min(len, this.currentBufferLength - this.nextIndexInCurrentBuffer);
520-
messageDigest.update(this.currentBuffer, this.nextIndexInCurrentBuffer, bytesToCopy);
521-
this.nextIndexInCurrentBuffer += bytesToCopy;
522-
updateMessageDigest(messageDigest, len - bytesToCopy);
527+
if (this.buffersIterator.hasNext()) {
528+
this.currentBuffer = this.buffersIterator.next();
529+
updateCurrentBufferLength();
530+
this.nextIndexInCurrentBuffer = 0;
523531
}
524532
else {
525-
if (this.buffersIterator.hasNext()) {
526-
this.currentBuffer = this.buffersIterator.next();
527-
updateCurrentBufferLength();
528-
this.nextIndexInCurrentBuffer = 0;
529-
}
530-
else {
531-
this.currentBuffer = null;
532-
}
533-
updateMessageDigest(messageDigest, len);
533+
this.currentBuffer = null;
534534
}
535+
updateMessageDigest(messageDigest, len);
535536
}
536537
}
537538

spring-web/src/main/java/org/springframework/web/method/annotation/ModelMethodProcessor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -65,7 +65,8 @@ public void handleReturnValue(@Nullable Object returnValue, MethodParameter retu
6565
if (returnValue == null) {
6666
return;
6767
}
68-
else if (returnValue instanceof Model model) {
68+
69+
if (returnValue instanceof Model model) {
6970
mavContainer.addAllAttributes(model.asMap());
7071
}
7172
else {

0 commit comments

Comments
 (0)