Skip to content

Commit

Permalink
Make code compilable on all supported Java versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
wrandelshofer committed Oct 15, 2024
1 parent e692134 commit 199e49b
Show file tree
Hide file tree
Showing 6 changed files with 207 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
interface CharSet {
boolean contains(char ch);

public static CharSet copyOf(Set<Character> set, boolean ignoreCase) {
static CharSet copyOf(Set<Character> set, boolean ignoreCase) {
set = applyIgnoreCase(set, ignoreCase);
switch (set.size()) {
case 0:
Expand All @@ -22,10 +22,10 @@ public static CharSet copyOf(Set<Character> set, boolean ignoreCase) {
}
}

private static Set<Character> applyIgnoreCase(Set<Character> set, boolean ignoreCase) {
static Set<Character> applyIgnoreCase(Set<Character> set, boolean ignoreCase) {
if (ignoreCase) {
var convertedSet = new LinkedHashSet<Character>();
for (var ch : set) {
LinkedHashSet<Character> convertedSet = new LinkedHashSet<Character>();
for (Character ch : set) {
convertedSet.add(ch);
char lc = Character.toLowerCase(ch);
char uc = Character.toUpperCase(ch);
Expand All @@ -39,7 +39,7 @@ private static Set<Character> applyIgnoreCase(Set<Character> set, boolean ignore
return set;
}

public static CharSet copyOfFirstChar(Set<String> strSet, boolean ignoreCase) {
static CharSet copyOfFirstChar(Set<String> strSet, boolean ignoreCase) {
LinkedHashSet<Character> set = new LinkedHashSet<Character>();
for (String str : strSet) {
set.add(str.charAt(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ public static List<NumberTestData> createNumberFormatSymbolsTestData() {
public static List<NumberTestData> createEstonianNumberFormatSymbolsTestData() {
List<NumberTestData> list = new ArrayList<>();
Locale estonianLocale = new Locale("et", "EE");
var dfs = DecimalFormatSymbols.getInstance(
DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(
estonianLocale
);
assertEquals(dfs.getMinusSign(), '\u2212', "Expected estonian minus sign U+2212");
var symbols = new NumberFormatSymbols(
NumberFormatSymbols symbols = new NumberFormatSymbols(
Set.of(dfs.getDecimalSeparator()),
Set.of(dfs.getGroupingSeparator()),
Set.of(dfs.getExponentSeparator()),
Expand Down Expand Up @@ -77,11 +77,11 @@ public static List<NumberTestData> createEstonianNumberFormatSymbolsTestData() {
public static List<NumberTestData> createIgnoreCaseNumberFormatSymbolsTestData() {
List<NumberTestData> list = new ArrayList<>();
Locale englishLocale = Locale.ENGLISH;
var dfs = DecimalFormatSymbols.getInstance(englishLocale);
DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(englishLocale);
dfs.setInfinity("Infinity");
dfs.setExponentSeparator("Exp");
dfs.setNaN("NaN");
var symbols = new NumberFormatSymbols(
NumberFormatSymbols symbols = new NumberFormatSymbols(
Set.of(dfs.getDecimalSeparator()),
Set.of(dfs.getGroupingSeparator()),
Set.of(dfs.getExponentSeparator()),
Expand All @@ -92,7 +92,7 @@ public static List<NumberTestData> createIgnoreCaseNumberFormatSymbolsTestData()
dfs.getZeroDigit()
);
DecimalFormat fmt = new DecimalFormat("#00.0####E0", dfs);
for (var n : new double[]{3e-9, -7e8, Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY}) {
for (double n : new double[]{3e-9, -7e8, Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY}) {
list.add(new NumberTestData("ignoreCase: " + fmt.format(n), englishLocale, symbols, true, fmt.format(n), n));
list.add(new NumberTestData("ignoreCase: lower-case " + fmt.format(n).toLowerCase(englishLocale), englishLocale, symbols, true, fmt.format(n).toLowerCase(englishLocale), n));
list.add(new NumberTestData("ignoreCase: upper-case " + fmt.format(n).toUpperCase(englishLocale), englishLocale, symbols, true, fmt.format(n).toUpperCase(englishLocale), n));
Expand All @@ -104,12 +104,12 @@ public static List<NumberTestData> createIgnoreCaseNumberFormatSymbolsTestData()
public static List<NumberTestData> createArabianNumberFormatSymbolsTestData() {
List<NumberTestData> list = new ArrayList<>();
Locale arabianLocale = new Locale("ar");
var dfs = DecimalFormatSymbols.getInstance(
DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(
arabianLocale
);
var symbols = NumberFormatSymbols.fromDecimalFormatSymbols(dfs);
NumberFormatSymbols symbols = NumberFormatSymbols.fromDecimalFormatSymbols(dfs);
DecimalFormat fmt = new DecimalFormat("#00.0####E0", dfs);
for (var n : new double[]{3e-9, -7e8, Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY}) {
for (double n : new double[]{3e-9, -7e8, Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY}) {
list.add(new NumberTestData(fmt.format(n), arabianLocale, symbols, fmt.format(n), n));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public NumberTestData(String title,
expectedThrowableClass,
locale, symbols, false);
}

public NumberTestData(CharSequence input, Number expectedValue) {
this(input.toString(), input, 0, input.length(), 0, input.length(),
10, expectedValue, null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@ public final class NumberTestData {
private final Number expectedValue;
private final String expectedErrorMessage;
private final Class<? extends Throwable> expectedThrowableClass;
private final java.util.Locale locale;
private final Locale locale;
private final NumberFormatSymbols symbols;
private final boolean ignoreCase;

public NumberTestData(String title,
CharSequence input,
int charOffset, int charLength,
int byteOffset, int byteLength,
int radix, Number expectedValue,
String expectedErrorMessage,
Class<? extends Throwable> expectedThrowableClass,
java.util.Locale locale) {
Locale locale, NumberFormatSymbols symbols, boolean ignoreCase) {
this.title = title;
this.input = input;
this.charOffset = charOffset;
Expand All @@ -40,79 +43,112 @@ public NumberTestData(String title,
this.expectedErrorMessage = expectedErrorMessage;
this.expectedThrowableClass = expectedThrowableClass;
this.locale = locale;
this.symbols = symbols;
this.ignoreCase = ignoreCase;
}

public NumberTestData(String title,
CharSequence input,
int charOffset, int charLength,
int byteOffset, int byteLength,
int radix, Number expectedValue,
String expectedErrorMessage,
Class<? extends Throwable> expectedThrowableClass,
Locale locale, NumberFormatSymbols symbols) {
this(title,
input,
charOffset, charLength,
byteOffset, byteLength,
radix, expectedValue,
expectedErrorMessage,
expectedThrowableClass,
locale, symbols, false);
}

public NumberTestData(CharSequence input, Number expectedValue) {
this(input.toString(), input, 0, input.length(), 0, input.length(),
10, expectedValue, null,
null, Locale.ENGLISH);
null, Locale.ENGLISH, null, false);
}

public NumberTestData(Locale locale, CharSequence input, Number expectedValue) {
this(input.toString(), input, 0, input.length(), 0, input.length(),
10, expectedValue, null,
null, locale, null, false);
}

public NumberTestData(String title, Locale locale, CharSequence input, Number expectedValue) {
this(title, input, 0, input.length(), 0, input.length(),
10, expectedValue, null,
null, locale, null, false);
}

public NumberTestData(String title, Locale locale, NumberFormatSymbols symbols, CharSequence input, Number expectedValue) {
this(title, input, 0, input.length(), 0, input.length(),
10, expectedValue, null,
null, locale, symbols, false);
}

public NumberTestData(String title, Locale locale, NumberFormatSymbols symbols, boolean ignoreCase, CharSequence input, Number expectedValue) {
this(title, input, 0, input.length(), 0, input.length(),
10, expectedValue, null,
null, locale, symbols, ignoreCase);
}

public NumberTestData(CharSequence input, int radix, Number expectedValue) {
this(input.toString(), input, 0, input.length(), 0, input.length(),
radix, expectedValue, null,
null, Locale.ENGLISH);
null, Locale.ENGLISH, null, false);
}

public NumberTestData(String title, CharSequence input, int radix, Number expectedValue) {
this(title, input, 0, input.length(), 0, input.length(),
radix, expectedValue, null,
null, Locale.ENGLISH);
null, Locale.ENGLISH, null, false);
}

public NumberTestData(CharSequence input, Number expectedValue, int offset, int length) {
this(input.toString(), input, offset, length, offset, length,
10, expectedValue, null, null, Locale.ENGLISH);
10, expectedValue, null, null, Locale.ENGLISH, null, false);
}

public NumberTestData(String title, CharSequence input, int radix, String expectedErrorMessage, Class<? extends Throwable> expectedThrowableClass) {
this(title, input, 0, input.length(), 0, input.length(),
radix, null, expectedErrorMessage,
expectedThrowableClass, Locale.ENGLISH);
expectedThrowableClass, Locale.ENGLISH, null, false);
}

public NumberTestData(CharSequence input, int radix, String expectedErrorMessage, Class<? extends Throwable> expectedThrowableClass) {
this(input.toString(), input, 0, input.length(), 0, input.length(),
radix, null, expectedErrorMessage,
expectedThrowableClass, Locale.ENGLISH);
expectedThrowableClass, Locale.ENGLISH, null, false);
}

public NumberTestData(CharSequence input, Number expectedValue, int offset, int length, String expectedErrorMessage, Class<? extends Throwable> expectedThrowableClass) {
this(input.toString(), input, offset, length, offset, length,
10, expectedValue, expectedErrorMessage,
expectedThrowableClass, Locale.ENGLISH);
expectedThrowableClass, Locale.ENGLISH, null, false);
}


public NumberTestData(String title, CharSequence input, int offset, int length, int bOffset, int bLength, String expectedErrorMessage,
Class<? extends Throwable> expectedThrowableClass) {
this(title, input, offset, length, bOffset, bLength,
10, null, expectedErrorMessage,
expectedThrowableClass, Locale.ENGLISH);
expectedThrowableClass, Locale.ENGLISH, null, false);
}

public NumberTestData(String title, CharSequence input, int offset, int length, int bOffset, int bLength, Number expectedValue) {
this(title, input, offset, length, bOffset, bLength,
10, expectedValue, null,
null, Locale.ENGLISH);
null, Locale.ENGLISH, null, false);
}

public NumberTestData(Locale locale, CharSequence input, Number expectedValue) {
this(input.toString(), input, 0, input.length(), 0, input.length(),
10, expectedValue, null,
null, locale);
}

public NumberTestData(Locale locale, String title, CharSequence input, Number expectedValue) {
this(title, input, 0, input.length(), 0, input.length(),
10, expectedValue, null,
null, locale);
}
public NumberTestData(String title, CharSequence input, Number expectedValue) {
this(title,
input, 0, input.length(), 0, input.length(),
10, expectedValue, null,
null, Locale.ENGLISH);
null, Locale.ENGLISH, null, false);
}

public NumberTestData(String title, CharSequence input, Function<String, Number> constructor) {
Expand All @@ -137,14 +173,14 @@ public NumberTestData(String title, CharSequence input, String expectedErrorMess
this(title,
input, 0, input.length(), 0, input.length(),
10, null, expectedErrorMessage,
expectedThrowableClass, Locale.ENGLISH);
expectedThrowableClass, Locale.ENGLISH, null, false);
}

public NumberTestData(CharSequence input, String expectedErrorMessage, Class<? extends Throwable> expectedThrowableClass) {
this(input.toString(),
input, 0, input.length(), 0, input.length(),
10, null, expectedErrorMessage,
expectedThrowableClass, Locale.ENGLISH);
expectedThrowableClass, Locale.ENGLISH, null, false);
}

public String title() {
Expand Down Expand Up @@ -187,14 +223,22 @@ public Class<? extends Throwable> expectedThrowableClass() {
return expectedThrowableClass;
}

public Locale locale() {
return locale;
}

public NumberFormatSymbols symbols() {
return symbols;
}

public boolean ignoreCase() {
return ignoreCase;
}

@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj == null || obj.getClass() != this.getClass()) {
return false;
}
if (obj == this) return true;
if (obj == null || obj.getClass() != this.getClass()) return false;
NumberTestData that = (NumberTestData) obj;
return Objects.equals(this.title, that.title) &&
Objects.equals(this.input, that.input) &&
Expand All @@ -205,12 +249,15 @@ public boolean equals(Object obj) {
this.radix == that.radix &&
Objects.equals(this.expectedValue, that.expectedValue) &&
Objects.equals(this.expectedErrorMessage, that.expectedErrorMessage) &&
Objects.equals(this.expectedThrowableClass, that.expectedThrowableClass);
Objects.equals(this.expectedThrowableClass, that.expectedThrowableClass) &&
Objects.equals(this.locale, that.locale) &&
Objects.equals(this.symbols, that.symbols) &&
this.ignoreCase == that.ignoreCase;
}

@Override
public int hashCode() {
return Objects.hash(title, input, charOffset, charLength, byteOffset, byteLength, radix, expectedValue, expectedErrorMessage, expectedThrowableClass);
return Objects.hash(title, input, charOffset, charLength, byteOffset, byteLength, radix, expectedValue, expectedErrorMessage, expectedThrowableClass, locale, symbols, ignoreCase);
}

@Override
Expand All @@ -225,7 +272,10 @@ public String toString() {
"radix=" + radix + ", " +
"expectedValue=" + expectedValue + ", " +
"expectedErrorMessage=" + expectedErrorMessage + ", " +
"expectedThrowableClass=" + expectedThrowableClass + ']';
"expectedThrowableClass=" + expectedThrowableClass + ", " +
"locale=" + locale + ", " +
"symbols=" + symbols + ", " +
"ignoreCase=" + ignoreCase + ']';
}

}
Loading

0 comments on commit 199e49b

Please sign in to comment.