Skip to content

Commit 6d65a5c

Browse files
author
Vincent Potucek
committed
Add errorprone.refasterrules
1 parent f6b2e04 commit 6d65a5c

File tree

77 files changed

+390
-299
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+390
-299
lines changed

android/guava-testlib/src/com/google/common/collect/testing/google/SetGenerators.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ protected SortedSet<String> create(String[] elements) {
179179

180180
public static class ImmutableSortedSetExplicitComparator extends TestStringSetGenerator {
181181

182-
private static final Comparator<String> STRING_REVERSED = Collections.reverseOrder();
182+
private static final Comparator<String> STRING_REVERSED = Comparator.reverseOrder();
183183

184184
@Override
185185
protected SortedSet<String> create(String[] elements) {
@@ -194,7 +194,7 @@ protected SortedSet<String> create(String[] elements) {
194194
@SuppressWarnings("CanIgnoreReturnValueSuggester")
195195
@Override
196196
public List<String> order(List<String> insertionOrder) {
197-
sort(insertionOrder, Collections.reverseOrder());
197+
sort(insertionOrder, Comparator.reverseOrder());
198198
return insertionOrder;
199199
}
200200
}
@@ -212,7 +212,7 @@ protected SortedSet<String> create(String[] elements) {
212212
@SuppressWarnings("CanIgnoreReturnValueSuggester") // see ImmutableSortedSetExplicitComparator
213213
@Override
214214
public List<String> order(List<String> insertionOrder) {
215-
sort(insertionOrder, Collections.reverseOrder());
215+
sort(insertionOrder, Comparator.reverseOrder());
216216
return insertionOrder;
217217
}
218218
}
@@ -227,7 +227,7 @@ protected SortedSet<String> create(String[] elements) {
227227
@SuppressWarnings("CanIgnoreReturnValueSuggester") // see ImmutableSortedSetExplicitComparator
228228
@Override
229229
public List<String> order(List<String> insertionOrder) {
230-
sort(insertionOrder, Collections.reverseOrder());
230+
sort(insertionOrder, Comparator.reverseOrder());
231231
return insertionOrder;
232232
}
233233
}

android/guava-tests/benchmark/com/google/common/base/AsciiBenchmark.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,6 @@ static String charSequenceToUpperCase(CharSequence chars) {
169169
for (int i = 0; i < newChars.length; i++) {
170170
newChars[i] = Ascii.toUpperCase(chars.charAt(i));
171171
}
172-
return String.valueOf(newChars);
172+
return new String(newChars);
173173
}
174174
}

android/guava-tests/test/com/google/common/base/AsciiTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public void testEqualsIgnoreCase() {
118118
assertTrue(Ascii.equalsIgnoreCase(LOWER, UPPER));
119119
assertTrue(Ascii.equalsIgnoreCase(UPPER, LOWER));
120120
// Create new strings here to avoid early-out logic.
121-
assertTrue(Ascii.equalsIgnoreCase(new String(IGNORED), new String(IGNORED)));
121+
assertTrue(Ascii.equalsIgnoreCase(IGNORED, IGNORED));
122122
// Compare to: "\u00c1".equalsIgnoreCase("\u00e1") == true
123123
assertFalse(Ascii.equalsIgnoreCase("\u00c1", "\u00e1"));
124124
// Test chars just outside the alphabetic range ('A'-1 vs 'a'-1, 'Z'+1 vs 'z'+1)

android/guava-tests/test/com/google/common/base/ObjectsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void testEqual() throws Exception {
4646

4747
// test distinct string objects
4848
String s1 = "foobar";
49-
String s2 = new String(s1);
49+
String s2 = s1;
5050
assertTrue(Objects.equal(s1, s2));
5151

5252
assertFalse(Objects.equal(s1, null));
@@ -57,7 +57,7 @@ public void testEqual() throws Exception {
5757

5858
public void testHashCode() throws Exception {
5959
int h1 = Objects.hashCode(1, "two", 3.0);
60-
int h2 = Objects.hashCode(Integer.valueOf(1), new String("two"), Double.valueOf(3.0));
60+
int h2 = Objects.hashCode(Integer.valueOf(1), "two", Double.valueOf(3.0));
6161
// repeatable
6262
assertEquals(h1, h2);
6363

android/guava-tests/test/com/google/common/collect/ConcurrentHashMultisetTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,8 @@ private void testIdentityKeyEquality(MapMakerInternalMap.Strength keyStrength) {
337337

338338
ConcurrentHashMultiset<String> multiset = ConcurrentHashMultiset.create(map);
339339

340-
String s1 = new String("a");
341-
String s2 = new String("a");
340+
String s1 = "a";
341+
String s2 = "a";
342342
assertEquals(s1, s2); // Stating the obvious.
343343
assertTrue(s1 != s2); // Stating the obvious.
344344

@@ -373,8 +373,8 @@ private void testLogicalKeyEquality(MapMakerInternalMap.Strength keyStrength) {
373373

374374
ConcurrentHashMultiset<String> multiset = ConcurrentHashMultiset.create(map);
375375

376-
String s1 = new String("a");
377-
String s2 = new String("a");
376+
String s1 = "a";
377+
String s2 = "a";
378378
assertEquals(s1, s2); // Stating the obvious.
379379

380380
multiset.add(s1);
@@ -419,8 +419,8 @@ public void testSerializationWithMapMaker_preservesIdentityKeyEquivalence() {
419419
ConcurrentHashMultiset<String> multiset = ConcurrentHashMultiset.create(map);
420420
multiset = reserializeAndAssert(multiset);
421421

422-
String s1 = new String("a");
423-
String s2 = new String("a");
422+
String s1 = "a";
423+
String s2 = "a";
424424
assertEquals(s1, s2); // Stating the obvious.
425425
assertTrue(s1 != s2); // Stating the obvious.
426426

android/guava-tests/test/com/google/common/collect/FauxveridesTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ public String toString() {
275275

276276
private static String getTypesString(List<? extends Type> types) {
277277
List<String> names = transform(types, SIMPLE_NAME_GETTER);
278-
return Joiner.on(", ").join(names);
278+
return String.join(", ", names);
279279
}
280280

281281
private static final Function<Type, String> SIMPLE_NAME_GETTER =

android/guava-tests/test/com/google/common/collect/ImmutableListMultimapTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import com.google.common.testing.SerializableTester;
3838
import java.util.Arrays;
3939
import java.util.Collection;
40-
import java.util.Collections;
40+
import java.util.Comparator;
4141
import java.util.Map.Entry;
4242
import junit.framework.Test;
4343
import junit.framework.TestCase;
@@ -285,7 +285,7 @@ public void testBuilderOrderKeysBy() {
285285
builder.put("b", 3);
286286
builder.put("d", 2);
287287
builder.put("a", 5);
288-
builder.orderKeysBy(Collections.reverseOrder());
288+
builder.orderKeysBy(Comparator.reverseOrder());
289289
builder.put("c", 4);
290290
builder.put("a", 2);
291291
builder.put("b", 6);
@@ -323,7 +323,7 @@ public void testBuilderOrderValuesBy() {
323323
builder.put("b", 3);
324324
builder.put("d", 2);
325325
builder.put("a", 5);
326-
builder.orderValuesBy(Collections.reverseOrder());
326+
builder.orderValuesBy(Comparator.reverseOrder());
327327
builder.put("c", 4);
328328
builder.put("a", 2);
329329
builder.put("b", 6);
@@ -339,8 +339,8 @@ public void testBuilderOrderKeysAndValuesBy() {
339339
builder.put("b", 3);
340340
builder.put("d", 2);
341341
builder.put("a", 5);
342-
builder.orderKeysBy(Collections.reverseOrder());
343-
builder.orderValuesBy(Collections.reverseOrder());
342+
builder.orderKeysBy(Comparator.reverseOrder());
343+
builder.orderValuesBy(Comparator.reverseOrder());
344344
builder.put("c", 4);
345345
builder.put("a", 2);
346346
builder.put("b", 6);

android/guava-tests/test/com/google/common/collect/ImmutableSetMultimapTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.util.Arrays;
3838
import java.util.Collection;
3939
import java.util.Collections;
40+
import java.util.Comparator;
4041
import java.util.Map.Entry;
4142
import junit.framework.Test;
4243
import junit.framework.TestCase;
@@ -326,7 +327,7 @@ public void testBuilderOrderKeysBy() {
326327
builder.put("b", 3);
327328
builder.put("d", 2);
328329
builder.put("a", 5);
329-
builder.orderKeysBy(Collections.reverseOrder());
330+
builder.orderKeysBy(Comparator.reverseOrder());
330331
builder.put("c", 4);
331332
builder.put("a", 2);
332333
builder.put("b", 6);
@@ -370,7 +371,7 @@ public void testBuilderOrderValuesBy() {
370371
builder.put("b", 3);
371372
builder.put("d", 2);
372373
builder.put("a", 5);
373-
builder.orderValuesBy(Collections.reverseOrder());
374+
builder.orderValuesBy(Comparator.reverseOrder());
374375
builder.put("c", 4);
375376
builder.put("a", 2);
376377
builder.put("b", 6);
@@ -396,8 +397,8 @@ public void testBuilderOrderKeysAndValuesBy() {
396397
builder.put("b", 3);
397398
builder.put("d", 2);
398399
builder.put("a", 5);
399-
builder.orderKeysBy(Collections.reverseOrder());
400-
builder.orderValuesBy(Collections.reverseOrder());
400+
builder.orderKeysBy(Comparator.reverseOrder());
401+
builder.orderValuesBy(Comparator.reverseOrder());
401402
builder.put("c", 4);
402403
builder.put("a", 2);
403404
builder.put("b", 6);

android/guava-tests/test/com/google/common/collect/InternersTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class InternersTest extends TestCase {
3737

3838
public void testStrong_simplistic() {
3939
String canonical = "a";
40-
String not = new String("a");
40+
String not = "a";
4141

4242
Interner<String> pool = Interners.newStrongInterner();
4343
assertSame(canonical, pool.intern(canonical));
@@ -59,7 +59,7 @@ public void testStrong_builder() {
5959

6060
public void testWeak_simplistic() {
6161
String canonical = "a";
62-
String not = new String("a");
62+
String not = "a";
6363

6464
Interner<String> pool = Interners.newWeakInterner();
6565
assertSame(canonical, pool.intern(canonical));
@@ -97,7 +97,7 @@ public void testWeak_afterGC() throws InterruptedException {
9797

9898
public void testAsFunction_simplistic() {
9999
String canonical = "a";
100-
String not = new String("a");
100+
String not = "a";
101101

102102
Function<String, String> internerFunction =
103103
Interners.asFunction(Interners.<String>newStrongInterner());

android/guava-tests/test/com/google/common/collect/ListsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public class ListsTest extends TestCase {
8181
private static final class RemoveFirstFunction implements Function<String, String>, Serializable {
8282
@Override
8383
public String apply(String from) {
84-
return (from.length() == 0) ? from : from.substring(1);
84+
return (from.isEmpty()) ? from : from.substring(1);
8585
}
8686
}
8787

0 commit comments

Comments
 (0)