Skip to content

Commit

Permalink
Issue #1. Repair and unit test of getLocalizedAbbreviations()
Browse files Browse the repository at this point in the history
  • Loading branch information
averbraeck committed Jan 21, 2023
1 parent 8010648 commit c4d0f46
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/main/java/org/djunits/unit/Unit.java
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,12 @@ public String getName()
public Set<String> getLocalizedAbbreviations()
{
String[] abbreviationArray = localization.getString(getQuantity().getName() + "." + this.id).split("\\|");
return new LinkedHashSet<>(Set.of(abbreviationArray));
Set<String> set = new LinkedHashSet<>();
for (String abb : abbreviationArray)
{
set.add(abb.strip());
}
return set;
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/test/java/org/djunits/locale/VerifyLocalizations.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,14 @@ public final void checkUnitSystemsLocale() throws URISyntaxException
assertEquals("Duration", DurationUnit.MINUTE.getLocalizedName());
assertEquals("h", DurationUnit.HOUR.getLocalizedDisplayAbbreviation());
assertEquals("hour", DurationUnit.HOUR.getLocalizedTextualAbbreviation());
Set<String> localizedAbbreviationsEN = DurationUnit.HOUR.getLocalizedAbbreviations();
assertTrue(localizedAbbreviationsEN.contains("h"));
Locale.setDefault(new Locale("nl", "NL"));
assertEquals("Tijdsduur", DurationUnit.MINUTE.getLocalizedName());
assertEquals("u", DurationUnit.HOUR.getLocalizedDisplayAbbreviation());
assertEquals("uur", DurationUnit.HOUR.getLocalizedTextualAbbreviation());
Set<String> localizedAbbreviationsNL = DurationUnit.HOUR.getLocalizedAbbreviations();
assertTrue(localizedAbbreviationsNL.contains("u"));
}

}

0 comments on commit c4d0f46

Please sign in to comment.