Use Set instead of list for better performance

This commit is contained in:
serso 2016-04-19 22:04:05 +02:00
parent 7547ee7a98
commit dec7754eb0

View File

@ -6,14 +6,16 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.List;
import java.util.HashSet;
import java.util.Set;
import static java.util.Arrays.asList;
public enum NumeralBase {
dec(10, 3) {
private final List<Character> characters = Arrays.asList('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
private final Set<Character> characters = new HashSet<>(asList('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'));
@Nonnull
@Override
@ -21,11 +23,6 @@ public enum NumeralBase {
return Double.valueOf(doubleString);
}
@Nonnull
public String toString(@Nonnull Double value) {
return value.toString();
}
@Nonnull
@Override
public String getJsclPrefix() {
@ -34,14 +31,14 @@ public enum NumeralBase {
@Nonnull
@Override
public List<Character> getAcceptableCharacters() {
public Set<Character> getAcceptableCharacters() {
return characters;
}
},
hex(16, 2) {
private final List<Character> characters = Arrays.asList('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');
private final Set<Character> characters = new HashSet<>(asList('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'));
@Nonnull
@Override
@ -51,14 +48,14 @@ public enum NumeralBase {
@Nonnull
@Override
public List<Character> getAcceptableCharacters() {
public Set<Character> getAcceptableCharacters() {
return characters;
}
},
oct(8, 4) {
private final List<Character> characters = Arrays.asList('0', '1', '2', '3', '4', '5', '6', '7');
private final Set<Character> characters = new HashSet<>(asList('0', '1', '2', '3', '4', '5', '6', '7'));
@Nonnull
@Override
@ -68,14 +65,14 @@ public enum NumeralBase {
@Nonnull
@Override
public List<Character> getAcceptableCharacters() {
public Set<Character> getAcceptableCharacters() {
return characters;
}
},
bin(2, 4) {
private final List<Character> characters = Arrays.asList('0', '1');
private final Set<Character> characters = new HashSet<>(asList('0', '1'));
@Nonnull
@Override
@ -85,7 +82,7 @@ public enum NumeralBase {
@Nonnull
@Override
public List<Character> getAcceptableCharacters() {
public Set<Character> getAcceptableCharacters() {
return characters;
}
};
@ -157,7 +154,7 @@ public enum NumeralBase {
public abstract String getJsclPrefix();
@Nonnull
public abstract List<Character> getAcceptableCharacters();
public abstract Set<Character> getAcceptableCharacters();
public int getGroupingSize() {
return groupingSize;