jdk/src/java.base/share/classes/sun/util/locale/UnicodeLocaleExtension.java
changeset 26219 1a19360ff122
parent 25859 3317bb8137f4
equal deleted inserted replaced
26218:98453f165e21 26219:1a19360ff122
     1 
     1 
     2 /*
     2 /*
     3  * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
     3  * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
     4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     5  *
     5  *
     6  * This code is free software; you can redistribute it and/or modify it
     6  * This code is free software; you can redistribute it and/or modify it
     7  * under the terms of the GNU General Public License version 2 only, as
     7  * under the terms of the GNU General Public License version 2 only, as
     8  * published by the Free Software Foundation.  Oracle designates this
     8  * published by the Free Software Foundation.  Oracle designates this
    36 import java.util.Map;
    36 import java.util.Map;
    37 import java.util.Map.Entry;
    37 import java.util.Map.Entry;
    38 import java.util.Set;
    38 import java.util.Set;
    39 import java.util.SortedMap;
    39 import java.util.SortedMap;
    40 import java.util.SortedSet;
    40 import java.util.SortedSet;
       
    41 import java.util.StringJoiner;
    41 
    42 
    42 public class UnicodeLocaleExtension extends Extension {
    43 public class UnicodeLocaleExtension extends Extension {
    43     public static final char SINGLETON = 'u';
    44     public static final char SINGLETON = 'u';
    44 
    45 
    45     private final Set<String> attributes;
    46     private final Set<String> attributes;
    68         } else {
    69         } else {
    69             this.keywords = Collections.emptyMap();
    70             this.keywords = Collections.emptyMap();
    70         }
    71         }
    71 
    72 
    72         if (!this.attributes.isEmpty() || !this.keywords.isEmpty()) {
    73         if (!this.attributes.isEmpty() || !this.keywords.isEmpty()) {
    73             StringBuilder sb = new StringBuilder();
    74             StringJoiner sj = new StringJoiner(LanguageTag.SEP);
    74             for (String attribute : this.attributes) {
    75             for (String attribute : this.attributes) {
    75                 sb.append(LanguageTag.SEP).append(attribute);
    76                 sj.add(attribute);
    76             }
    77             }
    77             for (Entry<String, String> keyword : this.keywords.entrySet()) {
    78             for (Entry<String, String> keyword : this.keywords.entrySet()) {
    78                 String key = keyword.getKey();
    79                 String key = keyword.getKey();
    79                 String value = keyword.getValue();
    80                 String value = keyword.getValue();
    80 
    81 
    81                 sb.append(LanguageTag.SEP).append(key);
    82                 sj.add(key);
    82                 if (value.length() > 0) {
    83                 if (value.length() > 0) {
    83                     sb.append(LanguageTag.SEP).append(value);
    84                     sj.add(value);
    84                 }
    85                 }
    85             }
    86             }
    86             setValue(sb.substring(1));   // skip leading '-'
    87             setValue(sj.toString());
    87         }
    88         }
    88     }
    89     }
    89 
    90 
    90     public Set<String> getUnicodeLocaleAttributes() {
    91     public Set<String> getUnicodeLocaleAttributes() {
    91         if (attributes == Collections.EMPTY_SET) {
    92         if (attributes == Collections.EMPTY_SET) {