From b20cd4223b4ffc03e334627a82ca4eff9738912c Mon Sep 17 00:00:00 2001 From: Adrien Hopkins Date: Sat, 16 Mar 2019 14:55:07 -0400 Subject: Moved project to Maven. --- pom.xml | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 pom.xml (limited to 'pom.xml') diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..3aede3b --- /dev/null +++ b/pom.xml @@ -0,0 +1,37 @@ + + 4.0.0 + org.unitConverter + unitConverter + 0.1.0 + Unit Converter + A Java unit converter inspired by GNU Units + + src + + + maven-compiler-plugin + 3.8.0 + + 1.8 + 1.8 + + + + org.codehaus.mojo + exec-maven-plugin + + org.unitConverter.converterGUI.UnitConverterGUI + + + + + + + junit + junit + 4.11 + + + \ No newline at end of file -- cgit v1.2.3 From 5f06f688ee0de31125682a9a0b1d05b4b5edf66c Mon Sep 17 00:00:00 2001 From: Adrien Hopkins Date: Sat, 16 Mar 2019 15:09:07 -0400 Subject: Updated changelog and fixed tests. --- CHANGELOG.org | 3 +++ pom.xml | 7 +++++++ 2 files changed, 10 insertions(+) (limited to 'pom.xml') diff --git a/CHANGELOG.org b/CHANGELOG.org index 280ceb3..b9c87c9 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -2,6 +2,9 @@ All notable changes in this project will be shown in this file. ** Unreleased +*** Changed + - Moved project to Maven + - Downgraded JUnit to 4.11 *** Added - GUI for a selection-based unit converter - The UnitDatabase now stores dimensions. diff --git a/pom.xml b/pom.xml index 3aede3b..8b3bc0d 100644 --- a/pom.xml +++ b/pom.xml @@ -18,6 +18,13 @@ 1.8 + + org.apache.maven.plugins + maven-surefire-plugin + + false + + org.codehaus.mojo exec-maven-plugin -- cgit v1.2.3 From 77051c4f70f450a4363be7ae587de36efc1fdd54 Mon Sep 17 00:00:00 2001 From: Adrien Hopkins Date: Sun, 14 Apr 2019 07:57:38 -0400 Subject: Added more units and dimensions to the converter. --- .DS_Store | Bin 0 -> 6148 bytes .classpath | 1 - dimensionfile.txt | 5 ++- pom.xml | 15 ++++++- .../converterGUI/FilterComparator.java | 18 +++++--- .../converterGUI/UnitConverterGUI.java | 50 ++++++++++++--------- unitsfile.txt | 13 ++++++ 7 files changed, 70 insertions(+), 32 deletions(-) create mode 100644 .DS_Store (limited to 'pom.xml') diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..5f8c120 Binary files /dev/null and b/.DS_Store differ diff --git a/.classpath b/.classpath index 72d7394..ef141e6 100644 --- a/.classpath +++ b/.classpath @@ -7,7 +7,6 @@ - diff --git a/dimensionfile.txt b/dimensionfile.txt index 7a1da10..3485de5 100644 --- a/dimensionfile.txt +++ b/dimensionfile.txt @@ -4,14 +4,15 @@ # ! means "look for an existing dimension which I will load at the start" # This is necessary because every dimension must be defined by others, and I need somewhere to start. -# I have excluded electric current and quantity since their units are exclusively SI. +# I have excluded electric current, quantity and luminous intensity since their units are exclusively SI. LENGTH ! MASS ! TIME ! TEMPERATURE ! -LUMINOUS_INTENSITY ! # Derived Dimensions +AREA LENGTH^2 +VOLUME LENGTH^3 VELOCITY LENGTH / TIME ENERGY MASS * VELOCITY^2 \ No newline at end of file diff --git a/pom.xml b/pom.xml index 8b3bc0d..5b3e468 100644 --- a/pom.xml +++ b/pom.xml @@ -31,7 +31,18 @@ org.unitConverter.converterGUI.UnitConverterGUI - + + + org.apache.maven.plugins + maven-jar-plugin + + + + org.unitConverter.converterGUI.UnitConverterGUI + + + + @@ -41,4 +52,4 @@ 4.11 - \ No newline at end of file + diff --git a/src/org/unitConverter/converterGUI/FilterComparator.java b/src/org/unitConverter/converterGUI/FilterComparator.java index bebc2df..ad8d0b0 100755 --- a/src/org/unitConverter/converterGUI/FilterComparator.java +++ b/src/org/unitConverter/converterGUI/FilterComparator.java @@ -20,7 +20,7 @@ import java.util.Comparator; import java.util.Objects; /** - * A comparator that compares strings using a filter. + * A comparator that compares strings using a filter. It is case-insensitive * * @author Adrien Hopkins * @since 2019-01-15 @@ -72,22 +72,26 @@ public final class FilterComparator implements Comparator { @Override public int compare(final String arg0, final String arg1) { + // this is case insensitive, so make them lowercase + final String arg0lower = arg0.toLowerCase(); + final String arg1lower = arg1.toLowerCase(); + // elements that start with the filter always go first - if (arg0.startsWith(this.filter) && !arg1.startsWith(this.filter)) + if (arg0lower.startsWith(this.filter) && !arg1lower.startsWith(this.filter)) return -1; - else if (!arg0.startsWith(this.filter) && arg1.startsWith(this.filter)) + else if (!arg0lower.startsWith(this.filter) && arg1lower.startsWith(this.filter)) return 1; // elements that contain the filter but don't start with them go next - if (arg0.contains(this.filter) && !arg1.contains(this.filter)) + if (arg0lower.contains(this.filter) && !arg1lower.contains(this.filter)) return -1; - else if (!arg0.contains(this.filter) && !arg1.contains(this.filter)) + else if (!arg0lower.contains(this.filter) && !arg1lower.contains(this.filter)) return 1; // other elements go last if (this.comparator == null) - return arg0.compareTo(arg1); + return arg0lower.compareTo(arg1lower); else - return this.comparator.compare(arg0, arg1); + return this.comparator.compare(arg0lower, arg1lower); } } diff --git a/src/org/unitConverter/converterGUI/UnitConverterGUI.java b/src/org/unitConverter/converterGUI/UnitConverterGUI.java index 49a40d6..34cbef9 100755 --- a/src/org/unitConverter/converterGUI/UnitConverterGUI.java +++ b/src/org/unitConverter/converterGUI/UnitConverterGUI.java @@ -62,6 +62,35 @@ import org.unitConverter.unit.UnitPrefix; */ final class UnitConverterGUI { private static class Presenter { + /** + * Adds default units and dimensions to a database. + * + * @param database + * database to add to + * @since 2019-04-14 + */ + private static void addDefaults(final UnitsDatabase database) { + database.addUnit("metre", SI.METRE); + database.addUnit("kilogram", SI.KILOGRAM); + database.addUnit("gram", SI.KILOGRAM.dividedBy(1000)); + database.addUnit("second", SI.SECOND); + database.addUnit("ampere", SI.AMPERE); + database.addUnit("kelvin", SI.KELVIN); + database.addUnit("mole", SI.MOLE); + database.addUnit("candela", SI.CANDELA); + database.addUnit("bit", SI.SI.getBaseUnit(StandardDimensions.INFORMATION)); + database.addUnit("unit", SI.SI.getBaseUnit(UnitDimension.EMPTY)); + // nonlinear units - must be loaded manually + database.addUnit("tempCelsius", NonlinearUnits.CELSIUS); + database.addUnit("tempFahrenheit", NonlinearUnits.FAHRENHEIT); + + // load initial dimensions + database.addDimension("LENGTH", StandardDimensions.LENGTH); + database.addDimension("MASS", StandardDimensions.MASS); + database.addDimension("TIME", StandardDimensions.TIME); + database.addDimension("TEMPERATURE", StandardDimensions.TEMPERATURE); + } + /** The presenter's associated view. */ private final View view; @@ -100,26 +129,7 @@ final class UnitConverterGUI { // load initial units this.units = new UnitsDatabase(); - this.units.addUnit("metre", SI.METRE); - this.units.addUnit("kilogram", SI.KILOGRAM); - this.units.addUnit("gram", SI.KILOGRAM.dividedBy(1000)); - this.units.addUnit("second", SI.SECOND); - this.units.addUnit("ampere", SI.AMPERE); - this.units.addUnit("kelvin", SI.KELVIN); - this.units.addUnit("mole", SI.MOLE); - this.units.addUnit("candela", SI.CANDELA); - this.units.addUnit("bit", SI.SI.getBaseUnit(StandardDimensions.INFORMATION)); - this.units.addUnit("unit", SI.SI.getBaseUnit(UnitDimension.EMPTY)); - // nonlinear units - must be loaded manually - this.units.addUnit("tempCelsius", NonlinearUnits.CELSIUS); - this.units.addUnit("tempFahrenheit", NonlinearUnits.FAHRENHEIT); - - // load initial dimensions - this.units.addDimension("LENGTH", StandardDimensions.LENGTH); - this.units.addDimension("MASS", StandardDimensions.MASS); - this.units.addDimension("TIME", StandardDimensions.TIME); - this.units.addDimension("TEMPERATURE", StandardDimensions.TEMPERATURE); - this.units.addDimension("LUMINOUS_INTENSITY", StandardDimensions.LUMINOUS_INTENSITY); + Presenter.addDefaults(this.units); this.units.loadUnitsFile(new File("unitsfile.txt")); this.units.loadDimensionFile(new File("dimensionfile.txt")); diff --git a/unitsfile.txt b/unitsfile.txt index 78f8117..553fd5e 100755 --- a/unitsfile.txt +++ b/unitsfile.txt @@ -124,6 +124,9 @@ T tesla hertz s^-1 Hz hertz +gram millikg +g gram + # Angle units and constants # Tau is the circle constant, equal to a circle's diameter divided by its radius @@ -243,8 +246,18 @@ calorie 4.18 J cal calorie Calorie kilocalorie Cal Calorie +Wh W h # Extra units to only include in the dimension-based converter +km km +cm cm +mm mm +mg mg +mL mL +ml ml +kJ kJ +MJ MJ +kWh kWh m/s m / s km/h km / h ft/s foot / s -- cgit v1.2.3