Skip to content

Commit

Permalink
More formatting improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
keilw committed Nov 24, 2024
1 parent 467a85e commit 90047a9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 21 deletions.
43 changes: 27 additions & 16 deletions src/main/java/tech/units/indriya/format/SimpleUnitFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -440,14 +440,12 @@ private DefaultFormat init() {
aliasWithPrefixes(Units.CELSIUS, "°C");
// Additional cases and aliases
label(Units.PERCENT, "%");
label(Units.METRE, "m");
label(Units.SECOND, "s");
label(Units.MINUTE, "min");
label(Units.HOUR, "h");
label(Units.DAY, "d");
alias(Units.DAY, "day");
label(Units.WEEK, "wk");
alias(Units.WEEK, "week");
labelWithPrefixes(Units.MINUTE, "min");
labelWithPrefixes(Units.HOUR, "h");
labelWithPrefixes(Units.DAY, "d");
aliasWithPrefixes(Units.DAY, "day");
labelWithPrefixes(Units.WEEK, "wk");
aliasWithPrefixes(Units.WEEK, "week");
label(Units.YEAR, "yr");
alias(Units.YEAR, "y");
alias(Units.YEAR, "year");
Expand All @@ -457,19 +455,17 @@ private DefaultFormat init() {
alias(Units.MONTH, "mon");
alias(Units.MONTH, "month");
label(Units.KILOMETRE_PER_HOUR, "km/h");
labelWithPrefixes(Units.SQUARE_METRE, "\u33A1");
aliasWithPrefixes(Units.SQUARE_METRE, "m2");
labelWithPrefixes(Units.CUBIC_METRE, "\u33A5");
aliasWithPrefixes(Units.CUBIC_METRE, "m3");
label(Units.NEWTON, "N");
label(Units.RADIAN, "rad");
labelWithPrefixes(Units.LITRE, "l");

label(AbstractUnit.ONE, "one");

// -- LITRE
label(Units.LITRE, "l");
for(Prefix prefix : MetricPrefix.values()) {
label(Units.LITRE.prefix(prefix), prefix.getSymbol()+"l");
} // TODO how about BinaryPrefix?
//label(Units.NEWTON, "N");
//label(Units.RADIAN, "rad");
//label(Units.METRE, "m");
//label(Units.SECOND, "s");

return this;
}
Expand Down Expand Up @@ -540,9 +536,13 @@ protected boolean isValidIdentifier(String name) {
*/
private void labelWithPrefixes(Unit<?> unit, String label) {
label(unit, label);
// TODO try to optimize this
for (int i = 0; i < METRIC_PREFIX_SYMBOLS.length; i++) {
label(unit.prefix(MetricPrefix.values()[i]), METRIC_PREFIX_SYMBOLS[i] + label);
}
for (int i = 0; i < BINARY_PREFIX_SYMBOLS.length; i++) {
label(unit.prefix(BinaryPrefix.values()[i]), BINARY_PREFIX_SYMBOLS[i] + label);
}
}

/**
Expand All @@ -553,9 +553,14 @@ private void labelWithPrefixes(Unit<?> unit, String label) {
*/
private void aliasWithPrefixes(Unit<?> unit, String alias) {
alias(unit, alias);
// TODO try to optimize this
for (int i = 0; i < METRIC_PREFIX_SYMBOLS.length; i++) {
alias(unit.prefix(MetricPrefix.values()[i]), METRIC_PREFIX_SYMBOLS[i] + alias);
}
for (int i = 0; i < BINARY_PREFIX_SYMBOLS.length; i++) {
alias(unit.prefix(BinaryPrefix.values()[i]), BINARY_PREFIX_SYMBOLS[i] + alias);
}

}

protected static boolean isUnitIdentifierPart(char ch) {
Expand Down Expand Up @@ -1177,6 +1182,9 @@ private void aliasWithAsciiPrefixes(Unit<?> unit, String alias) {
for (int i = 0; i < METRIC_PREFIX_SYMBOLS.length; i++) {
alias(unit.prefix(MetricPrefix.values()[i]), asciiPrefix(METRIC_PREFIX_SYMBOLS[i]) + alias);
}
for (int i = 0; i < BINARY_PREFIX_SYMBOLS.length; i++) {
alias(unit.prefix(BinaryPrefix.values()[i]), asciiPrefix(BINARY_PREFIX_SYMBOLS[i]) + alias);
}
}
}

Expand All @@ -1192,6 +1200,9 @@ private void labelWithAsciiPrefixes(Unit<?> unit, String label) {
for (int i = 0; i < METRIC_PREFIX_SYMBOLS.length; i++) {
label(unit.prefix(MetricPrefix.values()[i]), asciiPrefix(METRIC_PREFIX_SYMBOLS[i]) + label);
}
for (int i = 0; i < BINARY_PREFIX_SYMBOLS.length; i++) {
label(unit.prefix(BinaryPrefix.values()[i]), asciiPrefix(BINARY_PREFIX_SYMBOLS[i]) + label);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@
import static tech.units.indriya.unit.Units.CELSIUS;
import static tech.units.indriya.unit.Units.COULOMB;
import static tech.units.indriya.unit.Units.CUBIC_METRE;
import static tech.units.indriya.unit.Units.DAY;
import static tech.units.indriya.unit.Units.FARAD;
import static tech.units.indriya.unit.Units.GRAM;
import static tech.units.indriya.unit.Units.GRAY;
import static tech.units.indriya.unit.Units.HENRY;
import static tech.units.indriya.unit.Units.HERTZ;
import static tech.units.indriya.unit.Units.HOUR;
import static tech.units.indriya.unit.Units.JOULE;
import static tech.units.indriya.unit.Units.KATAL;
import static tech.units.indriya.unit.Units.KELVIN;
Expand All @@ -60,11 +62,13 @@
import static tech.units.indriya.unit.Units.SECOND;
import static tech.units.indriya.unit.Units.SIEMENS;
import static tech.units.indriya.unit.Units.SIEVERT;
import static tech.units.indriya.unit.Units.SQUARE_METRE;
import static tech.units.indriya.unit.Units.STERADIAN;
import static tech.units.indriya.unit.Units.TESLA;
import static tech.units.indriya.unit.Units.VOLT;
import static tech.units.indriya.unit.Units.WATT;
import static tech.units.indriya.unit.Units.WEBER;
import static tech.units.indriya.unit.Units.WEEK;

import java.util.Iterator;
import java.util.Map;
Expand Down Expand Up @@ -118,13 +122,13 @@ static enum NonPrefixedUnits {
Gray(GRAY),
Sievert(SIEVERT),
Katal(KATAL),
//SQUARE_METRE
//SquareMetre(SQUARE_METRE),
CubicMetre(CUBIC_METRE),
//PERCENT
//Minute(MINUTE),
//HOUR
//DAY
//WEEK
Minute(MINUTE),
Hour(HOUR),
//Day(DAY),
Week(WEEK),
//YEAR
Litre(LITRE)

Expand Down

0 comments on commit 90047a9

Please sign in to comment.