[LANG-1564] use Collections.singletonList insteadof Arrays.asList when there be only one element. (#549)

* asList

* Update TypeUtilsTest.java
This commit is contained in:
XenoAmess 2020-06-13 22:57:51 +08:00 committed by GitHub
parent 386c1e2f37
commit f2d376ae01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 5 deletions

View File

@ -19,6 +19,7 @@
import java.io.IOException;
import java.io.Writer;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumSet;
/**
@ -62,7 +63,7 @@ public NumericEntityUnescaper(final OPTION... options) {
if (options.length > 0) {
this.options = EnumSet.copyOf(Arrays.asList(options));
} else {
this.options = EnumSet.copyOf(Arrays.asList(OPTION.semiColonRequired));
this.options = EnumSet.copyOf(Collections.singletonList(OPTION.semiColonRequired));
}
}

View File

@ -243,10 +243,10 @@ public void testHashCodeMulti_multiple_nullArray() {
@Test
public void testHashCodeMulti_multiple_likeList() {
final List<Object> list0 = new ArrayList<>(Arrays.asList());
final List<Object> list0 = new ArrayList<>(Collections.emptyList());
assertEquals(list0.hashCode(), ObjectUtils.hashCodeMulti());
final List<Object> list1 = new ArrayList<>(Arrays.asList("a"));
final List<Object> list1 = new ArrayList<>(Collections.singletonList("a"));
assertEquals(list1.hashCode(), ObjectUtils.hashCodeMulti("a"));
final List<Object> list2 = new ArrayList<>(Arrays.asList("a", "b"));

View File

@ -32,7 +32,6 @@
import java.lang.reflect.WildcardType;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@ -504,7 +503,7 @@ public void testGetTypeArguments() {
assertEquals(Integer.class, typeVarAssigns.get(treeSetTypeVar),
"Type argument of Comparable from int: " + typeArg);
final Collection<Integer> col = Arrays.asList();
final Collection<Integer> col = Collections.emptyList();
typeVarAssigns = TypeUtils.getTypeArguments(List.class, Collection.class);
treeSetTypeVar = Comparable.class.getTypeParameters()[0];
assertFalse(typeVarAssigns.containsKey(treeSetTypeVar),