@Test(expected=IllegalArgumentException.class) public void doubleUnderscore() { System.err.println(LocaleUtils.parseLocale("__").getDisplayName()); }
public static Locale parseLocale(String string) { String[] segments = string.split("[-_]"); if (segments.length == 1) { if ("".equals(segments[0].trim())) { throw new IllegalArgumentException("Invalid locale string: " + string); } else { return new Locale(segments[0].trim()); } } else if (segments.length == 2) { if ("".equals(segments[0].trim()) || "".equals(segments[1].trim())) { throw new IllegalArgumentException("Invalid locale string: " + string); } else { return new Locale(segments[0].trim(), segments[1].trim()); } } else if (segments.length == 3) { if ("".equals(segments[0].trim()) || "".equals(segments[1].trim()) || "".equals(segments[2].trim())) { throw new IllegalArgumentException("Invalid locale string: " + string); } else { return new Locale(segments[0].trim(), segments[1].trim(), segments[2].trim()); } } else { throw new IllegalArgumentException("Invalid locale string: " + string); } }
LocaleUtils { public static Locale parseLocale(String string) { String[] segments = string.split("[-_]"); if (segments.length == 1) { if ("".equals(segments[0].trim())) { throw new IllegalArgumentException("Invalid locale string: " + string); } else { return new Locale(segments[0].trim()); } } else if (segments.length == 2) { if ("".equals(segments[0].trim()) || "".equals(segments[1].trim())) { throw new IllegalArgumentException("Invalid locale string: " + string); } else { return new Locale(segments[0].trim(), segments[1].trim()); } } else if (segments.length == 3) { if ("".equals(segments[0].trim()) || "".equals(segments[1].trim()) || "".equals(segments[2].trim())) { throw new IllegalArgumentException("Invalid locale string: " + string); } else { return new Locale(segments[0].trim(), segments[1].trim(), segments[2].trim()); } } else { throw new IllegalArgumentException("Invalid locale string: " + string); } } }
LocaleUtils { public static Locale parseLocale(String string) { String[] segments = string.split("[-_]"); if (segments.length == 1) { if ("".equals(segments[0].trim())) { throw new IllegalArgumentException("Invalid locale string: " + string); } else { return new Locale(segments[0].trim()); } } else if (segments.length == 2) { if ("".equals(segments[0].trim()) || "".equals(segments[1].trim())) { throw new IllegalArgumentException("Invalid locale string: " + string); } else { return new Locale(segments[0].trim(), segments[1].trim()); } } else if (segments.length == 3) { if ("".equals(segments[0].trim()) || "".equals(segments[1].trim()) || "".equals(segments[2].trim())) { throw new IllegalArgumentException("Invalid locale string: " + string); } else { return new Locale(segments[0].trim(), segments[1].trim(), segments[2].trim()); } } else { throw new IllegalArgumentException("Invalid locale string: " + string); } }  }
LocaleUtils { public static Locale parseLocale(String string) { String[] segments = string.split("[-_]"); if (segments.length == 1) { if ("".equals(segments[0].trim())) { throw new IllegalArgumentException("Invalid locale string: " + string); } else { return new Locale(segments[0].trim()); } } else if (segments.length == 2) { if ("".equals(segments[0].trim()) || "".equals(segments[1].trim())) { throw new IllegalArgumentException("Invalid locale string: " + string); } else { return new Locale(segments[0].trim(), segments[1].trim()); } } else if (segments.length == 3) { if ("".equals(segments[0].trim()) || "".equals(segments[1].trim()) || "".equals(segments[2].trim())) { throw new IllegalArgumentException("Invalid locale string: " + string); } else { return new Locale(segments[0].trim(), segments[1].trim(), segments[2].trim()); } } else { throw new IllegalArgumentException("Invalid locale string: " + string); } }  static Locale parseLocale(String string); static Locale bestLocale(Locale[] preferredLocales, Locale[] availableLocales); }
LocaleUtils { public static Locale parseLocale(String string) { String[] segments = string.split("[-_]"); if (segments.length == 1) { if ("".equals(segments[0].trim())) { throw new IllegalArgumentException("Invalid locale string: " + string); } else { return new Locale(segments[0].trim()); } } else if (segments.length == 2) { if ("".equals(segments[0].trim()) || "".equals(segments[1].trim())) { throw new IllegalArgumentException("Invalid locale string: " + string); } else { return new Locale(segments[0].trim(), segments[1].trim()); } } else if (segments.length == 3) { if ("".equals(segments[0].trim()) || "".equals(segments[1].trim()) || "".equals(segments[2].trim())) { throw new IllegalArgumentException("Invalid locale string: " + string); } else { return new Locale(segments[0].trim(), segments[1].trim(), segments[2].trim()); } } else { throw new IllegalArgumentException("Invalid locale string: " + string); } }  static Locale parseLocale(String string); static Locale bestLocale(Locale[] preferredLocales, Locale[] availableLocales); static final Locale DEFAULT_LOCALE; }