summaryrefslogtreecommitdiff
path: root/src/org/unitConverter/unit/Unit.java
diff options
context:
space:
mode:
authorAdrien Hopkins <masterofnumbers17@gmail.com>2019-10-21 21:41:26 -0400
committerAdrien Hopkins <masterofnumbers17@gmail.com>2019-10-21 21:41:26 -0400
commit8ec94bea790cc010c29cd8de86e47117ff331979 (patch)
tree6a544d2d0c672cf9cdf2650319f3dff2f33cd8f0 /src/org/unitConverter/unit/Unit.java
parent3c23fd15b88396868101457256173c0c2c29df5c (diff)
Added new ways to create named units.
Diffstat (limited to 'src/org/unitConverter/unit/Unit.java')
-rw-r--r--src/org/unitConverter/unit/Unit.java13
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."));
+ }
}