From da740edd3972fa049c4c8d0e43448c10a6a65dce Mon Sep 17 00:00:00 2001 From: Adrien Hopkins Date: Sun, 15 Jun 2025 19:26:12 -0500 Subject: Format & clean up source code --- .../java/sevenUnits/utils/UncertainDouble.java | 173 ++++++++++----------- 1 file changed, 82 insertions(+), 91 deletions(-) (limited to 'src/main/java/sevenUnits/utils/UncertainDouble.java') diff --git a/src/main/java/sevenUnits/utils/UncertainDouble.java b/src/main/java/sevenUnits/utils/UncertainDouble.java index f700454..ecee586 100644 --- a/src/main/java/sevenUnits/utils/UncertainDouble.java +++ b/src/main/java/sevenUnits/utils/UncertainDouble.java @@ -19,7 +19,6 @@ package sevenUnits.utils; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.Objects; -import java.util.regex.Matcher; import java.util.regex.Pattern; /** @@ -32,16 +31,12 @@ import java.util.regex.Pattern; * @since v0.3.0 */ public final class UncertainDouble implements Comparable { - /** - * The exact value 0 - */ + /** The exact value 0 */ public static final UncertainDouble ZERO = UncertainDouble.of(0, 0); static final String NUMBER_REGEX = "(\\d+(?:[\\.,]\\d+))"; - /** - * A regular expression that can recognize toString forms - */ + /** A regular expression that can recognize toString forms */ static final Pattern TO_STRING = Pattern.compile(NUMBER_REGEX // optional "± [number]" + "(?:\\s*(?:±|\\+-)\\s*" + NUMBER_REGEX + ")?"); @@ -50,18 +45,18 @@ public final class UncertainDouble implements Comparable { * Gets an UncertainDouble from a double string. The uncertainty of the * double will be one of the lowest decimal place of the number. For example, * "12345.678" will become 12345.678 ± 0.001. - * + * * @param s string to parse * @return parsed {@code UncertainDouble} - * + * * @throws NumberFormatException if the argument is not a number * * @since 2022-04-18 * @since v0.4.0 */ - public static final UncertainDouble fromRoundedString(String s) { - final BigDecimal value = new BigDecimal(s); - final double uncertainty = Math.pow(10, -value.scale()); + public static UncertainDouble fromRoundedString(String s) { + final var value = new BigDecimal(s); + final var uncertainty = Math.pow(10, -value.scale()); return UncertainDouble.of(value.doubleValue(), uncertainty); } @@ -72,16 +67,16 @@ public final class UncertainDouble implements Comparable { *

* This method allows some alternative forms of the string representation, * such as using "+-" instead of "±". - * + * * @param s string to parse * @return {@code UncertainDouble} instance * @throws IllegalArgumentException if the string is invalid * @since 2020-09-07 * @since v0.3.0 */ - public static final UncertainDouble fromString(String s) { + public static UncertainDouble fromString(String s) { Objects.requireNonNull(s, "s may not be null"); - final Matcher matcher = TO_STRING.matcher(s); + final var matcher = TO_STRING.matcher(s); if (!matcher.matches()) throw new IllegalArgumentException( @@ -95,7 +90,7 @@ public final class UncertainDouble implements Comparable { "String " + s + " not in correct format."); } - final String uncertaintyString = matcher.group(2); + final var uncertaintyString = matcher.group(2); if (uncertaintyString == null) { uncertainty = 0; } else { @@ -113,32 +108,32 @@ public final class UncertainDouble implements Comparable { /** * Gets an {@code UncertainDouble} from its value and absolute * uncertainty. - * + * * @param value double's value * @param uncertainty double's uncertainty (non-negative) * @return {@code UncertainDouble} instance with these parameters - * + * * @since 2020-09-07 * @since v0.3.0 */ - public static final UncertainDouble of(double value, double uncertainty) { + public static UncertainDouble of(double value, double uncertainty) { return new UncertainDouble(value, uncertainty); } /** * Gets an {@code UncertainDouble} from its value and relative * uncertainty. - * + * * @param value double's value * @param relativeUncertainty double's uncertainty (non-negative); the * absolute uncertainty is equal to this value * multiplied by {@code relativeUncertainty} * @return {@code UncertainDouble} instance with these parameters - * + * * @since 2020-09-07 * @since v0.3.0 */ - public static final UncertainDouble ofRelative(double value, + public static UncertainDouble ofRelative(double value, double relativeUncertainty) { return new UncertainDouble(value, value * relativeUncertainty); } @@ -173,20 +168,20 @@ public final class UncertainDouble implements Comparable { * {@code false}. */ @Override - public final int compareTo(UncertainDouble o) { + public int compareTo(UncertainDouble o) { return Double.compare(this.value, o.value); } /** * Returns the quotient of {@code this} and {@code other}. - * + * * @param other number to divide by * @return quotient - * + * * @since 2020-09-07 * @since v0.3.0 */ - public final UncertainDouble dividedBy(UncertainDouble other) { + public UncertainDouble dividedBy(UncertainDouble other) { Objects.requireNonNull(other, "other may not be null"); return UncertainDouble.ofRelative(this.value / other.value, Math .hypot(this.relativeUncertainty(), other.relativeUncertainty())); @@ -194,27 +189,25 @@ public final class UncertainDouble implements Comparable { /** * Returns the quotient of {@code this} and the exact value {@code other}. - * + * * @param other number to divide by * @return quotient - * + * * @since 2020-09-07 * @since v0.3.0 */ - public final UncertainDouble dividedByExact(double other) { + public UncertainDouble dividedByExact(double other) { return UncertainDouble.of(this.value / other, this.uncertainty / other); } @Override - public final boolean equals(Object obj) { + public boolean equals(Object obj) { if (this == obj) return true; if (!(obj instanceof UncertainDouble)) return false; - final UncertainDouble other = (UncertainDouble) obj; - if (Double.compare(this.value, other.value) != 0) - return false; - if (Double.compare(this.uncertainty, other.uncertainty) != 0) + final var other = (UncertainDouble) obj; + if ((Double.compare(this.value, other.value) != 0) || (Double.compare(this.uncertainty, other.uncertainty) != 0)) return false; return true; } @@ -226,7 +219,7 @@ public final class UncertainDouble implements Comparable { * @since 2020-09-07 * @since v0.3.0 */ - public final boolean equivalent(UncertainDouble other) { + public boolean equivalent(UncertainDouble other) { Objects.requireNonNull(other, "other may not be null"); return Math.abs(this.value - other.value) <= Math.min(this.uncertainty, other.uncertainty); @@ -234,11 +227,11 @@ public final class UncertainDouble implements Comparable { /** * Gets the preferred scale for rounding a value for toString. - * + * * @since 2020-09-07 * @since v0.3.0 */ - private final int getDisplayScale() { + private int getDisplayScale() { // round based on uncertainty // if uncertainty starts with 1 (ignoring zeroes and the decimal // point), rounds @@ -246,24 +239,23 @@ public final class UncertainDouble implements Comparable { // otherwise, rounds so that uncertainty has 1 significant digits. // the value is rounded to the same number of decimal places as the // uncertainty. - final BigDecimal bigUncertainty = BigDecimal.valueOf(this.uncertainty); + final var bigUncertainty = BigDecimal.valueOf(this.uncertainty); // the scale that will give the uncertainty two decimal places - final int twoDecimalPlacesScale = bigUncertainty.scale() + final var twoDecimalPlacesScale = bigUncertainty.scale() - bigUncertainty.precision() + 2; - final BigDecimal roundedUncertainty = bigUncertainty + final var roundedUncertainty = bigUncertainty .setScale(twoDecimalPlacesScale, RoundingMode.HALF_EVEN); if (roundedUncertainty.unscaledValue().intValue() >= 20) return twoDecimalPlacesScale - 1; // one decimal place - else - return twoDecimalPlacesScale; + return twoDecimalPlacesScale; } @Override - public final int hashCode() { - final int prime = 31; - int result = 1; + public int hashCode() { + final var prime = 31; + var result = 1; result = prime * result + Double.hashCode(this.value); result = prime * result + Double.hashCode(this.uncertainty); return result; @@ -271,24 +263,24 @@ public final class UncertainDouble implements Comparable { /** * @return true iff the value has no uncertainty - * + * * @since 2020-09-07 * @since v0.3.0 */ - public final boolean isExact() { + public boolean isExact() { return this.uncertainty == 0; } /** * Returns the difference of {@code this} and {@code other}. - * + * * @param other number to subtract * @return result of subtraction - * + * * @since 2020-09-07 * @since v0.3.0 */ - public final UncertainDouble minus(UncertainDouble other) { + public UncertainDouble minus(UncertainDouble other) { Objects.requireNonNull(other, "other may not be null"); return UncertainDouble.of(this.value - other.value, Math.hypot(this.uncertainty, other.uncertainty)); @@ -296,27 +288,27 @@ public final class UncertainDouble implements Comparable { /** * Returns the difference of {@code this} and the exact value {@code other}. - * + * * @param other number to subtract * @return result of subtraction - * + * * @since 2020-09-07 * @since v0.3.0 */ - public final UncertainDouble minusExact(double other) { + public UncertainDouble minusExact(double other) { return UncertainDouble.of(this.value - other, this.uncertainty); } /** * Returns the sum of {@code this} and {@code other}. - * + * * @param other number to add * @return result of addition - * + * * @since 2020-09-07 * @since v0.3.0 */ - public final UncertainDouble plus(UncertainDouble other) { + public UncertainDouble plus(UncertainDouble other) { Objects.requireNonNull(other, "other may not be null"); return UncertainDouble.of(this.value + other.value, Math.hypot(this.uncertainty, other.uncertainty)); @@ -324,14 +316,14 @@ public final class UncertainDouble implements Comparable { /** * Returns the sum of {@code this} and the exact value {@code other}. - * + * * @param other number to add * @return result of addition - * + * * @since 2020-09-07 * @since v0.3.0 */ - public final UncertainDouble plusExact(double other) { + public UncertainDouble plusExact(double other) { return UncertainDouble.of(this.value + other, this.uncertainty); } @@ -340,20 +332,20 @@ public final class UncertainDouble implements Comparable { * @since 2020-09-07 * @since v0.3.0 */ - public final double relativeUncertainty() { + public double relativeUncertainty() { return this.uncertainty / this.value; } /** * Returns the product of {@code this} and {@code other}. - * + * * @param other number to multiply * @return product - * + * * @since 2020-09-07 * @since v0.3.0 */ - public final UncertainDouble times(UncertainDouble other) { + public UncertainDouble times(UncertainDouble other) { Objects.requireNonNull(other, "other may not be null"); return UncertainDouble.ofRelative(this.value * other.value, Math .hypot(this.relativeUncertainty(), other.relativeUncertainty())); @@ -361,31 +353,31 @@ public final class UncertainDouble implements Comparable { /** * Returns the product of {@code this} and the exact value {@code other}. - * + * * @param other number to multiply * @return product - * + * * @since 2020-09-07 * @since v0.3.0 */ - public final UncertainDouble timesExact(double other) { + public UncertainDouble timesExact(double other) { return UncertainDouble.of(this.value * other, this.uncertainty * other); } /** * Returns the result of {@code this} raised to the exponent {@code other}. - * + * * @param other exponent * @return result of exponentation - * + * * @since 2020-09-07 * @since v0.3.0 */ - public final UncertainDouble toExponent(UncertainDouble other) { + public UncertainDouble toExponent(UncertainDouble other) { Objects.requireNonNull(other, "other may not be null"); - final double result = Math.pow(this.value, other.value); - final double relativeUncertainty = Math.hypot( + final var result = Math.pow(this.value, other.value); + final var relativeUncertainty = Math.hypot( other.value * this.relativeUncertainty(), Math.log(this.value) * other.uncertainty); @@ -395,14 +387,14 @@ public final class UncertainDouble implements Comparable { /** * Returns the result of {@code this} raised the exact exponent * {@code other}. - * + * * @param other exponent * @return result of exponentation - * + * * @since 2020-09-07 * @since v0.3.0 */ - public final UncertainDouble toExponentExact(double other) { + public UncertainDouble toExponentExact(double other) { return UncertainDouble.ofRelative(Math.pow(this.value, other), this.relativeUncertainty() * other); } @@ -413,21 +405,21 @@ public final class UncertainDouble implements Comparable { * This method returns the same value as * {@link #toString(boolean, RoundingMode)}, but {@code showUncertainty} is * true if and only if the uncertainty is non-zero. - * + * *

* Examples: - * + * *

 	 * UncertainDouble.of(3.27, 0.22).toString() = "3.3 � 0.2"
 	 * UncertainDouble.of(3.27, 0.13).toString() = "3.27 � 0.13"
 	 * UncertainDouble.of(-5.01, 0).toString() = "-5.01"
 	 * 
- * + * * @since 2020-09-07 * @since v0.3.0 */ @Override - public final String toString() { + public String toString() { return this.toString(!this.isExact(), RoundingMode.HALF_EVEN); } @@ -447,7 +439,7 @@ public final class UncertainDouble implements Comparable { * digits otherwise it will be rounded to one significant digit. *

* Examples: - * + * *

 	 * UncertainDouble.of(3.27, 0.22).toString(false) = "3.3"
 	 * UncertainDouble.of(3.27, 0.22).toString(true) = "3.3 ± 0.2"
@@ -456,16 +448,15 @@ public final class UncertainDouble implements Comparable {
 	 * UncertainDouble.of(-5.01, 0).toString(false) = "-5.01"
 	 * UncertainDouble.of(-5.01, 0).toString(true) = "-5.01 ± 0.0"
 	 * 
- * + * * @param showUncertainty uncertainty is only shown if this parameter is true - * @param roundingMode how to round values + * @param roundingMode how to round values * @return string representation of this {@code UncertainDouble} - * + * * @since 2020-09-07 * @since v0.3.0 */ - public final String toString(boolean showUncertainty, - RoundingMode roundingMode) { + public String toString(boolean showUncertainty, RoundingMode roundingMode) { String valueString, uncertaintyString; // generate the string representation of value and uncertainty @@ -475,13 +466,13 @@ public final class UncertainDouble implements Comparable { } else { // round the value and uncertainty according to getDisplayScale() - final BigDecimal bigValue = BigDecimal.valueOf(this.value); - final BigDecimal bigUncertainty = BigDecimal.valueOf(this.uncertainty); + final var bigValue = BigDecimal.valueOf(this.value); + final var bigUncertainty = BigDecimal.valueOf(this.uncertainty); - final int displayScale = this.getDisplayScale(); - final BigDecimal roundedUncertainty = bigUncertainty + final var displayScale = this.getDisplayScale(); + final var roundedUncertainty = bigUncertainty .setScale(displayScale, roundingMode); - final BigDecimal roundedValue = bigValue.setScale(displayScale, + final var roundedValue = bigValue.setScale(displayScale, roundingMode); valueString = roundedValue.toString(); @@ -497,7 +488,7 @@ public final class UncertainDouble implements Comparable { * @since 2020-09-07 * @since v0.3.0 */ - public final double uncertainty() { + public double uncertainty() { return this.uncertainty; } @@ -506,7 +497,7 @@ public final class UncertainDouble implements Comparable { * @since 2020-09-07 * @since v0.3.0 */ - public final double value() { + public double value() { return this.value; } } -- cgit v1.2.3 From bccb5b5e3452421c81c1fb58f83391ba6584807c Mon Sep 17 00:00:00 2001 From: Adrien Hopkins Date: Sun, 15 Jun 2025 19:37:19 -0500 Subject: Bump version number to 1.0.0 --- README.org | 4 ++-- src/main/java/sevenUnits/ProgramInfo.java | 5 ++--- src/main/java/sevenUnits/unit/LinearUnit.java | 6 ++---- src/main/java/sevenUnits/unit/LinearUnitValue.java | 3 +-- src/main/java/sevenUnits/unit/UnitDatabase.java | 13 +++++-------- .../sevenUnits/utils/SemanticVersionNumber.java | 5 +++-- src/main/java/sevenUnits/utils/UncertainDouble.java | 8 ++++---- .../sevenUnitsGUI/DefaultPrefixRepetitionRule.java | 3 ++- src/main/java/sevenUnitsGUI/Presenter.java | 3 +-- src/main/java/sevenUnitsGUI/SearchBoxList.java | 4 ++-- src/test/java/sevenUnits/unit/UnitTest.java | 9 +++------ .../utils/ConditionalExistenceCollectionsTest.java | 3 +-- .../java/sevenUnits/utils/SemanticVersionTest.java | 21 +++++++-------------- .../java/sevenUnits/utils/UncertainDoubleTest.java | 9 +++------ 14 files changed, 38 insertions(+), 58 deletions(-) (limited to 'src/main/java/sevenUnits/utils/UncertainDouble.java') diff --git a/README.org b/README.org index ff46ae2..2e3f227 100644 --- a/README.org +++ b/README.org @@ -1,5 +1,5 @@ -* 7Units Version 1.0.0-beta.2 -(this project uses Semantic Versioning) +* 7Units Version 1.0.0 +This project uses Semantic Versioning, and its public API is all public code in ~src/main/java~. [[http://unmaintained.tech/][http://unmaintained.tech/badge.svg]] ** What is it? diff --git a/src/main/java/sevenUnits/ProgramInfo.java b/src/main/java/sevenUnits/ProgramInfo.java index 5ed1309..e74a99b 100644 --- a/src/main/java/sevenUnits/ProgramInfo.java +++ b/src/main/java/sevenUnits/ProgramInfo.java @@ -25,10 +25,9 @@ import sevenUnits.utils.SemanticVersionNumber; * @since v0.3.1 */ public final class ProgramInfo { - - /** The version number (1.0.0-beta.2) */ + /** The version number (1.0.0) */ public static final SemanticVersionNumber VERSION = SemanticVersionNumber - .preRelease(1, 0, 0, "beta", 2); + .stableVersion(1, 0, 0); private ProgramInfo() { // this class is only for static variables, you shouldn't be able to diff --git a/src/main/java/sevenUnits/unit/LinearUnit.java b/src/main/java/sevenUnits/unit/LinearUnit.java index 22105b6..85f6dd9 100644 --- a/src/main/java/sevenUnits/unit/LinearUnit.java +++ b/src/main/java/sevenUnits/unit/LinearUnit.java @@ -220,8 +220,7 @@ public final class LinearUnit extends Unit { Objects.requireNonNull(divisor, "other must not be null"); // divide the units - final var base = this.getBase() - .dividedBy(divisor.getBase()); + final var base = this.getBase().dividedBy(divisor.getBase()); return valueOf(base, this.getConversionFactor() / divisor.getConversionFactor()); } @@ -382,8 +381,7 @@ public final class LinearUnit extends Unit { Objects.requireNonNull(multiplier, "other must not be null"); // multiply the units - final var base = this.getBase() - .times(multiplier.getBase()); + final var base = this.getBase().times(multiplier.getBase()); return valueOf(base, this.getConversionFactor() * multiplier.getConversionFactor()); } diff --git a/src/main/java/sevenUnits/unit/LinearUnitValue.java b/src/main/java/sevenUnits/unit/LinearUnitValue.java index 9a99e00..ce60e3b 100644 --- a/src/main/java/sevenUnits/unit/LinearUnitValue.java +++ b/src/main/java/sevenUnits/unit/LinearUnitValue.java @@ -150,8 +150,7 @@ public final class LinearUnitValue { remaining = remaining.minus(value); } - final var lastValue = remaining - .convertTo(others.get(others.size() - 1)); + final var lastValue = remaining.convertTo(others.get(others.size() - 1)); values.add(lastValue); return values; } diff --git a/src/main/java/sevenUnits/unit/UnitDatabase.java b/src/main/java/sevenUnits/unit/UnitDatabase.java index 05e9cc9..36c225f 100644 --- a/src/main/java/sevenUnits/unit/UnitDatabase.java +++ b/src/main/java/sevenUnits/unit/UnitDatabase.java @@ -1229,12 +1229,10 @@ public final class UnitDatabase { private final ExpressionParser prefixExpressionParser = new ExpressionParser.Builder<>( this::getPrefix).addBinaryOperator("+", UnitPrefix::plus, 0) .addBinaryOperator("-", UnitPrefix::minus, 0) - .addBinaryOperator("*", UnitPrefix::times, 1) - .addSpaceFunction("*") + .addBinaryOperator("*", UnitPrefix::times, 1).addSpaceFunction("*") .addBinaryOperator("/", UnitPrefix::dividedBy, 1) - .addBinaryOperator("|", UnitPrefix::dividedBy, 3) - .addBinaryOperator("^", (o1, o2) -> o1.toExponent(o2.getMultiplier()), - 2) + .addBinaryOperator("|", UnitPrefix::dividedBy, 3).addBinaryOperator( + "^", (o1, o2) -> o1.toExponent(o2.getMultiplier()), 2) .build(); /** @@ -1624,9 +1622,8 @@ public final class UnitDatabase { if (unit instanceof LinearUnit) return (LinearUnit) unit; - else - throw new IllegalArgumentException( - String.format("%s is not a linear unit.", name)); + throw new IllegalArgumentException( + String.format("%s is not a linear unit.", name)); } /** diff --git a/src/main/java/sevenUnits/utils/SemanticVersionNumber.java b/src/main/java/sevenUnits/utils/SemanticVersionNumber.java index c081a25..4bb7ce5 100644 --- a/src/main/java/sevenUnits/utils/SemanticVersionNumber.java +++ b/src/main/java/sevenUnits/utils/SemanticVersionNumber.java @@ -332,7 +332,7 @@ public final class SemanticVersionNumber if (aNumber < bNumber) return -1; - else if (aNumber > bNumber) + if (aNumber > bNumber) return 1; } else if (NUMERIC_IDENTIFER.matcher(bElement).matches()) // aElement is not a number but bElement is @@ -602,7 +602,8 @@ public final class SemanticVersionNumber return false; } else if (!this.buildMetadata.equals(other.buildMetadata)) return false; - if ((this.major != other.major) || (this.minor != other.minor) || (this.patch != other.patch)) + if ((this.major != other.major) || (this.minor != other.minor) + || (this.patch != other.patch)) return false; if (this.preReleaseIdentifiers == null) { if (other.preReleaseIdentifiers != null) diff --git a/src/main/java/sevenUnits/utils/UncertainDouble.java b/src/main/java/sevenUnits/utils/UncertainDouble.java index ecee586..24ada20 100644 --- a/src/main/java/sevenUnits/utils/UncertainDouble.java +++ b/src/main/java/sevenUnits/utils/UncertainDouble.java @@ -207,7 +207,8 @@ public final class UncertainDouble implements Comparable { if (!(obj instanceof UncertainDouble)) return false; final var other = (UncertainDouble) obj; - if ((Double.compare(this.value, other.value) != 0) || (Double.compare(this.uncertainty, other.uncertainty) != 0)) + if ((Double.compare(this.value, other.value) != 0) + || (Double.compare(this.uncertainty, other.uncertainty) != 0)) return false; return true; } @@ -470,10 +471,9 @@ public final class UncertainDouble implements Comparable { final var bigUncertainty = BigDecimal.valueOf(this.uncertainty); final var displayScale = this.getDisplayScale(); - final var roundedUncertainty = bigUncertainty - .setScale(displayScale, roundingMode); - final var roundedValue = bigValue.setScale(displayScale, + final var roundedUncertainty = bigUncertainty.setScale(displayScale, roundingMode); + final var roundedValue = bigValue.setScale(displayScale, roundingMode); valueString = roundedValue.toString(); uncertaintyString = roundedUncertainty.toString(); diff --git a/src/main/java/sevenUnitsGUI/DefaultPrefixRepetitionRule.java b/src/main/java/sevenUnitsGUI/DefaultPrefixRepetitionRule.java index a441911..0e38c67 100644 --- a/src/main/java/sevenUnitsGUI/DefaultPrefixRepetitionRule.java +++ b/src/main/java/sevenUnitsGUI/DefaultPrefixRepetitionRule.java @@ -74,7 +74,8 @@ public enum DefaultPrefixRepetitionRule implements Predicate> { for (final UnitPrefix prefix : prefixes) { // check that the current prefix is metric and appropriately // magnifying/reducing - if (!Metric.DECIMAL_PREFIXES.contains(prefix) || (magnifying != prefix.getMultiplier() > 1)) + if (!Metric.DECIMAL_PREFIXES.contains(prefix) + || (magnifying != prefix.getMultiplier() > 1)) return false; // check if the current prefix is correct diff --git a/src/main/java/sevenUnitsGUI/Presenter.java b/src/main/java/sevenUnitsGUI/Presenter.java index 7fd979a..d258e1f 100644 --- a/src/main/java/sevenUnitsGUI/Presenter.java +++ b/src/main/java/sevenUnitsGUI/Presenter.java @@ -766,8 +766,7 @@ public final class Presenter { } } if (LOCAL_LOCALES.contains(this.userLocale)) { - final var filename = String.format("/about/%s.txt", - this.userLocale); + final var filename = String.format("/about/%s.txt", this.userLocale); return this.formatAboutText( Presenter.getLinesFromResource(filename).stream()); } diff --git a/src/main/java/sevenUnitsGUI/SearchBoxList.java b/src/main/java/sevenUnitsGUI/SearchBoxList.java index bddce04..96f71de 100644 --- a/src/main/java/sevenUnitsGUI/SearchBoxList.java +++ b/src/main/java/sevenUnitsGUI/SearchBoxList.java @@ -237,7 +237,7 @@ final class SearchBoxList extends JPanel { public void reapplyFilter() { final var searchText = this.searchBoxEmpty ? "" : this.searchBox.getText(); - final var comparator = new FilterComparator(searchText, + final var comparator = new FilterComparator<>(searchText, this.defaultOrdering, this.caseSensitive); final var searchFilter = this.getSearchFilter(searchText); @@ -300,7 +300,7 @@ final class SearchBoxList extends JPanel { } final var searchText = this.searchBoxEmpty ? "" : this.searchBox.getText(); - final var comparator = new FilterComparator(searchText, + final var comparator = new FilterComparator<>(searchText, this.defaultOrdering, this.caseSensitive); final var searchFilter = this.getSearchFilter(searchText); diff --git a/src/test/java/sevenUnits/unit/UnitTest.java b/src/test/java/sevenUnits/unit/UnitTest.java index 7ae550f..fb21723 100644 --- a/src/test/java/sevenUnits/unit/UnitTest.java +++ b/src/test/java/sevenUnits/unit/UnitTest.java @@ -60,10 +60,8 @@ class UnitTest { // test with LinearUnitValue final var value1 = LinearUnitValue.getExact(Metric.METRE, 15); final var value2 = LinearUnitValue.getExact(foot, 120); - final var value3 = LinearUnitValue.getExact(Metric.METRE, - 0.5); - final var value4 = LinearUnitValue.getExact(Metric.KILOGRAM, - 60); + final var value3 = LinearUnitValue.getExact(Metric.METRE, 0.5); + final var value4 = LinearUnitValue.getExact(Metric.KILOGRAM, 60); // make sure addition is done correctly assertEquals(51.576, value1.plus(value2).getValueExact(), 0.001); @@ -151,8 +149,7 @@ class UnitTest { @Test public void testPrefixes() { - final var generatedKilometre = Metric.METRE - .withPrefix(Metric.KILO); + final var generatedKilometre = Metric.METRE.withPrefix(Metric.KILO); final var actualKilometre = Metric.METRE.times(1000); assertEquals(generatedKilometre, actualKilometre); diff --git a/src/test/java/sevenUnits/utils/ConditionalExistenceCollectionsTest.java b/src/test/java/sevenUnits/utils/ConditionalExistenceCollectionsTest.java index f203fad..8711847 100644 --- a/src/test/java/sevenUnits/utils/ConditionalExistenceCollectionsTest.java +++ b/src/test/java/sevenUnits/utils/ConditionalExistenceCollectionsTest.java @@ -120,8 +120,7 @@ class ConditionalExistenceCollectionsTest { /** Test method for the ConditionalExistenceCollection's iterator. */ @Test void testIterator() { - final var testIterator = this - .getTestIterator(); + final var testIterator = this.getTestIterator(); assertTrue(testIterator.hasNext); assertTrue(testIterator.hasNext()); diff --git a/src/test/java/sevenUnits/utils/SemanticVersionTest.java b/src/test/java/sevenUnits/utils/SemanticVersionTest.java index 047f0b5..5b74812 100644 --- a/src/test/java/sevenUnits/utils/SemanticVersionTest.java +++ b/src/test/java/sevenUnits/utils/SemanticVersionTest.java @@ -72,14 +72,12 @@ public final class SemanticVersionTest { */ @Test public void testComplexToString() { - final var v1 = builder(1, 2, 3).preRelease(1, 2, 3) - .build(); + final var v1 = builder(1, 2, 3).preRelease(1, 2, 3).build(); assertEquals("1.2.3-1.2.3", v1.toString()); final var v2 = builder(4, 5, 6).preRelease("abc", 123) .buildMetadata("2022-02-19").build(); assertEquals("4.5.6-abc.123+2022-02-19", v2.toString()); - final var v3 = builder(1, 0, 0) - .preRelease("x-y-z", "--").build(); + final var v3 = builder(1, 0, 0).preRelease("x-y-z", "--").build(); assertEquals("1.0.0-x-y-z.--", v3.toString()); } @@ -91,8 +89,7 @@ public final class SemanticVersionTest { */ @Test public void testComplexVersions() { - final var v1 = builder(1, 2, 3).preRelease(1, 2, 3) - .build(); + final var v1 = builder(1, 2, 3).preRelease(1, 2, 3).build(); assertEquals(1, v1.majorVersion()); assertEquals(2, v1.minorVersion()); assertEquals(3, v1.patchVersion()); @@ -107,8 +104,7 @@ public final class SemanticVersionTest { assertEquals(List.of("abc", "123"), v2.preReleaseIdentifiers()); assertEquals(List.of("2022-02-19"), v2.buildMetadata()); - final var v3 = builder(1, 0, 0) - .preRelease("x-y-z", "--").build(); + final var v3 = builder(1, 0, 0).preRelease("x-y-z", "--").build(); assertEquals(1, v3.majorVersion()); assertEquals(0, v3.minorVersion()); assertEquals(0, v3.patchVersion()); @@ -298,13 +294,10 @@ public final class SemanticVersionTest { */ @Test public void testOrder() { - final var v100a = builder(1, 0, 0).preRelease("alpha") - .build(); // 1.0.0-alpha + final var v100a = builder(1, 0, 0).preRelease("alpha").build(); // 1.0.0-alpha final var v100a1 = preRelease(1, 0, 0, "alpha", 1); // 1.0.0-alpha.1 - final var v100ab = builder(1, 0, 0) - .preRelease("alpha", "beta").build(); // 1.0.0-alpha.beta - final var v100b = builder(1, 0, 0).preRelease("beta") - .build(); // 1.0.0-alpha + final var v100ab = builder(1, 0, 0).preRelease("alpha", "beta").build(); // 1.0.0-alpha.beta + final var v100b = builder(1, 0, 0).preRelease("beta").build(); // 1.0.0-alpha final var v100b2 = preRelease(1, 0, 0, "beta", 2); // 1.0.0-beta.2 final var v100b11 = preRelease(1, 0, 0, "beta", 11); // 1.0.0-beta.11 final var v100rc1 = preRelease(1, 0, 0, "rc", 1); // 1.0.0-rc.1 diff --git a/src/test/java/sevenUnits/utils/UncertainDoubleTest.java b/src/test/java/sevenUnits/utils/UncertainDoubleTest.java index 8dcd595..733a308 100644 --- a/src/test/java/sevenUnits/utils/UncertainDoubleTest.java +++ b/src/test/java/sevenUnits/utils/UncertainDoubleTest.java @@ -49,15 +49,12 @@ class UncertainDoubleTest { final var x = UncertainDouble.of(Math.PI, 0.1); // slightly different because roundoff errors - final var x1 = UncertainDouble.of(Math.PI + Math.E - Math.E, - 0.1); - final var x2 = UncertainDouble.of(Math.PI * Math.E / Math.E, - 0.1); + final var x1 = UncertainDouble.of(Math.PI + Math.E - Math.E, 0.1); + final var x2 = UncertainDouble.of(Math.PI * Math.E / Math.E, 0.1); // get results final var result1 = x.plusExact(Math.E).minusExact(Math.E); - final var result2 = x.timesExact(Math.E) - .dividedByExact(Math.E); + final var result2 = x.timesExact(Math.E).dividedByExact(Math.E); // test that these operations work & don't change uncertainty assertEquals(x1, result1); -- cgit v1.2.3