Skip to content

Commit

Permalink
CLDR 16668 Revise order of units
Browse files Browse the repository at this point in the history
  • Loading branch information
macchiati committed May 8, 2024
1 parent 280cead commit 866a0aa
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 321 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package org.unicode.cldr.tool;

import com.google.common.base.Joiner;
import com.ibm.icu.impl.Row;
import com.ibm.icu.impl.Row.R4;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.EnumSet;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeSet;
import org.unicode.cldr.util.CldrUtility;
import org.unicode.cldr.util.MapComparator;
import org.unicode.cldr.util.Rational;
import org.unicode.cldr.util.Rational.FormatStyle;
import org.unicode.cldr.util.UnitConverter;
Expand Down Expand Up @@ -111,35 +110,15 @@ public void writeContents(FormattedFileWriter pw) throws IOException {
UnitConverter converter = SDI.getUnitConverter();
converter.getSourceToSystems();

Set<R4<UnitId, UnitSystem, Rational, String>> all = new TreeSet<>();
Set<R4<UnitId, UnitSystem, Rational, Integer>> all = new TreeSet<>();
MapComparator<String> shortIdUnicodeComparator = converter.getShortUnitIdComparator();

for (Entry<String, TargetInfo> entry : converter.getInternalConversionData().entrySet()) {
String sourceUnit = entry.getKey();
String quantity = converter.getQuantityFromUnit(sourceUnit, false);
TargetInfo targetInfo = entry.getValue();

final EnumSet<UnitSystem> systems =
EnumSet.copyOf(converter.getSystemsEnum(sourceUnit));

// to sort the right items together items together, put together a sort key
UnitSystem sortingSystem = systems.iterator().next();
switch (sortingSystem) {
case si:
case si_acceptable:
sortingSystem = UnitSystem.metric;
break;
case uksystem:
sortingSystem = UnitSystem.ussystem;
break;
default:
}
UnitId targetUnitId = converter.createUnitId(targetInfo.target);
R4<UnitId, UnitSystem, Rational, String> sortKey =
Row.of(targetUnitId, sortingSystem, targetInfo.unitInfo.factor, sourceUnit);
all.add(sortKey);

// get some formatted strings
// TODO: handle specials here, CLDR-16329 additional PR or follow-on ticket
final Set<UnitSystem> systems = converter.getSystemsEnum(sourceUnit);

final String repeatingFactor =
targetInfo.unitInfo.factor.toString(FormatStyle.repeating);
Expand All @@ -159,7 +138,7 @@ public void writeContents(FormattedFileWriter pw) throws IOException {

tablePrinter
.addRow()
.addCell(sortKey)
.addCell(shortIdUnicodeComparator.getOrdering(sourceUnit))
.addCell(quantity)
.addCell(targetDisplay)
.addCell(Joiner.on(", ").join(systems))
Expand Down
256 changes: 6 additions & 250 deletions tools/cldr-code/src/main/java/org/unicode/cldr/util/DtdData.java
Original file line number Diff line number Diff line change
Expand Up @@ -1617,260 +1617,16 @@ public AttributeStatus getAttributeStatus(String elementName, String attributeNa
// in sync.

public static MapComparator<String> getUnitOrder() {
return UnitOrderHolder.INSTANCE;
return UnitOrderHolder.getInstance();
}

private static final class UnitOrderHolder {
private static final MapComparator<String> INSTANCE =
// new MapComparator<String>()
//
// .add(Validity.getInstance().getCodeToStatus(LstrType.unit).keySet())
// .freeze();
// }
new MapComparator<>(
Arrays.asList(
"acceleration-g-force",
"acceleration-meter-per-square-second",
"acceleration-meter-per-second-squared", // deprecated
"angle-revolution",
"angle-radian",
"angle-degree",
"angle-arc-minute",
"angle-arc-second",
"area-square-kilometer",
"area-hectare",
"area-square-meter",
"area-square-centimeter",
"area-square-mile",
"area-acre",
"area-square-yard",
"area-square-foot",
"area-square-inch",
"area-dunam",
"concentr-karat",
"proportion-karat", // deprecated
"concentr-milligram-ofglucose-per-deciliter",
"concentr-milligram-per-deciliter",
"concentr-millimole-per-liter",
"concentr-item",
"concentr-portion",
"concentr-permillion",
"concentr-part-per-million", // deprecated
"concentr-percent",
"concentr-permille",
"concentr-permyriad",
"concentr-mole",
"concentr-ofglucose",
"consumption-liter-per-kilometer",
"consumption-liter-per-100-kilometer",
"consumption-liter-per-100kilometers", // deprecated
"consumption-mile-per-gallon",
"consumption-mile-per-gallon-imperial",
"digital-petabyte",
"digital-terabyte",
"digital-terabit",
"digital-gigabyte",
"digital-gigabit",
"digital-megabyte",
"digital-megabit",
"digital-kilobyte",
"digital-kilobit",
"digital-byte",
"digital-bit",
"duration-century",
"duration-decade",
"duration-year",
"duration-year-person",
"duration-quarter",
"duration-month",
"duration-month-person",
"duration-week",
"duration-week-person",
"duration-day",
"duration-day-person",
"duration-hour",
"duration-minute",
"duration-second",
"duration-millisecond",
"duration-microsecond",
"duration-nanosecond",
"electric-ampere",
"electric-milliampere",
"electric-ohm",
"electric-volt",
"energy-kilocalorie",
"energy-calorie",
"energy-foodcalorie",
"energy-kilojoule",
"energy-joule",
"energy-kilowatt-hour",
"energy-electronvolt",
"energy-british-thermal-unit",
"energy-therm-us",
"force-pound-force",
"force-newton",
"force-kilowatt-hour-per-100-kilometer",
"frequency-gigahertz",
"frequency-megahertz",
"frequency-kilohertz",
"frequency-hertz",
"graphics-em",
"graphics-pixel",
"graphics-megapixel",
"graphics-pixel-per-centimeter",
"graphics-pixel-per-inch",
"graphics-dot-per-centimeter",
"graphics-dot-per-inch",
"graphics-dot",
"length-earth-radius",
"length-100-kilometer",
"length-kilometer",
"length-meter",
"length-decimeter",
"length-centimeter",
"length-millimeter",
"length-micrometer",
"length-nanometer",
"length-picometer",
"length-mile",
"length-yard",
"length-foot",
"length-inch",
"length-parsec",
"length-light-year",
"length-astronomical-unit",
"length-furlong",
"length-fathom",
"length-nautical-mile",
"length-mile-scandinavian",
"length-point",
"length-solar-radius",
"light-lux",
"light-candela",
"light-lumen",
"light-solar-luminosity",
"mass-tonne",
"mass-metric-ton",
"mass-kilogram",
"mass-gram",
"mass-milligram",
"mass-microgram",
"mass-ton",
"mass-stone",
"mass-pound",
"mass-ounce",
"mass-ounce-troy",
"mass-carat",
"mass-dalton",
"mass-earth-mass",
"mass-solar-mass",
"mass-grain",
"power-gigawatt",
"power-megawatt",
"power-kilowatt",
"power-watt",
"power-milliwatt",
"power-horsepower",
"pressure-millimeter-ofhg",
"pressure-millimeter-of-mercury", // deprecated
"pressure-ofhg",
"pressure-pound-force-per-square-inch",
"pressure-pound-per-square-inch", // deprecated
"pressure-inch-ofhg",
"pressure-inch-hg", // deprecated
"pressure-bar",
"pressure-millibar",
"pressure-atmosphere",
"pressure-pascal",
"pressure-hectopascal",
"pressure-kilopascal",
"pressure-megapascal",
"speed-kilometer-per-hour",
"speed-meter-per-second",
"speed-mile-per-hour",
"speed-knot",
"speed-beaufort",
"temperature-generic",
"temperature-celsius",
"temperature-fahrenheit",
"temperature-kelvin",
"torque-pound-force-foot",
"torque-pound-foot", // deprecated
"torque-newton-meter",
"volume-cubic-kilometer",
"volume-cubic-meter",
"volume-cubic-centimeter",
"volume-cubic-mile",
"volume-cubic-yard",
"volume-cubic-foot",
"volume-cubic-inch",
"volume-megaliter",
"volume-hectoliter",
"volume-liter",
"volume-deciliter",
"volume-centiliter",
"volume-milliliter",
"volume-pint-metric",
"volume-cup-metric",
"volume-acre-foot",
"volume-bushel",
"volume-gallon",
"volume-gallon-imperial",
"volume-quart",
"volume-pint",
"volume-pint-imperial",
"volume-cup",
"volume-fluid-ounce",
"volume-fluid-ounce-imperial",
"volume-tablespoon",
"volume-teaspoon",
"volume-barrel",
"volume-dessert-spoon",
"volume-dessert-spoon-imperial",
"volume-drop",
"volume-dram",
"volume-jigger",
"volume-pinch",
"volume-quart-imperial",
"angle-steradian",
"concentr-katal",
"electric-coulomb",
"electric-farad",
"electric-henry",
"electric-siemens",
"energy-calorie-it",
"energy-british-thermal-unit-it",
"energy-becquerel",
"energy-sievert",
"energy-gray",
"force-kilogram-force",
"length-rod",
"length-chain",
"magnetic-tesla",
"magnetic-weber",
"temperature-rankine",
"duration-fortnight",
"mass-slug",
"pressure-gasoline-energy-density",
"length-rin",
"length-sun",
"length-shaku-length",
"length-shaku-cloth",
"length-ken",
"length-jo-jp",
"length-ri-jp",
"area-bu-jp",
"area-se-jp",
"area-cho",
"volume-kosaji",
"volume-osaji",
"volume-cup-jp",
"volume-shaku",
"volume-sai",
"volume-to-jp",
"volume-koku",
"mass-fun"))
.freeze();
SupplementalDataInfo.getInstance().getUnitConverter().getLongUnitIdComparator();

private static final MapComparator<String> getInstance() {
return INSTANCE;
}
}

static MapComparator<String> countValueOrder =
Expand Down
Loading

0 comments on commit 866a0aa

Please sign in to comment.