📄 dateformatsymbols.java
字号:
* be indexed by <code>Calendar.SUNDAY</code>, * <code>Calendar.MONDAY</code>, etc. */ public void setShortWeekdays(String[] newShortWeekdays) { shortWeekdays = duplicate(newShortWeekdays); } /** * Gets ampm strings. For example: "AM" and "PM". * @return the ampm strings. */ public String[] getAmPmStrings() { return duplicate(ampms); } /** * Sets ampm strings. For example: "AM" and "PM". * @param newAmpms the new ampm strings. */ public void setAmPmStrings(String[] newAmpms) { ampms = duplicate(newAmpms); } /** * Gets timezone strings. * @return the timezone strings. */ public String[][] getZoneStrings() { String[][] aCopy = new String[zoneStrings.length][]; for (int i = 0; i < zoneStrings.length; ++i) aCopy[i] = duplicate(zoneStrings[i]); return aCopy; } /** * Sets timezone strings. * @param newZoneStrings the new timezone strings. */ public void setZoneStrings(String[][] newZoneStrings) { String[][] aCopy = new String[newZoneStrings.length][]; for (int i = 0; i < newZoneStrings.length; ++i) aCopy[i] = duplicate(newZoneStrings[i]); zoneStrings = aCopy; } /** * Gets localized date-time pattern characters. For example: 'u', 't', etc. * @return the localized date-time pattern characters. */ public String getLocalPatternChars() { return new String(localPatternChars); } /** * Sets localized date-time pattern characters. For example: 'u', 't', etc. * @param newLocalPatternChars the new localized date-time * pattern characters. */ public void setLocalPatternChars(String newLocalPatternChars) { localPatternChars = new String(newLocalPatternChars); } /** * Overrides Cloneable */ public Object clone() { try { DateFormatSymbols other = (DateFormatSymbols)super.clone(); copyMembers(this, other); return other; } catch (CloneNotSupportedException e) { throw new InternalError(); } } /** * Override hashCode. * Generates a hash code for the DateFormatSymbols object. */ public int hashCode() { int hashcode = 0; for (int index = 0; index < this.zoneStrings[0].length; ++index) hashcode ^= this.zoneStrings[0][index].hashCode(); return hashcode; } /** * Override equals */ public boolean equals(Object obj) { if (this == obj) return true; if (obj == null || getClass() != obj.getClass()) return false; DateFormatSymbols that = (DateFormatSymbols) obj; return (Utility.arrayEquals(eras, that.eras) && Utility.arrayEquals(months, that.months) && Utility.arrayEquals(shortMonths, that.shortMonths) && Utility.arrayEquals(weekdays, that.weekdays) && Utility.arrayEquals(shortWeekdays, that.shortWeekdays) && Utility.arrayEquals(ampms, that.ampms) && Utility.arrayEquals(zoneStrings, that.zoneStrings) && Utility.arrayEquals(localPatternChars, that.localPatternChars)); } // =======================privates=============================== /** * Useful constant for defining timezone offsets. */ static final int millisPerHour = 60*60*1000; /** * Cache to hold the LocaleElements and DateFormatZoneData ResourceBundles * of a Locale. */ private static Hashtable cachedLocaleData = new Hashtable(3); /** * cache to hold time zone localized strings. Keyed by Locale */ private static Hashtable cachedZoneData = new Hashtable(); /** * Look up resource data for the desiredLocale in the cache; update the * cache if necessary. */ private ResourceBundle[] cacheLookup(Locale desiredLocale) { ResourceBundle[] rbs = new ResourceBundle[2]; SoftReference[] data = (SoftReference[])cachedLocaleData.get(desiredLocale); if (data == null) { rbs[0] = LocaleData.getLocaleElements(desiredLocale); rbs[1] = LocaleData.getDateFormatZoneData(desiredLocale); data = new SoftReference[] { new SoftReference(rbs[0]), new SoftReference(rbs[1]) }; cachedLocaleData.put(desiredLocale, data); } else { ResourceBundle r; if ((r = (ResourceBundle)data[0].get()) == null) { r = LocaleData.getLocaleElements(desiredLocale); data[0] = new SoftReference(r); } rbs[0] = r; if ((r = (ResourceBundle)data[1].get()) == null) { r = LocaleData.getDateFormatZoneData(desiredLocale); data[1] = new SoftReference(r); } rbs[1] = r; } return rbs; } /** * Load time zone localized strings. Enumerate all keys (except * "localPatternChars" and "zoneStrings"). */ private String[][] loadZoneStrings(Locale desiredLocale, ResourceBundle rsrc) { String[][] zones; SoftReference data = (SoftReference)cachedZoneData.get(desiredLocale); if (data == null || ((zones = (String[][])data.get()) == null)) { Vector vec = new Vector(); Enumeration keys = rsrc.getKeys(); while(keys.hasMoreElements()) { String key = (String)keys.nextElement(); if (!key.equals("localPatternChars") && !key.equals("zoneStrings")) { vec.add(rsrc.getObject(key)); } } zones = new String[vec.size()][]; vec.toArray(zones); data = new SoftReference(zones); cachedZoneData.put(desiredLocale, data); } return zones; } private void initializeData(Locale desiredLocale) { int i; ResourceBundle[] rbs = cacheLookup(desiredLocale); ResourceBundle resource = rbs[0]; ResourceBundle zoneResource = rbs[1]; // FIXME: cache only ResourceBundle. Hence every time, will do // getObject(). This won't be necessary if the Resource itself // is cached. eras = (String[])resource.getObject("Eras"); months = resource.getStringArray("MonthNames"); shortMonths = resource.getStringArray("MonthAbbreviations"); String[] lWeekdays = resource.getStringArray("DayNames"); weekdays = new String[8]; weekdays[0] = ""; // 1-based for (i=0; i<lWeekdays.length; i++) weekdays[i+1] = lWeekdays[i]; String[] sWeekdays = resource.getStringArray("DayAbbreviations"); shortWeekdays = new String[8]; shortWeekdays[0] = ""; // 1-based for (i=0; i<sWeekdays.length; i++) shortWeekdays[i+1] = sWeekdays[i]; ampms = resource.getStringArray("AmPmMarkers"); zoneStrings = (String[][])loadZoneStrings(desiredLocale, zoneResource); localPatternChars = (String) zoneResource.getObject("localPatternChars"); } /** * Package private: used by SimpleDateFormat * Gets the index for the given time zone ID to obtain the timezone * strings for formatting. The time zone ID is just for programmatic * lookup. NOT LOCALIZED!!! * @param ID the given time zone ID. * @return the index of the given time zone ID. Returns -1 if * the given time zone ID can't be located in the DateFormatSymbols object. * @see java.util.SimpleTimeZone */ final int getZoneIndex (String ID) { for (int index=0; index<zoneStrings.length; index++) { if (ID.equalsIgnoreCase(zoneStrings[index][0])) return index; } return -1; } /** * Clones an array of Strings. * @param srcArray the source array to be cloned. * @param count the number of elements in the given source array. * @return a cloned array. */ private final String[] duplicate(String[] srcArray) { String[] dstArray = new String[srcArray.length]; System.arraycopy(srcArray, 0, dstArray, 0, srcArray.length); return dstArray; } /** * Clones all the data members from the source DateFormatSymbols to * the target DateFormatSymbols. This is only for subclasses. * @param src the source DateFormatSymbols. * @param dst the target DateFormatSymbols. */ private final void copyMembers(DateFormatSymbols src, DateFormatSymbols dst) { dst.eras = duplicate(src.eras); dst.months = duplicate(src.months); dst.shortMonths = duplicate(src.shortMonths); dst.weekdays = duplicate(src.weekdays); dst.shortWeekdays = duplicate(src.shortWeekdays); dst.ampms = duplicate(src.ampms); for (int i = 0; i < dst.zoneStrings.length; ++i) dst.zoneStrings[i] = duplicate(src.zoneStrings[i]); dst.localPatternChars = new String (src.localPatternChars); } /** * Compares the equality of the two arrays of String. * @param current this String array. * @param other that String array. */ private final boolean equals(String[] current, String[] other) { int count = current.length; for (int i = 0; i < count; ++i) if (!current[i].equals(other[i])) return false; return true; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -