Subtag implements Serializable, Cloneable,
		Comparable<Subtag> { public boolean isValid() { switch (type) { case PRIMARY: case SCRIPT: case REGION: case VARIANT: case EXTLANG: try { getEnum(); return true; } catch (Exception e) { return false; } case EXTENSION: return name.matches("[A-Za-z0-9]{2,8}"); case GRANDFATHERED: return name.matches("[A-Za-z]{1,3}(?:-[A-Za-z0-9]{2,8}){1,2}"); case PRIVATEUSE: return name.matches("[A-Za-z0-9]{1,8}"); case SINGLETON: return name.matches("[A-Za-z]"); case WILDCARD: return name.equals("*"); case SIMPLE: return name.matches("[A-Za-z0-9]{1,8}"); default: return false; } } Subtag(Language language);  Subtag(Script script);  Subtag(Region region);  Subtag(Variant variant);  Subtag(Extlang extlang);  Subtag(Singleton singleton);  Subtag(Type type, String name);   Subtag();  Subtag(Type type, String name, Subtag prev);   Subtag(Type type, String name, Subtag prev, Subtag next); Type getType(); String getName(); Subtag getPrevious(); Subtag getNext(); String toString(); int hashCode(); boolean equals(Object obj); Subtag clone(); boolean isDeprecated(); @SuppressWarnings("unchecked") T getEnum(); boolean isValid(); Subtag canonicalize(); static Subtag newWildcard(); int compareTo(Subtag o);  }
@Test public void testIsValid() { Subtag validLang = new Subtag(Language.DE); Subtag invalidLang = new Subtag(Type.PRIMARY, "abcd"); assertTrue(validLang.isValid()); assertFalse(invalidLang.isValid()); Subtag validExtension = new Subtag(Type.EXTENSION, "abc"); Subtag invalidExtension = new Subtag(Type.EXTENSION, "a"); assertTrue(validExtension.isValid()); assertFalse(invalidExtension.isValid()); Subtag validGrandfathered = new Subtag(Type.GRANDFATHERED, "abc-AZ"); Subtag invalidGrandfathered = new Subtag(Type.GRANDFATHERED, "a"); assertTrue(validGrandfathered.isValid()); assertFalse(invalidGrandfathered.isValid()); Subtag validPrivateUse = new Subtag(Type.PRIVATEUSE, "a2c"); Subtag invalidPrivateUse = new Subtag(Type.PRIVATEUSE, "a-c"); assertTrue(validPrivateUse.isValid()); assertFalse(invalidPrivateUse.isValid()); Subtag validSingleton = new Subtag(Type.SINGLETON, "a"); Subtag invalidSingleton = new Subtag(Type.SINGLETON, "ab"); assertTrue(validSingleton.isValid()); assertFalse(invalidSingleton.isValid()); Subtag validWildcard = new Subtag(Type.WILDCARD, "*"); Subtag invalidWildcard = new Subtag(Type.WILDCARD, "?"); assertTrue(validWildcard.isValid()); assertFalse(invalidWildcard.isValid()); Subtag validSimple = new Subtag(Type.SIMPLE, "abc"); Subtag invalidSimple = new Subtag(Type.SIMPLE, "abc$"); assertTrue(validSimple.isValid()); assertFalse(invalidSimple.isValid()); }