jdk/src/share/classes/sun/util/locale/LocaleUtils.java
author okutsu
Thu, 14 Apr 2011 15:59:47 +0900
changeset 9224 75c0420badef
parent 6501 jdk/src/share/classes/sun/util/locale/AsciiUtil.java@684810d882b3
child 13583 dc0017b1a452
permissions -rw-r--r--
7028818: (lc) Lazily initialize locale extension 7029740: (lc) New Locale class implementation doesn't follow the Java coding conventions 7032820: (lc) sun.util.locale.InternalLocaleBuilder.CaseInsensitiveChar.equals problems 7033503: (lc) Restore optimization code for Locale class initialization 7033504: (lc) incompatible behavior change for ja_JP_JP and th_TH_TH locales Reviewed-by: naoto
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
     1
/*
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
     2
 * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
     4
 *
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    10
 *
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    15
 * accompanied this code).
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    16
 *
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    20
 *
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    23
 * questions.
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    24
 */
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    25
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    26
/*
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    27
 *******************************************************************************
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    28
 * Copyright (C) 2009, International Business Machines Corporation and         *
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    29
 * others. All Rights Reserved.                                                *
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    30
 *******************************************************************************
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    31
 */
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    32
package sun.util.locale;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    33
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
    34
import java.util.List;
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
    35
import java.util.Map;
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
    36
import java.util.Set;
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
    37
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
    38
/**
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
    39
 * Collection of static utility methods for Locale support. The
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
    40
 * methods which manipulate characters or strings support ASCII only.
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
    41
 */
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
    42
public final class LocaleUtils {
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
    43
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
    44
    private LocaleUtils() {
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
    45
    }
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
    46
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
    47
    /**
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
    48
     * Compares two ASCII Strings s1 and s2, ignoring case.
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
    49
     */
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    50
    public static boolean caseIgnoreMatch(String s1, String s2) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    51
        if (s1 == s2) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    52
            return true;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    53
        }
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
    54
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    55
        int len = s1.length();
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    56
        if (len != s2.length()) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    57
            return false;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    58
        }
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
    59
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
    60
        for (int i = 0; i < len; i++) {
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    61
            char c1 = s1.charAt(i);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    62
            char c2 = s2.charAt(i);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    63
            if (c1 != c2 && toLower(c1) != toLower(c2)) {
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
    64
                return false;
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    65
            }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    66
        }
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
    67
        return true;
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    68
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    69
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
    70
    static int caseIgnoreCompare(String s1, String s2) {
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    71
        if (s1 == s2) {
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    72
            return 0;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    73
        }
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
    74
        return toLowerString(s1).compareTo(toLowerString(s2));
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    75
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    76
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
    77
    static char toUpper(char c) {
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
    78
        return isLower(c) ? (char)(c - 0x20) : c;
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    79
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    80
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
    81
    static char toLower(char c) {
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
    82
        return isUpper(c) ? (char)(c + 0x20) : c;
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    83
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    84
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
    85
    /**
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
    86
     * Converts the given ASCII String to lower-case.
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
    87
     */
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    88
    public static String toLowerString(String s) {
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
    89
        int len = s.length();
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    90
        int idx = 0;
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
    91
        for (; idx < len; idx++) {
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
    92
            if (isUpper(s.charAt(idx))) {
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    93
                break;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    94
            }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    95
        }
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
    96
        if (idx == len) {
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    97
            return s;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
    98
        }
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
    99
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   100
        char[] buf = new char[len];
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   101
        for (int i = 0; i < len; i++) {
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   102
            char c = s.charAt(i);
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   103
            buf[i] = (i < idx) ? c : toLower(c);
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   104
        }
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   105
        return new String(buf);
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   106
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   107
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   108
    static String toUpperString(String s) {
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   109
        int len = s.length();
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   110
        int idx = 0;
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   111
        for (; idx < len; idx++) {
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   112
            if (isLower(s.charAt(idx))) {
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   113
                break;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   114
            }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   115
        }
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   116
        if (idx == len) {
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   117
            return s;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   118
        }
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   119
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   120
        char[] buf = new char[len];
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   121
        for (int i = 0; i < len; i++) {
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   122
            char c = s.charAt(i);
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   123
            buf[i] = (i < idx) ? c : toUpper(c);
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   124
        }
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   125
        return new String(buf);
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   126
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   127
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   128
    static String toTitleString(String s) {
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   129
        int len;
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   130
        if ((len = s.length()) == 0) {
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   131
            return s;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   132
        }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   133
        int idx = 0;
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   134
        if (!isLower(s.charAt(idx))) {
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   135
            for (idx = 1; idx < len; idx++) {
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   136
                if (isUpper(s.charAt(idx))) {
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   137
                    break;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   138
                }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   139
            }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   140
        }
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   141
        if (idx == len) {
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   142
            return s;
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   143
        }
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   144
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   145
        char[] buf = new char[len];
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   146
        for (int i = 0; i < len; i++) {
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   147
            char c = s.charAt(i);
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   148
            if (i == 0 && idx == 0) {
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   149
                buf[i] = toUpper(c);
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   150
            } else if (i < idx) {
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   151
                buf[i] = c;
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   152
            } else {
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   153
                buf[i] = toLower(c);
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   154
            }
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   155
        }
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   156
        return new String(buf);
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   157
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   158
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   159
    private static boolean isUpper(char c) {
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   160
        return c >= 'A' && c <= 'Z';
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   161
    }
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   162
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   163
    private static boolean isLower(char c) {
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   164
        return c >= 'a' && c <= 'z';
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   165
    }
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   166
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   167
    static boolean isAlpha(char c) {
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   168
        return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z');
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   169
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   170
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   171
    static boolean isAlphaString(String s) {
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   172
        int len = s.length();
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   173
        for (int i = 0; i < len; i++) {
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   174
            if (!isAlpha(s.charAt(i))) {
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   175
                return false;
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   176
            }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   177
        }
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   178
        return true;
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   179
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   180
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   181
    static boolean isNumeric(char c) {
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   182
        return (c >= '0' && c <= '9');
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   183
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   184
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   185
    static boolean isNumericString(String s) {
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   186
        int len = s.length();
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   187
        for (int i = 0; i < len; i++) {
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   188
            if (!isNumeric(s.charAt(i))) {
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   189
                return false;
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   190
            }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   191
        }
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   192
        return true;
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   193
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   194
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   195
    static boolean isAlphaNumeric(char c) {
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   196
        return isAlpha(c) || isNumeric(c);
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   197
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   198
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   199
    static boolean isAlphaNumericString(String s) {
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   200
        int len = s.length();
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   201
        for (int i = 0; i < len; i++) {
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   202
            if (!isAlphaNumeric(s.charAt(i))) {
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   203
                return false;
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   204
            }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   205
        }
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   206
        return true;
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   207
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   208
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   209
    static boolean isEmpty(String str) {
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   210
        return str == null || str.length() == 0;
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   211
    }
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   212
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   213
    static boolean isEmpty(Set<?> set) {
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   214
        return set == null || set.isEmpty();
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   215
    }
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   216
9224
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   217
    static boolean isEmpty(Map<?, ?> map) {
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   218
        return map == null || map.isEmpty();
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   219
    }
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   220
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   221
    static boolean isEmpty(List<?> list) {
75c0420badef 7028818: (lc) Lazily initialize locale extension
okutsu
parents: 6501
diff changeset
   222
        return list == null || list.isEmpty();
6501
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   223
    }
684810d882b3 6875847: Java Locale Enhancement
naoto
parents:
diff changeset
   224
}