LogManagerProperties extends Properties { static String toLanguageTag(final Locale locale) { final String l = locale.getLanguage(); final String c = locale.getCountry(); final String v = locale.getVariant(); final char[] b = new char[l.length() + c.length() + v.length() + 2]; int count = l.length(); l.getChars(0, count, b, 0); if (c.length() != 0 || (l.length() != 0 && v.length() != 0)) { b[count] = '-'; ++count; c.getChars(0, c.length(), b, count); count += c.length(); } if (v.length() != 0 && (l.length() != 0 || c.length() != 0)) { b[count] = '-'; ++count; v.getChars(0, v.length(), b, count); count += v.length(); } return String.valueOf(b, 0, count); } LogManagerProperties(final Properties parent, final String prefix); @Override @SuppressWarnings("CloneDoesntCallSuperClone") synchronized Object clone(); @Override synchronized String getProperty(final String key); @Override String getProperty(final String key, final String def); @Override Object get(final Object key); @Override synchronized Object put(final Object key, final Object value); @Override Object setProperty(String key, String value); @Override boolean containsKey(final Object key); @Override synchronized Object remove(final Object key); @Override Enumeration<?> propertyNames(); @Override boolean equals(final Object o); @Override int hashCode();  }
@Test public void testToLanguageTag() throws Exception { assertEquals("en-US", LogManagerProperties.toLanguageTag(Locale.US)); assertEquals("en", LogManagerProperties.toLanguageTag(Locale.ENGLISH)); assertEquals("", LogManagerProperties.toLanguageTag(new Locale("", "", ""))); Locale l = new Locale("en", "US", "slang"); assertEquals("en-US-slang", LogManagerProperties.toLanguageTag(l)); l = new Locale("en", "", "slang"); assertEquals("en--slang", LogManagerProperties.toLanguageTag(l)); try { LogManagerProperties.toLanguageTag(null); fail("Null was allowed."); } catch (NullPointerException expect) { } }