From dec7754eb0a2dffe3e43f24e8349fadd8244ec99 Mon Sep 17 00:00:00 2001 From: serso Date: Tue, 19 Apr 2016 22:04:05 +0200 Subject: [PATCH] Use Set instead of list for better performance --- jscl/src/main/java/jscl/NumeralBase.java | 29 +++++++++++------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/jscl/src/main/java/jscl/NumeralBase.java b/jscl/src/main/java/jscl/NumeralBase.java index 2f329dd6..43311535 100644 --- a/jscl/src/main/java/jscl/NumeralBase.java +++ b/jscl/src/main/java/jscl/NumeralBase.java @@ -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 characters = Arrays.asList('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'); + private final Set 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 getAcceptableCharacters() { + public Set getAcceptableCharacters() { return characters; } }, hex(16, 2) { - private final List characters = Arrays.asList('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'); + private final Set 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 getAcceptableCharacters() { + public Set getAcceptableCharacters() { return characters; } }, oct(8, 4) { - private final List characters = Arrays.asList('0', '1', '2', '3', '4', '5', '6', '7'); + private final Set 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 getAcceptableCharacters() { + public Set getAcceptableCharacters() { return characters; } }, bin(2, 4) { - private final List characters = Arrays.asList('0', '1'); + private final Set characters = new HashSet<>(asList('0', '1')); @Nonnull @Override @@ -85,7 +82,7 @@ public enum NumeralBase { @Nonnull @Override - public List getAcceptableCharacters() { + public Set getAcceptableCharacters() { return characters; } }; @@ -157,7 +154,7 @@ public enum NumeralBase { public abstract String getJsclPrefix(); @Nonnull - public abstract List getAcceptableCharacters(); + public abstract Set getAcceptableCharacters(); public int getGroupingSize() { return groupingSize;