test/jdk/java/util/PluggableLocale/providersrc/DateFormatProviderImpl.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 7787 jdk/test/java/util/PluggableLocale/providersrc/DateFormatProviderImpl.java@d2420a14d0a2
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7787
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
     2
 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
package com.foo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.text.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.text.spi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import com.foobar.Utils;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
public class DateFormatProviderImpl extends DateFormatProvider {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    static Locale[] avail = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
        Locale.JAPAN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
        new Locale("ja", "JP", "osaka"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
        new Locale("ja", "JP", "kyoto"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
        new Locale("yy")};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    static String[] datePattern = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        "yyyy'\u5e74'M'\u6708'd'\u65e5'", // full date pattern
7787
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
    45
        "yyyy/MMM/dd", // long date pattern
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        "yyyy/MM/dd", // medium date pattern
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        "yy/MM/dd" // short date pattern
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    static String[] timePattern = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        "H'\u6642'mm'\u5206'ss'\u79d2' z", // full time pattern
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        "H:mm:ss z", // long time pattern
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        "H:mm:ss", // medium time pattern
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        "H:mm" // short time pattern
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    static String[] dialect = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        "\u3067\u3059\u3002",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        "\u3084\u3002",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        "\u3069\u3059\u3002",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        "\u308f\u3044\u308f\u3044"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    public Locale[] getAvailableLocales() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        return avail;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public DateFormat getDateInstance(int style, Locale locale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        for (int i = 0; i < avail.length; i ++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            if (Utils.supportsLocale(avail[i], locale)) {
7787
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
    71
                return new FooDateFormat(datePattern[style]+dialect[i], locale);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        throw new IllegalArgumentException("locale is not supported: "+locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public DateFormat getTimeInstance(int style, Locale locale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        for (int i = 0; i < avail.length; i ++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            if (Utils.supportsLocale(avail[i], locale)) {
7787
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
    80
                return new FooDateFormat(timePattern[style]+dialect[i], locale);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        throw new IllegalArgumentException("locale is not supported: "+locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public DateFormat getDateTimeInstance(int dateStyle, int timeStyle, Locale locale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        for (int i = 0; i < avail.length; i ++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            if (Utils.supportsLocale(avail[i], locale)) {
7787
d2420a14d0a2 7003643: [Fmt-Me] MessageFormat.toPattern produces wrong quoted string and subformat modifiers
okutsu
parents: 5506
diff changeset
    89
                return new FooDateFormat(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                    datePattern[dateStyle]+" "+timePattern[timeStyle]+dialect[i], locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        throw new IllegalArgumentException("locale is not supported: "+locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
}