diff options
Diffstat (limited to 'src/org/unitConverter/unit/Unit.java')
-rw-r--r-- | src/org/unitConverter/unit/Unit.java | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/org/unitConverter/unit/Unit.java b/src/org/unitConverter/unit/Unit.java index d65e14f..d848ea1 100644 --- a/src/org/unitConverter/unit/Unit.java +++ b/src/org/unitConverter/unit/Unit.java @@ -513,4 +513,17 @@ public abstract class Unit { + (this.getSymbol().isPresent() ? String.format(" (%s)", this.getSymbol().get()) : "") + ", derived from " + this.getBase().toString(); } + + /** + * @param ns + * name(s) and symbol to use + * @return a copy of this unit with provided name(s) and symbol + * @since 2019-10-21 + * @throws NullPointerException + * if ns is null + */ + public Unit withName(final NameSymbol ns) { + return fromConversionFunctions(this.getBase(), this::convertFromBase, this::convertToBase, + Objects.requireNonNull(ns, "ns must not be null.")); + } } |