diff options
Diffstat (limited to 'src/main/java/sevenUnitsGUI/DefaultPrefixRepetitionRule.java')
-rw-r--r-- | src/main/java/sevenUnitsGUI/DefaultPrefixRepetitionRule.java | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/src/main/java/sevenUnitsGUI/DefaultPrefixRepetitionRule.java b/src/main/java/sevenUnitsGUI/DefaultPrefixRepetitionRule.java index 1fb2709..0e38c67 100644 --- a/src/main/java/sevenUnitsGUI/DefaultPrefixRepetitionRule.java +++ b/src/main/java/sevenUnitsGUI/DefaultPrefixRepetitionRule.java @@ -1,5 +1,18 @@ /** - * @since 2020-08-26 + * Copyright (C) 2020, 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package sevenUnitsGUI; @@ -13,14 +26,17 @@ import sevenUnits.unit.UnitPrefix; * A rule that specifies whether prefix repetition is allowed * * @since 2020-08-26 + * @since v0.3.0 */ public enum DefaultPrefixRepetitionRule implements Predicate<List<UnitPrefix>> { + /** Prefix repetition is never allowed; only one prefix may be used. */ NO_REPETITION { @Override public boolean test(List<UnitPrefix> prefixes) { return prefixes.size() <= 1; } }, + /** Prefix repetition is always allowed, without restrictions. */ NO_RESTRICTION { @Override public boolean test(List<UnitPrefix> prefixes) { @@ -40,7 +56,7 @@ public enum DefaultPrefixRepetitionRule implements Predicate<List<UnitPrefix>> { final boolean magnifying; if (prefixes.isEmpty()) return true; - else if (prefixes.get(0).getMultiplier() > 1) { + if (prefixes.get(0).getMultiplier() > 1) { magnifying = true; } else { magnifying = false; @@ -52,15 +68,14 @@ public enum DefaultPrefixRepetitionRule implements Predicate<List<UnitPrefix>> { if (!Metric.DECIMAL_PREFIXES.contains(prefixes.get(0))) return NO_REPETITION.test(prefixes); - int part = 0; // 0=yotta/yoctos, 1=kilo-zetta/milli-zepto, + var part = 0; // 0=yotta/yoctos, 1=kilo-zetta/milli-zepto, // 2=deka,hecto,deci,centi for (final UnitPrefix prefix : prefixes) { // check that the current prefix is metric and appropriately // magnifying/reducing - if (!Metric.DECIMAL_PREFIXES.contains(prefix)) - return false; - if (magnifying != prefix.getMultiplier() > 1) + if (!Metric.DECIMAL_PREFIXES.contains(prefix) + || (magnifying != prefix.getMultiplier() > 1)) return false; // check if the current prefix is correct |