package org.djunits.generator; import java.util.Arrays; import java.util.Comparator; import java.util.TreeMap; import org.djunits.unit.AreaUnit; import org.djunits.unit.Unit; import org.djunits.unit.quantity.Quantities; import org.djunits.unit.quantity.Quantity; import org.djunits.unit.unitsystem.UnitSystem; import org.djunits.unit.util.UNITS; /** * Generator for the locale properties file. *
* @author Peter Knoppers
*/
public class GenerateUSLocale
{
/**
* Determine if a double is (very near to) a power of 10.
* @param value double; the value to test
* @return boolean; true if value
is (very near to) a power of 10; false otherwise
*/
static boolean isPowerOf10(final double value)
{
double log = Math.log10(value);
double rintLog = Math.rint(log);
boolean result = Math.abs(rintLog - log) < 0.000001;
// System.out.println("value " + value + " is power of 10? " + result);
return result;
}
/**
* Compare two double values.
* @param left double; the left value
* @param right double; the right value
* @return int; 0 if the values are equal; -1 if left should be sorted before right; +1 if right should be sorted before
* left
*/
static int compareDoubles(final double left, final double right)
{
if (left > right)
{
return -1;
}
else if (left < right)
{
return 1;
}
return 0;
}
/**
* Indicate if a unit is SI.
* @param unit Unit<?>; the unit
* @return boolean; true if the unit is SI; false otherwise
*/
static boolean isSI(final Unit> unit)
{
return unit.getUnitSystem().equals(UnitSystem.SI_ACCEPTED) || unit.getUnitSystem().equals(UnitSystem.SI_BASE)
|| unit.getUnitSystem().equals(UnitSystem.SI_DERIVED);
}
/**
* Generate the localeunit.properties file.
* @param args String[]; the command line arguments; not used (yet)
*/
public static void main(final String[] args)
{
@SuppressWarnings("unused")
AreaUnit junk = UNITS.ACRE; // force loading of all units
System.out.println("# Format:");
System.out.println("# UnitType.unitname = abbreviation | description");
System.out.println("# UnitType.unitname = abbreviation | description | text_abbreviation1 | text_abbreviation2 | ...");
TreeMap