diff options
author | Matthias Klose <doko@gcc.gnu.org> | 2012-12-19 17:03:15 +0000 |
---|---|---|
committer | Matthias Klose <doko@gcc.gnu.org> | 2012-12-19 17:03:15 +0000 |
commit | a1906e8bbfa426ed1adfe751608bc74f1d4d2ab7 (patch) | |
tree | 9b478aacc6b13f1beadacec2ade096dcb732af53 /libjava/classpath/java/text | |
parent | baeb2e16475b278e83fe73751d4f0f572805b16e (diff) | |
download | gcc-a1906e8bbfa426ed1adfe751608bc74f1d4d2ab7.zip gcc-a1906e8bbfa426ed1adfe751608bc74f1d4d2ab7.tar.gz gcc-a1906e8bbfa426ed1adfe751608bc74f1d4d2ab7.tar.bz2 |
Import GNU Classpath (20121202).
2012-12-19 Matthias Klose <doko@ubuntu.com>
Import GNU Classpath (20121202).
* Regenerate class and header files.
* Regenerate auto* files.
* sources.am, gcj/javaprims.h: Regenerate.
* gnu/java/nio/FileLockImpl.java (close): New override.
From-SVN: r194618
Diffstat (limited to 'libjava/classpath/java/text')
-rw-r--r-- | libjava/classpath/java/text/AttributedString.java | 44 | ||||
-rw-r--r-- | libjava/classpath/java/text/AttributedStringIterator.java | 43 | ||||
-rw-r--r-- | libjava/classpath/java/text/Bidi.java | 26 | ||||
-rw-r--r-- | libjava/classpath/java/text/BreakIterator.java | 4 | ||||
-rw-r--r-- | libjava/classpath/java/text/ChoiceFormat.java | 8 | ||||
-rw-r--r-- | libjava/classpath/java/text/CollationElementIterator.java | 73 | ||||
-rw-r--r-- | libjava/classpath/java/text/DateFormatSymbols.java | 315 | ||||
-rw-r--r-- | libjava/classpath/java/text/DecimalFormat.java | 6 | ||||
-rw-r--r-- | libjava/classpath/java/text/MessageFormat.java | 3 | ||||
-rw-r--r-- | libjava/classpath/java/text/NumberFormat.java | 3 |
10 files changed, 372 insertions, 153 deletions
diff --git a/libjava/classpath/java/text/AttributedString.java b/libjava/classpath/java/text/AttributedString.java index 7ffb3d4..4293d7d 100644 --- a/libjava/classpath/java/text/AttributedString.java +++ b/libjava/classpath/java/text/AttributedString.java @@ -1,5 +1,5 @@ /* AttributedString.java -- Models text with attributes - Copyright (C) 1998, 1999, 2004, 2005, 2006, Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2004, 2005, 2006, 2012 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -48,6 +48,8 @@ import java.util.Iterator; import java.util.Map; import java.util.Set; +import static java.text.AttributedCharacterIterator.Attribute; + /** * This class models a <code>String</code> with attributes over various * subranges of the string. It allows applications to access this @@ -68,7 +70,7 @@ public class AttributedString { /** A Map of the attributes */ - Map attribs; + Map<? extends Attribute, ?> attribs; /** The beginning index of the attributes */ int beginIndex; @@ -83,7 +85,8 @@ public class AttributedString * @param beginIndex the start index. * @param endIndex the end index. */ - AttributeRange(Map attribs, int beginIndex, int endIndex) + AttributeRange(Map<? extends Attribute, ?> attribs, + int beginIndex, int endIndex) { this.attribs = attribs; this.beginIndex = beginIndex; @@ -122,7 +125,7 @@ public class AttributedString * @param attributes The attribute list. */ public AttributedString(String str, - Map<? extends AttributedCharacterIterator.Attribute, ?> attributes) + Map<? extends Attribute, ?> attributes) { this(str); @@ -178,7 +181,7 @@ public class AttributedString * <code>null</code> to include all attributes. */ public AttributedString(AttributedCharacterIterator aci, int begin, int end, - AttributedCharacterIterator.Attribute[] attributes) + Attribute[] attributes) { // Validate some arguments if ((begin < 0) || (end < begin) || end > aci.getEndIndex()) @@ -187,29 +190,28 @@ public class AttributedString CPStringBuilder sb = new CPStringBuilder(""); // Get the valid attribute list - Set allAttribs = aci.getAllAttributeKeys(); + Set<Attribute> allAttribs = aci.getAllAttributeKeys(); if (attributes != null) allAttribs.retainAll(Arrays.asList(attributes)); // Loop through and extract the attributes char c = aci.setIndex(begin); - ArrayList accum = new ArrayList(); + ArrayList<AttributeRange> accum = new ArrayList<AttributeRange>(); do { sb.append(c); - Iterator iter = allAttribs.iterator(); + Iterator<Attribute> iter = allAttribs.iterator(); while(iter.hasNext()) { Object obj = iter.next(); // What should we do if this is not true? - if (!(obj instanceof AttributedCharacterIterator.Attribute)) + if (!(obj instanceof Attribute)) continue; - AttributedCharacterIterator.Attribute attrib = - (AttributedCharacterIterator.Attribute)obj; + Attribute attrib = (Attribute)obj; // Make sure the attribute is defined. Object attribObj = aci.getAttribute(attrib); @@ -237,7 +239,7 @@ public class AttributedString } // Create a map object. Yes this will only contain one attribute - Map newMap = new Hashtable(); + Map<Attribute,Object> newMap = new Hashtable<Attribute,Object>(); newMap.put(attrib, attribObj); // Add it to the attribute list. @@ -249,7 +251,7 @@ public class AttributedString while( aci.getIndex() < end ); attribs = new AttributeRange[accum.size()]; - attribs = (AttributeRange[]) accum.toArray(attribs); + attribs = accum.toArray(attribs); sci = new StringCharacterIterator(sb.toString()); } @@ -260,8 +262,7 @@ public class AttributedString * @param attrib The attribute to add. * @param value The value of the attribute. */ - public void addAttribute(AttributedCharacterIterator.Attribute attrib, - Object value) + public void addAttribute(Attribute attrib, Object value) { addAttribute(attrib, value, 0, sci.getEndIndex()); } @@ -278,14 +279,13 @@ public class AttributedString * @exception IllegalArgumentException If attribute is <code>null</code> or * the subrange is not valid. */ - public void addAttribute(AttributedCharacterIterator.Attribute attrib, - Object value, int begin, int end) + public void addAttribute(Attribute attrib, Object value, int begin, int end) { if (attrib == null) throw new IllegalArgumentException("null attribute"); if (end <= begin) throw new IllegalArgumentException("Requires end > begin"); - HashMap hm = new HashMap(); + HashMap<Attribute,Object> hm = new HashMap<Attribute,Object>(); hm.put(attrib, value); addAttributes(hm, begin, end); @@ -303,7 +303,7 @@ public class AttributedString * <code>null</code>. * @throws IllegalArgumentException if the subrange is not valid. */ - public void addAttributes(Map<? extends AttributedCharacterIterator.Attribute, ?> attributes, + public void addAttributes(Map<? extends Attribute, ?> attributes, int beginIndex, int endIndex) { if (attributes == null) @@ -343,8 +343,7 @@ public class AttributedString * * @return An <code>AttributedCharacterIterator</code> for this string. */ - public AttributedCharacterIterator getIterator( - AttributedCharacterIterator.Attribute[] attributes) + public AttributedCharacterIterator getIterator(Attribute[] attributes) { return(getIterator(attributes, 0, sci.getEndIndex())); } @@ -363,8 +362,7 @@ public class AttributedString * * @return An <code>AttributedCharacterIterator</code> for this string. */ - public AttributedCharacterIterator getIterator( - AttributedCharacterIterator.Attribute[] attributes, + public AttributedCharacterIterator getIterator(Attribute[] attributes, int beginIndex, int endIndex) { if ((beginIndex < 0) || (endIndex > sci.getEndIndex()) || diff --git a/libjava/classpath/java/text/AttributedStringIterator.java b/libjava/classpath/java/text/AttributedStringIterator.java index 429bd70..6d402cb 100644 --- a/libjava/classpath/java/text/AttributedStringIterator.java +++ b/libjava/classpath/java/text/AttributedStringIterator.java @@ -1,5 +1,5 @@ /* AttributedStringIterator.java -- Class to iterate over AttributedString - Copyright (C) 1998, 1999, 2004, 2005, 2006, Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2004, 2005, 2006, 2012 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -44,6 +44,8 @@ import java.util.Iterator; import java.util.Map; import java.util.Set; +import static java.text.AttributedCharacterIterator.Attribute; + /** * This class implements the AttributedCharacterIterator interface. It * is used by AttributedString.getIterator(). @@ -67,7 +69,7 @@ class AttributedStringIterator implements AttributedCharacterIterator * The list of attributes that the user is interested in. We may, * at our option, not return any other attributes. */ - private AttributedCharacterIterator.Attribute[] restricts; + private Attribute[] restricts; /*************************************************************************/ @@ -155,9 +157,9 @@ class AttributedStringIterator implements AttributedCharacterIterator * Returns a list of all the attribute keys that are defined anywhere * on this string. */ - public Set getAllAttributeKeys() + public Set<Attribute> getAllAttributeKeys() { - HashSet s = new HashSet(); + HashSet<Attribute> s = new HashSet<Attribute>(); if (attribs == null) return(s); @@ -167,8 +169,7 @@ class AttributedStringIterator implements AttributedCharacterIterator || attribs[i].endIndex <= getBeginIndex()) continue; - Set key_set = attribs[i].attribs.keySet(); - Iterator iter = key_set.iterator(); + Iterator<? extends Attribute> iter = attribs[i].attribs.keySet().iterator(); while (iter.hasNext()) { s.add(iter.next()); @@ -190,14 +191,14 @@ class AttributedStringIterator implements AttributedCharacterIterator return getRunLimit(getAllAttributeKeys()); } - public int getRunLimit(AttributedCharacterIterator.Attribute attrib) + public int getRunLimit(Attribute attrib) { - HashSet s = new HashSet(); + HashSet<Attribute> s = new HashSet<Attribute>(); s.add(attrib); return(getRunLimit(s)); } - public synchronized int getRunLimit(Set attributeSet) + public synchronized int getRunLimit(Set<? extends Attribute> attributeSet) { if (attributeSet == null) return ci.getEndIndex(); @@ -207,13 +208,13 @@ class AttributedStringIterator implements AttributedCharacterIterator int limit = current; if (current == end) return end; - Map runValues = getAttributes(); + Map<Attribute,Object> runValues = getAttributes(); while (limit < end) { - Iterator iterator = attributeSet.iterator(); + Iterator<? extends Attribute> iterator = attributeSet.iterator(); while (iterator.hasNext()) { - Attribute attributeKey = (Attribute) iterator.next(); + Attribute attributeKey = iterator.next(); Object v1 = runValues.get(attributeKey); Object v2 = getAttribute(attributeKey, limit + 1); boolean changed = false; @@ -262,11 +263,11 @@ class AttributedStringIterator implements AttributedCharacterIterator * * return The index of the first character in the run. */ - public int getRunStart(AttributedCharacterIterator.Attribute attrib) + public int getRunStart(Attribute attrib) { if (attrib == null) return ci.getBeginIndex(); - HashSet s = new HashSet(); + HashSet<Attribute> s = new HashSet<Attribute>(); s.add(attrib); return(getRunStart(s)); } @@ -279,7 +280,7 @@ class AttributedStringIterator implements AttributedCharacterIterator * * return The index of the first character in the run. */ - public int getRunStart(Set attributeSet) + public int getRunStart(Set<? extends Attribute> attributeSet) { if (attributeSet == null) return ci.getBeginIndex(); @@ -289,14 +290,14 @@ class AttributedStringIterator implements AttributedCharacterIterator int start = current; if (start == begin) return begin; - Map runValues = getAttributes(); + Map<Attribute, Object> runValues = getAttributes(); int prev = start - 1; while (start > begin) { - Iterator iterator = attributeSet.iterator(); + Iterator<? extends Attribute> iterator = attributeSet.iterator(); while (iterator.hasNext()) { - Attribute attributeKey = (Attribute) iterator.next(); + Attribute attributeKey = iterator.next(); Object v1 = runValues.get(attributeKey); Object v2 = getAttribute(attributeKey, prev); boolean changed = false; @@ -340,7 +341,7 @@ class AttributedStringIterator implements AttributedCharacterIterator { if (pos >= attribs[i].beginIndex && pos < attribs[i].endIndex) { - Set keys = attribs[i].attribs.keySet(); + Set<? extends Attribute> keys = attribs[i].attribs.keySet(); if (keys.contains(key)) { return attribs[i].attribs.get(key); @@ -370,9 +371,9 @@ class AttributedStringIterator implements AttributedCharacterIterator * Return a list of all the attributes and values defined for this * character */ - public Map getAttributes() + public Map<Attribute,Object> getAttributes() { - HashMap m = new HashMap(); + HashMap<Attribute,Object> m = new HashMap<Attribute,Object>(); if (attribs == null) return(m); diff --git a/libjava/classpath/java/text/Bidi.java b/libjava/classpath/java/text/Bidi.java index 6a7bd07..236247d 100644 --- a/libjava/classpath/java/text/Bidi.java +++ b/libjava/classpath/java/text/Bidi.java @@ -1,5 +1,5 @@ /* Bidi.java -- Bidirectional Algorithm implementation - Copyright (C) 2005, 2006 Free Software Foundation, Inc. + Copyright (C) 2005, 2006, 2012 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -109,7 +109,7 @@ public final class Bidi // A list of indices where a formatting code was found. These // are indicies into the original text -- not into the text after // the codes have been removed. - private ArrayList formatterIndices; + private ArrayList<Integer> formatterIndices; // Indices of the starts of runs in the text. private int[] runs; @@ -161,13 +161,13 @@ public final class Bidi if (val instanceof NumericShaper) shaper = (NumericShaper) val; - char[] text = new char[iter.getEndIndex() - iter.getBeginIndex()]; - this.embeddings = new byte[this.text.length]; - this.embeddingOffset = 0; - this.length = text.length; - for (int i = 0; i < this.text.length; ++i) + text = new char[iter.getEndIndex() - iter.getBeginIndex()]; + embeddings = new byte[text.length]; + embeddingOffset = 0; + length = text.length; + for (int i = 0; i < text.length; ++i) { - this.text[i] = iter.current(); + text[i] = iter.current(); val = iter.getAttribute(TextAttribute.BIDI_EMBEDDING); if (val instanceof Integer) @@ -178,13 +178,13 @@ public final class Bidi bval = 0; else bval = (byte) ival; - this.embeddings[i] = bval; + embeddings[i] = bval; } } // Invoke the numeric shaper, if specified. if (shaper != null) - shaper.shape(this.text, 0, this.length); + shaper.shape(text, 0, length); runBidi(); } @@ -404,7 +404,7 @@ public final class Bidi { // Mark this character for removal. if (formatterIndices == null) - formatterIndices = new ArrayList(); + formatterIndices = new ArrayList<Integer>(); formatterIndices.add(Integer.valueOf(i)); } else if (directionalOverride != -1) @@ -427,7 +427,7 @@ public final class Bidi if (i == size) nextFmt = length; else - nextFmt = ((Integer) formatterIndices.get(i)).intValue(); + nextFmt = formatterIndices.get(i).intValue(); // Non-formatter codes are from 'input' to 'nextFmt'. int len = nextFmt - input; System.arraycopy(levels, input, levels, output, len); @@ -716,7 +716,7 @@ public final class Bidi // Process from the end as we are copying the array over itself here. for (int index = formatterIndices.size() - 1; index >= 0; --index) { - int nextFmt = ((Integer) formatterIndices.get(index)).intValue(); + int nextFmt = formatterIndices.get(index).intValue(); // nextFmt points to a location in the original array. So, // nextFmt+1 is the target of our copying. output is the location diff --git a/libjava/classpath/java/text/BreakIterator.java b/libjava/classpath/java/text/BreakIterator.java index 628cb72..6fed88f 100644 --- a/libjava/classpath/java/text/BreakIterator.java +++ b/libjava/classpath/java/text/BreakIterator.java @@ -1,5 +1,5 @@ /* BreakIterator.java -- Breaks text into elements - Copyright (C) 1998, 1999, 2001, 2004, 2005, 2007 + Copyright (C) 1998, 1999, 2001, 2004, 2005, 2007, 2012 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -160,7 +160,7 @@ public abstract class BreakIterator implements Cloneable } try { - Class k = Class.forName(className); + Class<?> k = Class.forName(className); return (BreakIterator) k.newInstance(); } catch (ClassNotFoundException x1) diff --git a/libjava/classpath/java/text/ChoiceFormat.java b/libjava/classpath/java/text/ChoiceFormat.java index 4842f49..c6a508c 100644 --- a/libjava/classpath/java/text/ChoiceFormat.java +++ b/libjava/classpath/java/text/ChoiceFormat.java @@ -1,5 +1,5 @@ /* ChoiceFormat.java -- Format over a range of numbers - Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2005 + Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2005, 2012 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -98,8 +98,8 @@ public class ChoiceFormat extends NumberFormat // This isn't explicitly documented. But for instance we accept // '#' as a literal hash in a format string. int index = 0, max = newPattern.length(); - Vector stringVec = new Vector (); - Vector limitVec = new Vector (); + Vector<String> stringVec = new Vector<String> (); + Vector<Double> limitVec = new Vector<Double> (); final CPStringBuilder buf = new CPStringBuilder (); while (true) @@ -159,7 +159,7 @@ public class ChoiceFormat extends NumberFormat choiceLimits = new double[limitVec.size()]; for (int i = 0; i < choiceLimits.length; ++i) { - Double d = (Double) limitVec.elementAt(i); + Double d = limitVec.elementAt(i); choiceLimits[i] = d.doubleValue(); } } diff --git a/libjava/classpath/java/text/CollationElementIterator.java b/libjava/classpath/java/text/CollationElementIterator.java index 0ca23d0..42452e9 100644 --- a/libjava/classpath/java/text/CollationElementIterator.java +++ b/libjava/classpath/java/text/CollationElementIterator.java @@ -1,5 +1,5 @@ /* CollationElementIterator.java -- Walks through collation elements - Copyright (C) 1998, 1999, 2001, 2002, 2003, 2004 Free Software Foundation + Copyright (C) 1998, 1999, 2001, 2002, 2003, 2004, 2012 Free Software Foundation This file is part of GNU Classpath. @@ -91,12 +91,12 @@ public final class CollationElementIterator * Array containing the collation decomposition of the * text given to the constructor. */ - private RuleBasedCollator.CollationElement[] text_decomposition; + private RuleBasedCollator.CollationElement[] textDecomposition; /** * Array containing the index of the specified block. */ - private int[] text_indexes; + private int[] textIndexes; /** * This method initializes a new instance of <code>CollationElementIterator</code> @@ -130,12 +130,12 @@ public final class CollationElementIterator RuleBasedCollator.CollationElement nextBlock() { - if (index >= text_decomposition.length) + if (index >= textDecomposition.length) return null; - RuleBasedCollator.CollationElement e = text_decomposition[index]; + RuleBasedCollator.CollationElement e = textDecomposition[index]; - textIndex = text_indexes[index+1]; + textIndex = textIndexes[index+1]; index++; @@ -148,9 +148,9 @@ public final class CollationElementIterator return null; index--; - RuleBasedCollator.CollationElement e = text_decomposition[index]; + RuleBasedCollator.CollationElement e = textDecomposition[index]; - textIndex = text_indexes[index+1]; + textIndex = textIndexes[index+1]; return e; } @@ -268,23 +268,23 @@ public final class CollationElementIterator String work_text = text.intern(); - ArrayList a_element = new ArrayList(); - ArrayList a_idx = new ArrayList(); + ArrayList<RuleBasedCollator.CollationElement> aElement = new ArrayList<RuleBasedCollator.CollationElement>(); + ArrayList<Integer> aIdx = new ArrayList<Integer>(); // Build element collection ordered as they come in "text". while (idx < work_text.length()) { - String key, key_old; + String key, keyOld; Object object = null; int p = 1; // IMPROVE: use a TreeMap with a prefix-ordering rule. - key_old = key = null; + keyOld = key = null; do { if (object != null) - key_old = key; + keyOld = key; key = work_text.substring (idx, idx+p); object = collator.prefix_tree.get (key); if (object != null && idx < alreadyExpanded) @@ -294,7 +294,7 @@ public final class CollationElementIterator prefix.expansion.startsWith(work_text.substring(0, idx))) { object = null; - key = key_old; + key = keyOld; } } p++; @@ -302,7 +302,7 @@ public final class CollationElementIterator while (idx+p <= work_text.length()); if (object == null) - key = key_old; + key = keyOld; RuleBasedCollator.CollationElement prefix = (RuleBasedCollator.CollationElement) collator.prefix_tree.get (key); @@ -322,8 +322,8 @@ public final class CollationElementIterator RuleBasedCollator.CollationElement e = collator.getDefaultAccentedElement (work_text.charAt (idx)); - a_element.add (e); - a_idx.add (new Integer(idx_idx)); + aElement.add (e); + aIdx.add (Integer.valueOf(idx_idx)); idx++; alreadyExpanded--; if (alreadyExpanded == 0) @@ -342,15 +342,15 @@ public final class CollationElementIterator /* This is a normal character. */ RuleBasedCollator.CollationElement e = collator.getDefaultElement (work_text.charAt (idx)); - Integer i_ref = new Integer(idx_idx); + Integer iRef = Integer.valueOf(idx_idx); /* Don't forget to mark it as a special sequence so the * string can be ordered. */ - a_element.add (RuleBasedCollator.SPECIAL_UNKNOWN_SEQ); - a_idx.add (i_ref); - a_element.add (e); - a_idx.add (i_ref); + aElement.add (RuleBasedCollator.SPECIAL_UNKNOWN_SEQ); + aIdx.add (iRef); + aElement.add (e); + aIdx.add (iRef); idx_idx++; idx++; } @@ -367,8 +367,8 @@ public final class CollationElementIterator work_text = prefix.expansion + work_text.substring (idx+prefix.key.length()); idx = 0; - a_element.add (prefix); - a_idx.add (new Integer(idx_idx)); + aElement.add (prefix); + aIdx.add (Integer.valueOf(idx_idx)); if (alreadyExpanded == 0) idxToMove = prefix.key.length(); alreadyExpanded += prefix.expansion.length()-prefix.key.length(); @@ -378,8 +378,8 @@ public final class CollationElementIterator /* Third case: the simplest. We have got the prefix and it * has not to be expanded. */ - a_element.add (prefix); - a_idx.add (new Integer(idx_idx)); + aElement.add (prefix); + aIdx.add (Integer.valueOf(idx_idx)); idx += prefix.key.length(); /* If the sequence is in an expansion, we must decrease the * counter. @@ -398,14 +398,13 @@ public final class CollationElementIterator } } - text_decomposition = (RuleBasedCollator.CollationElement[]) - a_element.toArray(new RuleBasedCollator.CollationElement[a_element.size()]); - text_indexes = new int[a_idx.size()+1]; - for (int i = 0; i < a_idx.size(); i++) + textDecomposition = aElement.toArray(new RuleBasedCollator.CollationElement[aElement.size()]); + textIndexes = new int[aIdx.size()+1]; + for (int i = 0; i < aIdx.size(); i++) { - text_indexes[i] = ((Integer)a_idx.get(i)).intValue(); + textIndexes[i] = aIdx.get(i).intValue(); } - text_indexes[a_idx.size()] = text.length(); + textIndexes[aIdx.size()] = text.length(); } /** @@ -460,19 +459,19 @@ public final class CollationElementIterator if (offset > (text.getEndIndex() - 1)) throw new IllegalArgumentException("Offset too large: " + offset); - for (index = 0; index < text_decomposition.length; index++) + for (index = 0; index < textDecomposition.length; index++) { - if (offset <= text_indexes[index]) + if (offset <= textIndexes[index]) break; } /* - * As text_indexes[0] == 0, we should not have to take care whether index is + * As textIndexes[0] == 0, we should not have to take care whether index is * greater than 0. It is always. */ - if (text_indexes[index] == offset) + if (textIndexes[index] == offset) textIndex = offset; else - textIndex = text_indexes[index-1]; + textIndex = textIndexes[index-1]; } /** diff --git a/libjava/classpath/java/text/DateFormatSymbols.java b/libjava/classpath/java/text/DateFormatSymbols.java index 53e7ba0..9d0ace6 100644 --- a/libjava/classpath/java/text/DateFormatSymbols.java +++ b/libjava/classpath/java/text/DateFormatSymbols.java @@ -56,6 +56,11 @@ import java.util.ResourceBundle; import java.util.ServiceLoader; import java.util.TimeZone; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.ConcurrentHashMap; + +import java.util.regex.Pattern; + import java.util.spi.TimeZoneNameProvider; /** @@ -71,14 +76,6 @@ import java.util.spi.TimeZoneNameProvider; */ public class DateFormatSymbols implements java.io.Serializable, Cloneable { - String[] ampms; - String[] eras; - private String localPatternChars; - String[] months; - String[] shortMonths; - String[] shortWeekdays; - String[] weekdays; - /** * The set of properties for obtaining the metazone data. */ @@ -100,6 +97,173 @@ public class DateFormatSymbols implements java.io.Serializable, Cloneable } } + private static final Pattern ZONE_SEP = Pattern.compile("\u00a9"); + + private static final Pattern FIELD_SEP = Pattern.compile("\u00ae"); + + /** + * Class for storing DateFormatSymbols data parsed from the property files. + */ + private static class DFSData + { + private String[] ampms; + private String[] eras; + private String localPatternChars; + private String[] months; + private String[] shortMonths; + private String[] weekdays; + private String[] shortWeekdays; + private String[] dateFormats; + private String[] timeFormats; + private String[][] runtimeZoneStrings; + + /** + * Construct a new instance with the parsed data. + * + * @param ampms strings for "am" and "pm". + * @param eras strings for calendar eras. + * @param localPatternChars localised pattern characters. + * @param months strings for the months of the year. + * @param shortMonths short strings for the months of the year. + * @param weekdays strings for the days of the week. + * @param shortWeekdays short strings for the days of the week. + * @param dateFormats localised date formats. + * @param timeFormats localised time formats. + * @param runtimeZoneStrings localised time zone names. + */ + public DFSData(String[] ampms, String[] eras, String localPatternChars, + String[] months, String[] shortMonths, String[] weekdays, + String[] shortWeekdays, String[] dateFormats, + String[] timeFormats, String[][] runtimeZoneStrings) + { + this.ampms = ampms; + this.eras = eras; + this.localPatternChars = localPatternChars; + this.months = months; + this.shortMonths = shortMonths; + this.weekdays = weekdays; + this.shortWeekdays = shortWeekdays; + this.dateFormats = dateFormats; + this.timeFormats = timeFormats; + this.runtimeZoneStrings = runtimeZoneStrings; + } + + /** + * Accessor for the AM/PM data. + * + * @return the AM/PM strings. + */ + public String[] getAMPMs() + { + return ampms.clone(); + } + + /** + * Accessor for the era data. + * + * @return the era strings. + */ + public String[] getEras() + { + return eras.clone(); + } + + /** + * Accessor for the local pattern characters. + * + * @return the local pattern characters. + */ + public String getLocalPatternChars() + { + return localPatternChars; + } + + /** + * Accessor for the months of the year (long form). + * + * @return the months of the year (long form). + */ + public String[] getMonths() + { + return months.clone(); + } + + /** + * Accessor for the months of the year (short form). + * + * @return the months of the year (short form). + */ + public String[] getShortMonths() + { + return shortMonths.clone(); + } + + /** + * Accessor for the days of the week (long form). + * + * @return the days of the week (long form). + */ + public String[] getWeekdays() + { + return weekdays.clone(); + } + + /** + * Accessor for the days of the week (short form). + * + * @return the days of the week (short form). + */ + public String[] getShortWeekdays() + { + return shortWeekdays.clone(); + } + + /** + * Accessor for the date formats. + * + * @return the date formats. + */ + public String[] getDateFormats() + { + return dateFormats.clone(); + } + + /** + * Accessor for the time formats. + * + * @return the time formats. + */ + public String[] getTimeFormats() + { + return timeFormats.clone(); + } + + /** + * Accessor for the zone strings. + * + * @return the zone strings. + */ + public String[][] getZoneStrings() + { + // Perform a deep clone so subarrays aren't modifiable + String[][] clone = runtimeZoneStrings.clone(); + for (int a = 0; a < clone.length; ++a) + clone[a] = runtimeZoneStrings[a].clone(); + return clone; + } + + } + + private static final ConcurrentMap<Locale, DFSData> dataCache = new ConcurrentHashMap<Locale, DFSData>(); + + String[] ampms; + String[] eras; + private String localPatternChars; + String[] months; + String[] shortMonths; + String[] shortWeekdays; + String[] weekdays; + /** * The timezone strings supplied by the runtime. */ @@ -161,7 +325,7 @@ public class DateFormatSymbols implements java.io.Serializable, Cloneable for (int a = 0; a < bundles.size(); ++a) { String localeData = bundles.get(a).getString(name); - String[] array = localeData.split("\u00ae", size); + String[] array = FIELD_SEP.split(localeData, size); for (int b = 0; b < data.length; ++b) { if (array.length > b && array[b] != null && data[b].isEmpty() && !array[b].isEmpty()) @@ -180,21 +344,20 @@ public class DateFormatSymbols implements java.io.Serializable, Cloneable return data; } - private String[][] getZoneStrings(ResourceBundle res, Locale locale) + private static String[][] getZoneStrings(List<ResourceBundle> bundles, Locale locale) { List<String[]> allZones = new ArrayList<String[]>(); try { Map<String,String[]> systemZones = new HashMap<String,String[]>(); - while (true) + for (ResourceBundle bundle : bundles) { - int index = 0; String country = locale.getCountry(); - String data = res.getString("zoneStrings"); - String[] zones = data.split("\u00a9"); + String data = bundle.getString("zoneStrings"); + String[] zones = ZONE_SEP.split(data); for (int a = 0; a < zones.length; ++a) { - String[] strings = zones[a].split("\u00ae"); + String[] strings = FIELD_SEP.split(zones[a]); String type = properties.getProperty(strings[0] + "." + country); if (type == null) type = properties.getProperty(strings[0] + ".DEFAULT"); @@ -217,12 +380,6 @@ public class DateFormatSymbols implements java.io.Serializable, Cloneable } systemZones.put(strings[0], strings); } - if (res.getLocale() == Locale.ROOT) - break; - else - res = ResourceBundle.getBundle("gnu.java.locale.LocaleInformation", - LocaleHelper.getFallbackLocale(res.getLocale()), - ClassLoader.getSystemClassLoader()); } /* Final sanity check for missing values */ for (String[] zstrings : systemZones.values()) @@ -288,17 +445,95 @@ public class DateFormatSymbols implements java.io.Serializable, Cloneable return allZones.toArray(new String[allZones.size()][]); } - private String[] formatsForKey(ResourceBundle res, String key) + /** + * Retrieve the date or time formats for a specific key e.g. + * asking for "DateFormat" will return an array containing the + * full, long, medium and short date formats localised for + * the locales in the specified bundle. + * + * @param bundles the stack of bundles to check, most-specific first. + * @param key the type of format to retrieve. + * @param an array of localised strings for each format prefix. + */ + private static String[] formatsForKey(List<ResourceBundle> bundles, String key) { String[] values = new String[formatPrefixes.length]; for (int i = 0; i < formatPrefixes.length; i++) - values[i] = res.getString(formatPrefixes[i] + key); + values[i] = getString(bundles, formatPrefixes[i] + key); return values; } /** + * Simple wrapper around extracting a {@code String} from a + * {@code ResourceBundle}. Keep searching less-specific locales + * until a non-null non-empty value is found. + * + * @param bundles the stack of bundles to check, most-specific first. + * @param key the key of the value to retrieve. + * @return the first non-null non-empty String found or the last + * retrieved if one isn't found. + */ + private static String getString(List<ResourceBundle> bundles, String key) + { + String val = null; + for (ResourceBundle bundle : bundles) + { + val = bundle.getString(key); + if (val != null && !val.isEmpty()) + return val; + } + return val; + } + + /** + * Retrieves the locale data from the property files and constructs a + * {@code DFSData} instance for it. + * + * @param the locale for which data should be retrieved. + * @return the parsed data. + * @throws MissingResourceException if the resources for the specified + * locale could not be found or loaded. + */ + private static DFSData retrieveData(Locale locale) + throws MissingResourceException + { + DFSData data = dataCache.get(locale); + if (data == null) + { + ClassLoader ldr = ClassLoader.getSystemClassLoader(); + List<ResourceBundle> bundles = new ArrayList<ResourceBundle>(); + ResourceBundle res + = ResourceBundle.getBundle("gnu.java.locale.LocaleInformation", locale, ldr); + bundles.add(res); + Locale resLocale = res.getLocale(); + while (resLocale != Locale.ROOT) + { + res = ResourceBundle.getBundle("gnu.java.locale.LocaleInformation", + LocaleHelper.getFallbackLocale(resLocale), ldr); + bundles.add(res); + resLocale = res.getLocale(); + } + String[] lMonths = getStringArray(bundles, "months", 13); + String[] lWeekdays = getStringArray(bundles, "weekdays", 8); + data = new DFSData(getStringArray(bundles, "ampms", 2), + getStringArray(bundles, "eras", 2), + getString(bundles, "localPatternChars"), + lMonths, getStringArray(bundles, "shortMonths", 13, lMonths), + lWeekdays, getStringArray(bundles, "shortWeekdays", 8, lWeekdays), + formatsForKey(bundles, "DateFormat"), + formatsForKey(bundles, "TimeFormat"), + getZoneStrings(bundles, locale)); + DFSData cachedData = dataCache.putIfAbsent(locale, data); + // Use the earlier version if another thread beat us to it. + if (cachedData != null) + data = cachedData; + } + return data; + } + + /** * This method initializes a new instance of <code>DateFormatSymbols</code> * by loading the date format information for the specified locale. * This constructor only obtains instances using the runtime's resources; @@ -314,29 +549,17 @@ public class DateFormatSymbols implements java.io.Serializable, Cloneable public DateFormatSymbols (Locale locale) throws MissingResourceException { - ClassLoader ldr = ClassLoader.getSystemClassLoader(); - List<ResourceBundle> bundles = new ArrayList<ResourceBundle>(); - ResourceBundle res - = ResourceBundle.getBundle("gnu.java.locale.LocaleInformation", locale, ldr); - bundles.add(res); - Locale resLocale = res.getLocale(); - while (resLocale != Locale.ROOT) - { - res = ResourceBundle.getBundle("gnu.java.locale.LocaleInformation", - LocaleHelper.getFallbackLocale(resLocale), ldr); - bundles.add(res); - resLocale = res.getLocale(); - } - ampms = getStringArray(bundles, "ampms", 2); - eras = getStringArray(bundles, "eras", 2); - localPatternChars = res.getString("localPatternChars"); - months = getStringArray(bundles, "months", 13); - shortMonths = getStringArray(bundles, "shortMonths", 13, months); - weekdays = getStringArray(bundles, "weekdays", 8); - shortWeekdays = getStringArray(bundles, "shortWeekdays", 8, weekdays); - dateFormats = formatsForKey(res, "DateFormat"); - timeFormats = formatsForKey(res, "TimeFormat"); - runtimeZoneStrings = getZoneStrings(res, locale); + DFSData data = retrieveData(locale); + ampms = data.getAMPMs(); + eras = data.getEras(); + localPatternChars = data.getLocalPatternChars(); + months = data.getMonths(); + shortMonths = data.getShortMonths(); + weekdays = data.getWeekdays(); + shortWeekdays = data.getShortWeekdays(); + dateFormats = data.getDateFormats(); + timeFormats = data.getTimeFormats(); + runtimeZoneStrings = data.getZoneStrings(); } /** diff --git a/libjava/classpath/java/text/DecimalFormat.java b/libjava/classpath/java/text/DecimalFormat.java index 9f02bb8..77af0d3 100644 --- a/libjava/classpath/java/text/DecimalFormat.java +++ b/libjava/classpath/java/text/DecimalFormat.java @@ -1,5 +1,5 @@ /* DecimalFormat.java -- Formats and parses numbers - Copyright (C) 1999, 2000, 2001, 2003, 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 1999, 2000, 2001, 2003, 2004, 2005, 2012 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -177,7 +177,7 @@ public class DecimalFormat extends NumberFormat private boolean hasFractionalPattern; /** Stores a list of attributes for use by formatToCharacterIterator. */ - private ArrayList attributes = new ArrayList(); + private ArrayList<FieldPosition> attributes = new ArrayList<FieldPosition>(); /** * Constructs a <code>DecimalFormat</code> which uses the default @@ -438,7 +438,7 @@ public class DecimalFormat extends NumberFormat // add NumberFormat field attributes to the AttributedString for (int i = 0; i < attributes.size(); i++) { - FieldPosition pos = (FieldPosition) attributes.get(i); + FieldPosition pos = attributes.get(i); Format.Field attribute = pos.getFieldAttribute(); as.addAttribute(attribute, attribute, pos.getBeginIndex(), diff --git a/libjava/classpath/java/text/MessageFormat.java b/libjava/classpath/java/text/MessageFormat.java index ba5805a..0e04b2b 100644 --- a/libjava/classpath/java/text/MessageFormat.java +++ b/libjava/classpath/java/text/MessageFormat.java @@ -1,5 +1,5 @@ /* MessageFormat.java - Localized message formatting. - Copyright (C) 1999, 2001, 2002, 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 1999, 2001, 2002, 2004, 2005, 2012 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -164,7 +164,6 @@ public class MessageFormat extends Format public static final MessageFormat.Field ARGUMENT = new MessageFormat.Field("argument"); // For deserialization - @SuppressWarnings("unused") private Field() { super(""); diff --git a/libjava/classpath/java/text/NumberFormat.java b/libjava/classpath/java/text/NumberFormat.java index fef986b..555ee37 100644 --- a/libjava/classpath/java/text/NumberFormat.java +++ b/libjava/classpath/java/text/NumberFormat.java @@ -1,5 +1,5 @@ /* NumberFormat.java -- Formats and parses numbers - Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004, 2007 + Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004, 2007, 2012 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -177,7 +177,6 @@ public abstract class NumberFormat extends Format implements Cloneable * This constructor is only used by the deserializer. Without it, * it would fail to construct a valid object. */ - @SuppressWarnings("unused") private Field() { super(""); |