summaryrefslogtreecommitdiff
path: root/src/main/java/sevenUnits/unit
diff options
context:
space:
mode:
authorAdrien Hopkins <ahopk127@my.yorku.ca>2021-10-07 16:21:00 -0500
committerAdrien Hopkins <ahopk127@my.yorku.ca>2021-10-07 16:21:00 -0500
commitb4fd2b39e85e2a086e65555ad7c45244bec8ae37 (patch)
treea49542fe896f56b02d73a42b9c458d4df5d3f90b /src/main/java/sevenUnits/unit
parentb59082c6b558705d4bd5effce2ae4b98c8a3ebe5 (diff)
Added tests for getUnit and the prefixed unit map
Also fixed a bug where a prefixed unit map with units but no prefixes would appear empty
Diffstat (limited to 'src/main/java/sevenUnits/unit')
-rw-r--r--src/main/java/sevenUnits/unit/UnitDatabase.java12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/main/java/sevenUnits/unit/UnitDatabase.java b/src/main/java/sevenUnits/unit/UnitDatabase.java
index 7c72570..d3c65b2 100644
--- a/src/main/java/sevenUnits/unit/UnitDatabase.java
+++ b/src/main/java/sevenUnits/unit/UnitDatabase.java
@@ -243,7 +243,8 @@ public final class UnitDatabase {
return false;
else {
if (this.prefixNames.isEmpty())
- return this.unitNamePosition >= this.unitNames.size() - 1;
+ return this.prefixCoordinates.isEmpty()
+ && this.unitNamePosition < this.unitNames.size();
else
return true;
}
@@ -557,7 +558,8 @@ public final class UnitDatabase {
return false;
else {
if (this.prefixNames.isEmpty())
- return this.unitNamePosition >= this.unitNames.size() - 1;
+ return this.prefixCoordinates.isEmpty()
+ && this.unitNamePosition < this.unitNames.size();
else
return true;
}
@@ -1038,7 +1040,7 @@ public final class UnitDatabase {
@Override
public String toString() {
if (this.units.isEmpty() || this.prefixes.isEmpty())
- return super.toString();
+ return new HashMap<>(this).toString();
else
return String.format(
"Infinite map of name-unit entries created from units %s and prefixes %s",
@@ -1645,7 +1647,7 @@ public final class UnitDatabase {
* @since 2019-03-22
* @since v0.2.0
*/
- private LinearUnit getLinearUnit(final String name) {
+ LinearUnit getLinearUnit(final String name) {
// see if I am using a function-unit like tempC(100)
Objects.requireNonNull(name, "name may not be null");
if (name.contains("(") && name.contains(")")) {
@@ -1680,7 +1682,7 @@ public final class UnitDatabase {
* @return {@code LinearUnitValue} instance
* @since 2020-08-04
*/
- private LinearUnitValue getLinearUnitValue(final String name) {
+ LinearUnitValue getLinearUnitValue(final String name) {
try {
// try to parse it as a number - otherwise it is not a number!
final BigDecimal number = new BigDecimal(name);