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