[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 @@ package org.apache.commons.lang3.text.translate;
import java.io.IOException; import java.io.IOException;
import java.io.Writer; import java.io.Writer;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.EnumSet; import java.util.EnumSet;
/** /**
@ -62,7 +63,7 @@ public class NumericEntityUnescaper extends CharSequenceTranslator {
if (options.length > 0) { if (options.length > 0) {
this.options = EnumSet.copyOf(Arrays.asList(options)); this.options = EnumSet.copyOf(Arrays.asList(options));
} else { } else {
this.options = EnumSet.copyOf(Arrays.asList(OPTION.semiColonRequired)); this.options = EnumSet.copyOf(Collections.singletonList(OPTION.semiColonRequired));
} }
} }

View File

@ -243,10 +243,10 @@ public class ObjectUtilsTest {
@Test @Test
public void testHashCodeMulti_multiple_likeList() { 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()); 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")); assertEquals(list1.hashCode(), ObjectUtils.hashCodeMulti("a"));
final List<Object> list2 = new ArrayList<>(Arrays.asList("a", "b")); final List<Object> list2 = new ArrayList<>(Arrays.asList("a", "b"));

View File

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