diff --git a/icu4j/main/core/src/main/java/com/ibm/icu/impl/units/MeasureUnitImpl.java b/icu4j/main/core/src/main/java/com/ibm/icu/impl/units/MeasureUnitImpl.java index 1c5cba038db7..e42797f20161 100644 --- a/icu4j/main/core/src/main/java/com/ibm/icu/impl/units/MeasureUnitImpl.java +++ b/icu4j/main/core/src/main/java/com/ibm/icu/impl/units/MeasureUnitImpl.java @@ -612,6 +612,18 @@ private MeasureUnitImpl parse() { return result; } + /** + * Token states definitions. + */ + enum TokenState { + // No tokens seen yet (will accept power, SI or binary prefix, or simple unit) + NO_TOKENS_SEEN, + // Power token seen (will not accept another power token) + POWER_TOKEN_SEEN, + // SI or binary prefix token seen (will not accept a power, or SI or binary prefix token) + PREFIX_TOKEN_SEEN + } + /** * Returns the next "single unit" via result. *

@@ -627,13 +639,7 @@ private MeasureUnitImpl parse() { private SingleUnitOrConstant nextSingleUnit() { SingleUnitImpl result = new SingleUnitImpl(); - // State definitions: - // 0 = No tokens seen yet (will accept power, SI or binary prefix, or simple - // unit) - // 1 = Power token seen (will not accept another power token) - // 2 = SI or binary prefix token seen (will not accept a power, or SI or binary - // prefix token) - int state = 0; + TokenState state = TokenState.NO_TOKENS_SEEN; boolean atStart = fIndex == 0; Token token = nextToken(); @@ -704,21 +710,21 @@ private SingleUnitOrConstant nextSingleUnit() { while (true) { switch (token.getType()) { case TYPE_POWER_PART: - if (state > 0) { + if (state != TokenState.NO_TOKENS_SEEN) { throw new IllegalArgumentException(); } result.setDimensionality(result.getDimensionality() * token.getPower()); - state = 1; + state = TokenState.POWER_TOKEN_SEEN; break; case TYPE_PREFIX: - if (state > 1) { + if (state == TokenState.PREFIX_TOKEN_SEEN) { throw new IllegalArgumentException(); } result.setPrefix(token.getPrefix()); - state = 2; + state = TokenState.PREFIX_TOKEN_SEEN; break; case TYPE_SIMPLE_UNIT: