1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
|
/*
* Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
*
*/
package com.foo;
import java.text.*;
import java.text.spi.*;
import java.util.*;
import com.foobar.Utils;
public class DateFormatSymbolsProviderImpl extends DateFormatSymbolsProvider {
static Locale[] avail = {
new Locale("ja", "JP", "osaka"),
new Locale("ja", "JP", "kyoto"),
Locale.JAPAN,
new Locale("yy", "ZZ")
};
static List<Locale> availList = Arrays.asList(avail);
static String[] dialect = {
"\u3084\u3002",
"\u3069\u3059\u3002",
"\u3067\u3059\u3002",
"-yy-ZZ"
};
static Map<Locale, FooDateFormatSymbols> symbols = new HashMap<Locale, FooDateFormatSymbols>(4);
public Locale[] getAvailableLocales() {
return avail;
}
public DateFormatSymbols getInstance(Locale locale) {
if (!Utils.supportsLocale(availList, locale)) {
throw new IllegalArgumentException("locale is not supported: "+locale);
}
FooDateFormatSymbols fdfs = symbols.get(locale);
if (fdfs == null) {
for (int index = 0; index < avail.length; index ++) {
if (Utils.supportsLocale(avail[index], locale)) {
fdfs = new FooDateFormatSymbols(index);
symbols.put(locale, fdfs);
break;
}
}
}
return fdfs;
}
class FooDateFormatSymbols extends DateFormatSymbols {
String dialect = "";
String[] eras = null;
String[] months = null;
String[] shortMonths = null;
String[] weekdays = null;
String[] shortWeekdays = null;
String[] ampms = null;
public FooDateFormatSymbols(int index) {
super(DateFormatSymbolsProviderImpl.this.avail[index]);
dialect = DateFormatSymbolsProviderImpl.this.dialect[index];
}
public String[] getEras() {
if (eras == null) {
eras = super.getEras();
for (int i = 0; i < eras.length; i++) {
eras[i] = eras[i]+dialect;
}
}
return eras;
}
/**
* Sets era strings. For example: "AD" and "BC".
* @param newEras the new era strings.
*/
public void setEras(String[] newEras) {
eras = newEras;
}
/**
* Gets month strings. For example: "January", "February", etc.
* @return the month strings.
*/
public String[] getMonths() {
if (months == null) {
months = super.getMonths();
for (int i = 0; i < months.length; i++) {
months[i] = months[i]+dialect;
}
}
return months;
}
/**
* Sets month strings. For example: "January", "February", etc.
* @param newMonths the new month strings.
*/
public void setMonths(String[] newMonths) {
months = newMonths;
}
/**
* Gets short month strings. For example: "Jan", "Feb", etc.
* @return the short month strings.
*/
public String[] getShortMonths() {
if (shortMonths == null) {
shortMonths = super.getShortMonths();
for (int i = 0; i < shortMonths.length; i++) {
shortMonths[i] = shortMonths[i]+dialect;
}
}
return shortMonths;
}
/**
* Sets short month strings. For example: "Jan", "Feb", etc.
* @param newShortMonths the new short month strings.
*/
public void setShortMonths(String[] newShortMonths) {
shortMonths = newShortMonths;
}
/**
* Gets weekday strings. For example: "Sunday", "Monday", etc.
* @return the weekday strings. Use <code>Calendar.SUNDAY</code>,
* <code>Calendar.MONDAY</code>, etc. to index the result array.
*/
public String[] getWeekdays() {
if (weekdays == null) {
weekdays = super.getWeekdays();
for (int i = 0; i < weekdays.length; i++) {
weekdays[i] = weekdays[i]+dialect;
}
}
return weekdays;
}
/**
* Sets weekday strings. For example: "Sunday", "Monday", etc.
* @param newWeekdays the new weekday strings. The array should
* be indexed by <code>Calendar.SUNDAY</code>,
* <code>Calendar.MONDAY</code>, etc.
*/
public void setWeekdays(String[] newWeekdays) {
weekdays = newWeekdays;
}
/**
* Gets short weekday strings. For example: "Sun", "Mon", etc.
* @return the short weekday strings. Use <code>Calendar.SUNDAY</code>,
* <code>Calendar.MONDAY</code>, etc. to index the result array.
*/
public String[] getShortWeekdays() {
if (shortWeekdays == null) {
shortWeekdays = super.getShortWeekdays();
for (int i = 0; i < shortWeekdays.length; i++) {
shortWeekdays[i] = shortWeekdays[i]+dialect;
}
}
return shortWeekdays;
}
/**
* Sets short weekday strings. For example: "Sun", "Mon", etc.
* @param newShortWeekdays the new short weekday strings. The array should
* be indexed by <code>Calendar.SUNDAY</code>,
* <code>Calendar.MONDAY</code>, etc.
*/
public void setShortWeekdays(String[] newShortWeekdays) {
shortWeekdays = newShortWeekdays;
}
/**
* Gets ampm strings. For example: "AM" and "PM".
* @return the ampm strings.
*/
public String[] getAmPmStrings() {
if (ampms == null) {
ampms = super.getAmPmStrings();
for (int i = 0; i < ampms.length; i++) {
ampms[i] = ampms[i]+dialect;
}
}
return ampms;
}
/**
* Sets ampm strings. For example: "AM" and "PM".
* @param newAmpms the new ampm strings.
*/
public void setAmPmStrings(String[] newAmpms) {
ampms = newAmpms;
}
@Override
public String[][] getZoneStrings() {
return new String[0][0];
}
}
}
|