Java Code Examples for java.util.Locale.getUnicodeLocaleAttributes()

The following are Jave code examples for showing how to use getUnicodeLocaleAttributes() of the java.util.Locale class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: jdk8u-jdk   File: LocaleEnhanceTest.java   View Source Code Vote up 5 votes
public void testGetUnicodeLocaleAttributes() {
    Locale locale = Locale.forLanguageTag("en-US-u-abc-def");
    Set<String> attributes = locale.getUnicodeLocaleAttributes();
    assertEquals("number of attributes", 2, attributes.size());
    assertTrue("attribute abc", attributes.contains("abc"));
    assertTrue("attribute def", attributes.contains("def"));

    locale = Locale.forLanguageTag("en-US-u-ca-gregory");
    attributes = locale.getUnicodeLocaleAttributes();
    assertTrue("empty attributes", attributes.isEmpty());
}
 
Example 2
Project: jdk8u-jdk   File: LocaleEnhanceTest.java   View Source Code Vote up 5 votes
public void testBuilderAddUnicodeLocaleAttribute() {
    Builder builder = new Builder();
    Locale locale = builder
        .addUnicodeLocaleAttribute("def")
        .addUnicodeLocaleAttribute("abc")
        .build();

    Set<String> uattrs = locale.getUnicodeLocaleAttributes();
    assertEquals("number of attributes", 2, uattrs.size());
    assertTrue("attribute abc", uattrs.contains("abc"));
    assertTrue("attribute def", uattrs.contains("def"));

    // remove attribute
    locale = builder.removeUnicodeLocaleAttribute("xxx")
        .build();

    assertEquals("remove bogus", 2, uattrs.size());

    // add duplicate
    locale = builder.addUnicodeLocaleAttribute("abc")
        .build();
    assertEquals("add duplicate", 2, uattrs.size());

    // null attribute throws NPE
    new BuilderNPE("null attribute") { public void call() { b.addUnicodeLocaleAttribute(null); }};

    // illformed attribute throws IllformedLocaleException
    new BuilderILE("invalid attribute") { public void call() { b.addUnicodeLocaleAttribute("ca"); }};
}
 
Example 3
Project: openjdk-jdk10   File: LocaleEnhanceTest.java   View Source Code Vote up 5 votes
public void testGetUnicodeLocaleAttributes() {
    Locale locale = Locale.forLanguageTag("en-US-u-abc-def");
    Set<String> attributes = locale.getUnicodeLocaleAttributes();
    assertEquals("number of attributes", 2, attributes.size());
    assertTrue("attribute abc", attributes.contains("abc"));
    assertTrue("attribute def", attributes.contains("def"));

    locale = Locale.forLanguageTag("en-US-u-ca-gregory");
    attributes = locale.getUnicodeLocaleAttributes();
    assertTrue("empty attributes", attributes.isEmpty());
}
 
Example 4
Project: openjdk-jdk10   File: LocaleEnhanceTest.java   View Source Code Vote up 5 votes
public void testBuilderAddUnicodeLocaleAttribute() {
    Builder builder = new Builder();
    Locale locale = builder
        .addUnicodeLocaleAttribute("def")
        .addUnicodeLocaleAttribute("abc")
        .build();

    Set<String> uattrs = locale.getUnicodeLocaleAttributes();
    assertEquals("number of attributes", 2, uattrs.size());
    assertTrue("attribute abc", uattrs.contains("abc"));
    assertTrue("attribute def", uattrs.contains("def"));

    // remove attribute
    locale = builder.removeUnicodeLocaleAttribute("xxx")
        .build();

    assertEquals("remove bogus", 2, uattrs.size());

    // add duplicate
    locale = builder.addUnicodeLocaleAttribute("abc")
        .build();
    assertEquals("add duplicate", 2, uattrs.size());

    // null attribute throws NPE
    new BuilderNPE("null attribute") { public void call() { b.addUnicodeLocaleAttribute(null); }};
    new BuilderNPE("null attribute removal") { public void call() { b.removeUnicodeLocaleAttribute(null); }};

    // illformed attribute throws IllformedLocaleException
    new BuilderILE("invalid attribute") { public void call() { b.addUnicodeLocaleAttribute("ca"); }};
}