From 8ec94bea790cc010c29cd8de86e47117ff331979 Mon Sep 17 00:00:00 2001 From: Adrien Hopkins Date: Mon, 21 Oct 2019 21:41:26 -0400 Subject: Added new ways to create named units. --- src/org/unitConverter/unit/Unit.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/org/unitConverter/unit/Unit.java') 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.")); + } } -- cgit v1.2.3