summaryrefslogtreecommitdiff
path: root/src/unitConverter/UnitsDatabase.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/unitConverter/UnitsDatabase.java')
-rwxr-xr-xsrc/unitConverter/UnitsDatabase.java69
1 files changed, 63 insertions, 6 deletions
diff --git a/src/unitConverter/UnitsDatabase.java b/src/unitConverter/UnitsDatabase.java
index 4816db1..9f5a6a2 100755
--- a/src/unitConverter/UnitsDatabase.java
+++ b/src/unitConverter/UnitsDatabase.java
@@ -37,7 +37,7 @@ import unitConverter.unit.Unit;
import unitConverter.unit.UnitPrefix;
/**
- * A database of units.
+ * A database of units and prefixes, and their names.
*
* @author Adrien Hopkins
* @since 2019-01-07
@@ -61,6 +61,13 @@ public final class UnitsDatabase {
private final Map<String, UnitPrefix> prefixes;
/**
+ * The dimensions in this system.
+ *
+ * @since 2019-03-14
+ */
+ private final Map<String, UnitDimension> dimensions;
+
+ /**
* Creates the {@code UnitsDatabase}.
*
* @since 2019-01-10
@@ -69,6 +76,7 @@ public final class UnitsDatabase {
public UnitsDatabase() {
this.units = new HashMap<>();
this.prefixes = new HashMap<>();
+ this.dimensions = new HashMap<>();
}
/**
@@ -164,14 +172,30 @@ public final class UnitsDatabase {
}
/**
- * Adds a unit prefix to the database using a custom name
+ * Adds a unit dimension to the database.
+ *
+ * @param name
+ * dimension's name
+ * @param dimension
+ * dimension to add
+ * @throws NullPointerException
+ * if name or dimension is null
+ * @since 2019-03-14
+ */
+ public void addDimension(final String name, final UnitDimension dimension) {
+ this.dimensions.put(Objects.requireNonNull(name, "name must not be null."),
+ Objects.requireNonNull(dimension, "dimension must not be null."));
+ }
+
+ /**
+ * Adds a unit prefix to the database.
*
* @param name
* prefix's name
* @param prefix
* prefix to add
* @throws NullPointerException
- * if name or unit is null
+ * if name or prefix is null
* @since 2019-01-14
* @since v0.1.0
*/
@@ -181,7 +205,7 @@ public final class UnitsDatabase {
}
/**
- * Adds a unit to the database using a custom name
+ * Adds a unit to the database.
*
* @param name
* unit's name
@@ -193,7 +217,20 @@ public final class UnitsDatabase {
* @since v0.1.0
*/
public void addUnit(final String name, final Unit unit) {
- this.units.put(name, Objects.requireNonNull(unit, "unit must not be null."));
+ this.units.put(Objects.requireNonNull(name, "name must not be null."),
+ Objects.requireNonNull(unit, "unit must not be null."));
+ }
+
+ /**
+ * Tests if the database has a unit dimension with this name.
+ *
+ * @param name
+ * name to test
+ * @return if database contains name
+ * @since 2019-03-14
+ */
+ public boolean containsDimensionName(final String name) {
+ return this.dimensions.containsKey(name);
}
/**
@@ -210,7 +247,7 @@ public final class UnitsDatabase {
}
/**
- * Tests if the database has a unit prefix with this name
+ * Tests if the database has a unit prefix with this name.
*
* @param name
* name to test
@@ -242,6 +279,26 @@ public final class UnitsDatabase {
}
/**
+ * @return an immutable set of all of the dimension names in this database.
+ * @since 2019-03-14
+ */
+ public Set<String> dimensionNameSet() {
+ return Collections.unmodifiableSet(this.dimensions.keySet());
+ }
+
+ /**
+ * Gets a unit dimension from the database using its name.
+ *
+ * @param name
+ * dimension's name
+ * @return dimension
+ * @since 2019-03-14
+ */
+ public UnitDimension getDimension(final String name) {
+ return this.dimensions.get(name);
+ }
+
+ /**
* Gets a unit prefix from the database from its name
*
* @param name