summaryrefslogtreecommitdiff
path: root/src/main/java/sevenUnitsGUI/StandardDisplayRules.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/sevenUnitsGUI/StandardDisplayRules.java')
-rw-r--r--src/main/java/sevenUnitsGUI/StandardDisplayRules.java48
1 files changed, 25 insertions, 23 deletions
diff --git a/src/main/java/sevenUnitsGUI/StandardDisplayRules.java b/src/main/java/sevenUnitsGUI/StandardDisplayRules.java
index d00263b..16d31ae 100644
--- a/src/main/java/sevenUnitsGUI/StandardDisplayRules.java
+++ b/src/main/java/sevenUnitsGUI/StandardDisplayRules.java
@@ -1,5 +1,5 @@
/**
- * Copyright (C) 2022 Adrien Hopkins
+ * Copyright (C) 2022, 2024, 2025 Adrien Hopkins
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@@ -28,28 +28,28 @@ import sevenUnits.utils.UncertainDouble;
* A static utility class that can be used to make display rules for the
* presenter.
*
- * @since v0.4.0
* @since 2022-04-18
+ * @since v0.4.0
*/
public final class StandardDisplayRules {
/**
* A rule that rounds to a fixed number of decimal places.
*
- * @since v0.4.0
* @since 2022-04-18
+ * @since v0.4.0
*/
public static final class FixedDecimals
implements Function<UncertainDouble, String> {
+ /** Regular expression used for converting this to a string. */
public static final Pattern TO_STRING_PATTERN = Pattern
.compile("Round to (\\d+) decimal places");
- /**
- * The number of places to round to.
- */
+ /** The number of places to round to. */
private final int decimalPlaces;
/**
* @param decimalPlaces
* @since 2022-04-18
+ * @since v0.4.0
*/
private FixedDecimals(int decimalPlaces) {
this.decimalPlaces = decimalPlaces;
@@ -65,6 +65,7 @@ public final class StandardDisplayRules {
/**
* @return the number of decimal places this rule rounds to
* @since 2022-04-18
+ * @since v0.4.0
*/
public int decimalPlaces() {
return this.decimalPlaces;
@@ -76,7 +77,7 @@ public final class StandardDisplayRules {
return true;
if (!(obj instanceof FixedDecimals))
return false;
- final FixedDecimals other = (FixedDecimals) obj;
+ final var other = (FixedDecimals) obj;
if (this.decimalPlaces != other.decimalPlaces)
return false;
return true;
@@ -96,22 +97,22 @@ public final class StandardDisplayRules {
/**
* A rule that rounds to a fixed number of significant digits.
*
- * @since v0.4.0
* @since 2022-04-18
+ * @since v0.4.0
*/
public static final class FixedPrecision
implements Function<UncertainDouble, String> {
+ /** Regular expression used for converting this to a string. */
public static final Pattern TO_STRING_PATTERN = Pattern
.compile("Round to (\\d+) significant figures");
- /**
- * The number of significant figures to round to.
- */
+ /** The number of significant figures to round to. */
private final MathContext mathContext;
/**
* @param significantFigures
* @since 2022-04-18
+ * @since v0.4.0
*/
private FixedPrecision(int significantFigures) {
this.mathContext = new MathContext(significantFigures,
@@ -130,7 +131,7 @@ public final class StandardDisplayRules {
return true;
if (!(obj instanceof FixedPrecision))
return false;
- final FixedPrecision other = (FixedPrecision) obj;
+ final var other = (FixedPrecision) obj;
if (this.mathContext == null) {
if (other.mathContext != null)
return false;
@@ -148,6 +149,7 @@ public final class StandardDisplayRules {
/**
* @return the number of significant figures this rule rounds to
* @since 2022-04-18
+ * @since v0.4.0
*/
public int significantFigures() {
return this.mathContext.getPrecision();
@@ -165,8 +167,8 @@ public final class StandardDisplayRules {
* This means the output will have around as many significant figures as the
* input.
*
- * @since v0.4.0
* @since 2022-04-18
+ * @since v0.4.0
*/
public static final class UncertaintyBased
implements Function<UncertainDouble, String> {
@@ -193,10 +195,10 @@ public final class StandardDisplayRules {
/**
* @param decimalPlaces decimal places to round to
* @return a rounding rule that rounds to fixed number of decimal places
- * @since v0.4.0
* @since 2022-04-18
+ * @since v0.4.0
*/
- public static final FixedDecimals fixedDecimals(int decimalPlaces) {
+ public static FixedDecimals fixedDecimals(int decimalPlaces) {
return new FixedDecimals(decimalPlaces);
}
@@ -204,10 +206,10 @@ public final class StandardDisplayRules {
* @param significantFigures significant figures to round to
* @return a rounding rule that rounds to a fixed number of significant
* figures
- * @since v0.4.0
* @since 2022-04-18
+ * @since v0.4.0
*/
- public static final FixedPrecision fixedPrecision(int significantFigures) {
+ public static FixedPrecision fixedPrecision(int significantFigures) {
return new FixedPrecision(significantFigures);
}
@@ -218,10 +220,10 @@ public final class StandardDisplayRules {
* @return display rule
* @throws IllegalArgumentException if the provided string is not that of a
* standard rule.
- * @since v0.4.0
* @since 2021-12-24
+ * @since v0.4.0
*/
- public static final Function<UncertainDouble, String> getStandardRule(
+ public static Function<UncertainDouble, String> getStandardRule(
String ruleToString) {
if (UNCERTAINTY_BASED_ROUNDING_RULE.toString().equals(ruleToString))
return UNCERTAINTY_BASED_ROUNDING_RULE;
@@ -230,13 +232,13 @@ public final class StandardDisplayRules {
final var placesMatch = FixedDecimals.TO_STRING_PATTERN
.matcher(ruleToString);
if (placesMatch.matches())
- return new FixedDecimals(Integer.valueOf(placesMatch.group(1)));
+ return new FixedDecimals(Integer.parseInt(placesMatch.group(1)));
// test if it is a fixed-sig-fig rule
final var sigFigMatch = FixedPrecision.TO_STRING_PATTERN
.matcher(ruleToString);
if (sigFigMatch.matches())
- return new FixedPrecision(Integer.valueOf(sigFigMatch.group(1)));
+ return new FixedPrecision(Integer.parseInt(sigFigMatch.group(1)));
throw new IllegalArgumentException(
"Provided string does not match any given rules.");
@@ -244,10 +246,10 @@ public final class StandardDisplayRules {
/**
* @return an UncertainDouble-based rounding rule
- * @since v0.4.0
* @since 2022-04-18
+ * @since v0.4.0
*/
- public static final UncertaintyBased uncertaintyBased() {
+ public static UncertaintyBased uncertaintyBased() {
return UNCERTAINTY_BASED_ROUNDING_RULE;
}