diff options
author | Adrien Hopkins <ahopk127@my.yorku.ca> | 2022-04-19 16:10:44 -0500 |
---|---|---|
committer | Adrien Hopkins <ahopk127@my.yorku.ca> | 2022-04-19 16:10:44 -0500 |
commit | 0aacba9fc8a9140fdf331172ad66afe280d09b5e (patch) | |
tree | 3699f6cf4ce40db818233287853474a4cf99ba5c /src/main/java/sevenUnits/utils/NameSymbol.java | |
parent | 40f7b6e806140fc2fc741c63c71f5ce97b4bd1d2 (diff) |
Implemented prefix settings, saving & loading of settings
Also fixed some bugs:
- Presenter now has default values for its settings in case they don't load properly
- UnitDatabase ensures its units, prefixes and dimensions have all of the names
you give it
Diffstat (limited to 'src/main/java/sevenUnits/utils/NameSymbol.java')
-rw-r--r-- | src/main/java/sevenUnits/utils/NameSymbol.java | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/main/java/sevenUnits/utils/NameSymbol.java b/src/main/java/sevenUnits/utils/NameSymbol.java index 955f980..7ef2967 100644 --- a/src/main/java/sevenUnits/utils/NameSymbol.java +++ b/src/main/java/sevenUnits/utils/NameSymbol.java @@ -288,4 +288,21 @@ public final class NameSymbol { else return this.primaryName.orElseGet(this.symbol::orElseThrow); } + + /** + * Creates and returns a copy of this {@code NameSymbol} with the provided + * extra name. If this {@code NameSymbol} has a primary name, the provided + * name will become an other name, otherwise it will become the primary name. + * + * @since 2022-04-19 + */ + public final NameSymbol withExtraName(String name) { + if (this.primaryName.isPresent()) { + final var otherNames = new HashSet<>(this.otherNames); + otherNames.add(name); + return NameSymbol.ofNullable(this.primaryName.orElse(null), + this.symbol.orElse(null), otherNames); + } else + return NameSymbol.ofNullable(name, this.symbol.orElse(null)); + } }
\ No newline at end of file |