Skip to content

Commit

Permalink
Remove redundant else blocks.
Browse files Browse the repository at this point in the history
Fixes #3974.

RELNOTES=n/a
PiperOrigin-RevId: 359299673
  • Loading branch information
pradipta authored and Google Java Core Libraries committed Feb 24, 2021
1 parent 3fbc6f2 commit 906cf06
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ boolean isHashCodeFast() {
public boolean equals(@NullableDecl Object object) {
if (object == this) {
return true;
} else if (object instanceof ImmutableSet
}
if (object instanceof ImmutableSet
&& isHashCodeFast()
&& ((ImmutableSet<?>) object).isHashCodeFast()
&& hashCode() != object.hashCode()) {
Expand Down
33 changes: 15 additions & 18 deletions android/guava/src/com/google/common/io/BaseEncoding.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,10 @@ public OutputStream openStream() throws IOException {
private static byte[] extract(byte[] result, int length) {
if (length == result.length) {
return result;
} else {
byte[] trunc = new byte[length];
System.arraycopy(result, 0, trunc, 0, length);
return trunc;
}
byte[] trunc = new byte[length];
System.arraycopy(result, 0, trunc, 0, length);
return trunc;
}

/**
Expand Down Expand Up @@ -517,27 +516,25 @@ private boolean hasUpperCase() {
Alphabet upperCase() {
if (!hasLowerCase()) {
return this;
} else {
checkState(!hasUpperCase(), "Cannot call upperCase() on a mixed-case alphabet");
char[] upperCased = new char[chars.length];
for (int i = 0; i < chars.length; i++) {
upperCased[i] = Ascii.toUpperCase(chars[i]);
}
return new Alphabet(name + ".upperCase()", upperCased);
}
checkState(!hasUpperCase(), "Cannot call upperCase() on a mixed-case alphabet");
char[] upperCased = new char[chars.length];
for (int i = 0; i < chars.length; i++) {
upperCased[i] = Ascii.toUpperCase(chars[i]);
}
return new Alphabet(name + ".upperCase()", upperCased);
}

Alphabet lowerCase() {
if (!hasUpperCase()) {
return this;
} else {
checkState(!hasLowerCase(), "Cannot call lowerCase() on a mixed-case alphabet");
char[] lowerCased = new char[chars.length];
for (int i = 0; i < chars.length; i++) {
lowerCased[i] = Ascii.toLowerCase(chars[i]);
}
return new Alphabet(name + ".lowerCase()", lowerCased);
}
checkState(!hasLowerCase(), "Cannot call lowerCase() on a mixed-case alphabet");
char[] lowerCased = new char[chars.length];
for (int i = 0; i < chars.length; i++) {
lowerCased[i] = Ascii.toLowerCase(chars[i]);
}
return new Alphabet(name + ".lowerCase()", lowerCased);
}

public boolean matches(char c) {
Expand Down
24 changes: 12 additions & 12 deletions android/guava/src/com/google/common/io/CharStreams.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,19 @@ public static long copy(Readable from, Appendable to) throws IOException {
} else {
return copyReaderToWriter((Reader) from, asWriter(to));
}
} else {
checkNotNull(from);
checkNotNull(to);
long total = 0;
CharBuffer buf = createBuffer();
while (from.read(buf) != -1) {
Java8Compatibility.flip(buf);
to.append(buf);
total += buf.remaining();
Java8Compatibility.clear(buf);
}
return total;
}

checkNotNull(from);
checkNotNull(to);
long total = 0;
CharBuffer buf = createBuffer();
while (from.read(buf) != -1) {
Java8Compatibility.flip(buf);
to.append(buf);
total += buf.remaining();
Java8Compatibility.clear(buf);
}
return total;
}

// TODO(lukes): consider allowing callers to pass in a buffer to use, some callers would be able
Expand Down
3 changes: 2 additions & 1 deletion guava/src/com/google/common/collect/ImmutableSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,8 @@ boolean isHashCodeFast() {
public boolean equals(@Nullable Object object) {
if (object == this) {
return true;
} else if (object instanceof ImmutableSet
}
if (object instanceof ImmutableSet
&& isHashCodeFast()
&& ((ImmutableSet<?>) object).isHashCodeFast()
&& hashCode() != object.hashCode()) {
Expand Down
33 changes: 15 additions & 18 deletions guava/src/com/google/common/io/BaseEncoding.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,10 @@ public OutputStream openStream() throws IOException {
private static byte[] extract(byte[] result, int length) {
if (length == result.length) {
return result;
} else {
byte[] trunc = new byte[length];
System.arraycopy(result, 0, trunc, 0, length);
return trunc;
}
byte[] trunc = new byte[length];
System.arraycopy(result, 0, trunc, 0, length);
return trunc;
}

/**
Expand Down Expand Up @@ -517,27 +516,25 @@ private boolean hasUpperCase() {
Alphabet upperCase() {
if (!hasLowerCase()) {
return this;
} else {
checkState(!hasUpperCase(), "Cannot call upperCase() on a mixed-case alphabet");
char[] upperCased = new char[chars.length];
for (int i = 0; i < chars.length; i++) {
upperCased[i] = Ascii.toUpperCase(chars[i]);
}
return new Alphabet(name + ".upperCase()", upperCased);
}
checkState(!hasUpperCase(), "Cannot call upperCase() on a mixed-case alphabet");
char[] upperCased = new char[chars.length];
for (int i = 0; i < chars.length; i++) {
upperCased[i] = Ascii.toUpperCase(chars[i]);
}
return new Alphabet(name + ".upperCase()", upperCased);
}

Alphabet lowerCase() {
if (!hasUpperCase()) {
return this;
} else {
checkState(!hasLowerCase(), "Cannot call lowerCase() on a mixed-case alphabet");
char[] lowerCased = new char[chars.length];
for (int i = 0; i < chars.length; i++) {
lowerCased[i] = Ascii.toLowerCase(chars[i]);
}
return new Alphabet(name + ".lowerCase()", lowerCased);
}
checkState(!hasLowerCase(), "Cannot call lowerCase() on a mixed-case alphabet");
char[] lowerCased = new char[chars.length];
for (int i = 0; i < chars.length; i++) {
lowerCased[i] = Ascii.toLowerCase(chars[i]);
}
return new Alphabet(name + ".lowerCase()", lowerCased);
}

public boolean matches(char c) {
Expand Down
24 changes: 12 additions & 12 deletions guava/src/com/google/common/io/CharStreams.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,19 @@ public static long copy(Readable from, Appendable to) throws IOException {
} else {
return copyReaderToWriter((Reader) from, asWriter(to));
}
} else {
checkNotNull(from);
checkNotNull(to);
long total = 0;
CharBuffer buf = createBuffer();
while (from.read(buf) != -1) {
Java8Compatibility.flip(buf);
to.append(buf);
total += buf.remaining();
Java8Compatibility.clear(buf);
}
return total;
}

checkNotNull(from);
checkNotNull(to);
long total = 0;
CharBuffer buf = createBuffer();
while (from.read(buf) != -1) {
Java8Compatibility.flip(buf);
to.append(buf);
total += buf.remaining();
Java8Compatibility.clear(buf);
}
return total;
}

// TODO(lukes): consider allowing callers to pass in a buffer to use, some callers would be able
Expand Down

0 comments on commit 906cf06

Please sign in to comment.