From f8b2536dddb95b132a2e70c04f49d33b6ed0254e Mon Sep 17 00:00:00 2001 From: dbhole Date: Thu, 24 May 2012 19:00:16 -0700 Subject: [PATCH] 7117230: clean up warnings in java.text Reviewed-by: jrose, smarks --- .../text/AttributedCharacterIterator.java | 4 +- .../classes/java/text/AttributedString.java | 109 ++++++++++-------- .../classes/java/text/BreakDictionary.java | 6 +- .../classes/java/text/BreakIterator.java | 12 +- .../text/CharacterIteratorFieldDelegate.java | 10 +- src/share/classes/java/text/ChoiceFormat.java | 4 +- .../java/text/CollationElementIterator.java | 17 +-- src/share/classes/java/text/DateFormat.java | 2 +- .../classes/java/text/DecimalFormat.java | 8 +- .../text/DictionaryBasedBreakIterator.java | 26 +++-- .../classes/java/text/MergeCollation.java | 20 ++-- .../classes/java/text/MessageFormat.java | 13 ++- src/share/classes/java/text/NumberFormat.java | 6 +- .../classes/java/text/ParseException.java | 2 + .../classes/java/text/RBCollationTables.java | 22 ++-- .../classes/java/text/RBTableBuilder.java | 34 +++--- .../java/text/RuleBasedBreakIterator.java | 6 +- 17 files changed, 162 insertions(+), 139 deletions(-) diff --git a/src/share/classes/java/text/AttributedCharacterIterator.java b/src/share/classes/java/text/AttributedCharacterIterator.java index 86597bfec..3c6ed68c5 100644 --- a/src/share/classes/java/text/AttributedCharacterIterator.java +++ b/src/share/classes/java/text/AttributedCharacterIterator.java @@ -97,7 +97,7 @@ public interface AttributedCharacterIterator extends CharacterIterator { private String name; // table of all instances in this class, used by readResolve - private static final Map instanceMap = new HashMap(7); + private static final Map instanceMap = new HashMap<>(7); /** * Constructs an {@code Attribute} with the given name. @@ -150,7 +150,7 @@ public interface AttributedCharacterIterator extends CharacterIterator { throw new InvalidObjectException("subclass didn't correctly implement readResolve"); } - Attribute instance = (Attribute) instanceMap.get(getName()); + Attribute instance = instanceMap.get(getName()); if (instance != null) { return instance; } else { diff --git a/src/share/classes/java/text/AttributedString.java b/src/share/classes/java/text/AttributedString.java index c7c1f05d6..7e06e4266 100644 --- a/src/share/classes/java/text/AttributedString.java +++ b/src/share/classes/java/text/AttributedString.java @@ -61,8 +61,8 @@ public class AttributedString { int runArraySize; // current size of the arrays int runCount; // actual number of runs, <= runArraySize int runStarts[]; // start index for each run - Vector runAttributes[]; // vector of attribute keys for each run - Vector runAttributeValues[]; // parallel vector of attribute values for each run + Vector runAttributes[]; // vector of attribute keys for each run + Vector runAttributeValues[]; // parallel vector of attribute values for each run /** * Constructs an AttributedString instance with the given @@ -92,7 +92,7 @@ public class AttributedString { // Determine the runs, creating a new run when the attributes // differ. int offset = 0; - Map last = null; + Map last = null; for (int counter = 0; counter < iterators.length; counter++) { AttributedCharacterIterator iterator = iterators[counter]; @@ -103,7 +103,7 @@ public class AttributedString { while (index < end) { iterator.setIndex(index); - Map attrs = iterator.getAttributes(); + Map attrs = iterator.getAttributes(); if (mapsDiffer(last, attrs)) { setAttributes(attrs, index - start + offset); @@ -156,13 +156,14 @@ public class AttributedString { int attributeCount = attributes.size(); if (attributeCount > 0) { createRunAttributeDataVectors(); - Vector newRunAttributes = new Vector(attributeCount); - Vector newRunAttributeValues = new Vector(attributeCount); + Vector newRunAttributes = new Vector<>(attributeCount); + Vector newRunAttributeValues = new Vector<>(attributeCount); runAttributes[0] = newRunAttributes; runAttributeValues[0] = newRunAttributeValues; - Iterator iterator = attributes.entrySet().iterator(); + + Iterator> iterator = attributes.entrySet().iterator(); while (iterator.hasNext()) { - Map.Entry entry = (Map.Entry) iterator.next(); + Map.Entry entry = iterator.next(); newRunAttributes.addElement(entry.getKey()); newRunAttributeValues.addElement(entry.getValue()); } @@ -252,7 +253,7 @@ public class AttributedString { return; // Select attribute keys to be taken care of - HashSet keys = new HashSet(); + HashSet keys = new HashSet<>(); if (attributes == null) { keys.addAll(text.getAllAttributeKeys()); } else { @@ -266,9 +267,9 @@ public class AttributedString { // Get and set attribute runs for each attribute name. Need to // scan from the top of the text so that we can discard any // Annotation that is no longer applied to a subset text segment. - Iterator itr = keys.iterator(); + Iterator itr = keys.iterator(); while (itr.hasNext()) { - Attribute attributeKey = (Attribute)itr.next(); + Attribute attributeKey = itr.next(); text.setIndex(textBeginIndex); while (text.getIndex() < endIndex) { int start = text.getRunStart(attributeKey); @@ -390,10 +391,11 @@ public class AttributedString { int beginRunIndex = ensureRunBreak(beginIndex); int endRunIndex = ensureRunBreak(endIndex); - Iterator iterator = attributes.entrySet().iterator(); + Iterator> iterator = + attributes.entrySet().iterator(); while (iterator.hasNext()) { - Map.Entry entry = (Map.Entry) iterator.next(); - addAttributeRunData((Attribute) entry.getKey(), entry.getValue(), beginRunIndex, endRunIndex); + Map.Entry entry = iterator.next(); + addAttributeRunData(entry.getKey(), entry.getValue(), beginRunIndex, endRunIndex); } } @@ -415,8 +417,13 @@ public class AttributedString { private final void createRunAttributeDataVectors() { // use temporary variables so things remain consistent in case of an exception int newRunStarts[] = new int[ARRAY_SIZE_INCREMENT]; - Vector newRunAttributes[] = new Vector[ARRAY_SIZE_INCREMENT]; - Vector newRunAttributeValues[] = new Vector[ARRAY_SIZE_INCREMENT]; + + @SuppressWarnings("unchecked") + Vector newRunAttributes[] = (Vector[]) new Vector[ARRAY_SIZE_INCREMENT]; + + @SuppressWarnings("unchecked") + Vector newRunAttributeValues[] = (Vector[]) new Vector[ARRAY_SIZE_INCREMENT]; + runStarts = newRunStarts; runAttributes = newRunAttributes; runAttributeValues = newRunAttributeValues; @@ -461,8 +468,13 @@ public class AttributedString { if (runCount == runArraySize) { int newArraySize = runArraySize + ARRAY_SIZE_INCREMENT; int newRunStarts[] = new int[newArraySize]; - Vector newRunAttributes[] = new Vector[newArraySize]; - Vector newRunAttributeValues[] = new Vector[newArraySize]; + + @SuppressWarnings("unchecked") + Vector newRunAttributes[] = (Vector[]) new Vector[newArraySize]; + + @SuppressWarnings("unchecked") + Vector newRunAttributeValues[] = (Vector[]) new Vector[newArraySize]; + for (int i = 0; i < runArraySize; i++) { newRunStarts[i] = runStarts[i]; newRunAttributes[i] = runAttributes[i]; @@ -476,17 +488,17 @@ public class AttributedString { // make copies of the attribute information of the old run that the new one used to be part of // use temporary variables so things remain consistent in case of an exception - Vector newRunAttributes = null; - Vector newRunAttributeValues = null; + Vector newRunAttributes = null; + Vector newRunAttributeValues = null; if (copyAttrs) { - Vector oldRunAttributes = runAttributes[runIndex - 1]; - Vector oldRunAttributeValues = runAttributeValues[runIndex - 1]; + Vector oldRunAttributes = runAttributes[runIndex - 1]; + Vector oldRunAttributeValues = runAttributeValues[runIndex - 1]; if (oldRunAttributes != null) { - newRunAttributes = (Vector) oldRunAttributes.clone(); + newRunAttributes = new Vector<>(oldRunAttributes); } if (oldRunAttributeValues != null) { - newRunAttributeValues = (Vector) oldRunAttributeValues.clone(); + newRunAttributeValues = new Vector<>(oldRunAttributeValues); } } @@ -511,8 +523,8 @@ public class AttributedString { for (int i = beginRunIndex; i < endRunIndex; i++) { int keyValueIndex = -1; // index of key and value in our vectors; assume we don't have an entry yet if (runAttributes[i] == null) { - Vector newRunAttributes = new Vector(); - Vector newRunAttributeValues = new Vector(); + Vector newRunAttributes = new Vector<>(); + Vector newRunAttributeValues = new Vector<>(); runAttributes[i] = newRunAttributes; runAttributeValues[i] = newRunAttributeValues; } else { @@ -597,8 +609,8 @@ public class AttributedString { } private synchronized Object getAttribute(Attribute attribute, int runIndex) { - Vector currentRunAttributes = runAttributes[runIndex]; - Vector currentRunAttributeValues = runAttributeValues[runIndex]; + Vector currentRunAttributes = runAttributes[runIndex]; + Vector currentRunAttributeValues = runAttributeValues[runIndex]; if (currentRunAttributes == null) { return null; } @@ -650,10 +662,10 @@ public class AttributedString { } // returns whether all specified attributes have equal values in the runs with the given indices - private boolean attributeValuesMatch(Set attributes, int runIndex1, int runIndex2) { - Iterator iterator = attributes.iterator(); + private boolean attributeValuesMatch(Set attributes, int runIndex1, int runIndex2) { + Iterator iterator = attributes.iterator(); while (iterator.hasNext()) { - Attribute key = (Attribute) iterator.next(); + Attribute key = iterator.next(); if (!valuesMatch(getAttribute(key, runIndex1), getAttribute(key, runIndex2))) { return false; } @@ -690,7 +702,7 @@ public class AttributedString { * (typically the end of the text) to the ones specified in attrs. * This is only meant to be called from the constructor! */ - private void setAttributes(Map attrs, int offset) { + private void setAttributes(Map attrs, int offset) { if (runCount == 0) { createRunAttributeDataVectors(); } @@ -699,12 +711,12 @@ public class AttributedString { int size; if (attrs != null && (size = attrs.size()) > 0) { - Vector runAttrs = new Vector(size); - Vector runValues = new Vector(size); - Iterator iterator = attrs.entrySet().iterator(); + Vector runAttrs = new Vector<>(size); + Vector runValues = new Vector<>(size); + Iterator> iterator = attrs.entrySet().iterator(); while (iterator.hasNext()) { - Map.Entry entry = (Map.Entry)iterator.next(); + Map.Entry entry = iterator.next(); runAttrs.add(entry.getKey()); runValues.add(entry.getValue()); @@ -717,7 +729,7 @@ public class AttributedString { /** * Returns true if the attributes specified in last and attrs differ. */ - private static boolean mapsDiffer(Map last, Map attrs) { + private static boolean mapsDiffer(Map last, Map attrs) { if (last == null) { return (attrs != null && attrs.size() > 0); } @@ -761,7 +773,7 @@ public class AttributedString { this.currentIndex = beginIndex; updateRunInfo(); if (attributes != null) { - relevantAttributes = (Attribute[]) attributes.clone(); + relevantAttributes = attributes.clone(); } } @@ -944,7 +956,7 @@ public class AttributedString { if (runAttributes == null || currentRunIndex == -1 || runAttributes[currentRunIndex] == null) { // ??? would be nice to return null, but current spec doesn't allow it // returning Hashtable saves AttributeMap from dealing with emptiness - return new Hashtable(); + return new Hashtable<>(); } return new AttributeMap(currentRunIndex, beginIndex, endIndex); } @@ -954,16 +966,16 @@ public class AttributedString { if (runAttributes == null) { // ??? would be nice to return null, but current spec doesn't allow it // returning HashSet saves us from dealing with emptiness - return new HashSet(); + return new HashSet<>(); } synchronized (AttributedString.this) { // ??? should try to create this only once, then update if necessary, // and give callers read-only view - Set keys = new HashSet(); + Set keys = new HashSet<>(); int i = 0; while (i < runCount) { if (runStarts[i] < endIndex && (i == runCount - 1 || runStarts[i + 1] > beginIndex)) { - Vector currentRunAttributes = runAttributes[i]; + Vector currentRunAttributes = runAttributes[i]; if (currentRunAttributes != null) { int j = currentRunAttributes.size(); while (j-- > 0) { @@ -1052,12 +1064,12 @@ public class AttributedString { this.endIndex = endIndex; } - public Set entrySet() { - HashSet set = new HashSet(); + public Set> entrySet() { + HashSet> set = new HashSet<>(); synchronized (AttributedString.this) { int size = runAttributes[runIndex].size(); for (int i = 0; i < size; i++) { - Attribute key = (Attribute) runAttributes[runIndex].get(i); + Attribute key = runAttributes[runIndex].get(i); Object value = runAttributeValues[runIndex].get(i); if (value instanceof Annotation) { value = AttributedString.this.getAttributeCheckRange(key, @@ -1066,7 +1078,8 @@ public class AttributedString { continue; } } - Map.Entry entry = new AttributeEntry(key, value); + + Map.Entry entry = new AttributeEntry(key, value); set.add(entry); } } @@ -1079,7 +1092,7 @@ public class AttributedString { } } -class AttributeEntry implements Map.Entry { +class AttributeEntry implements Map.Entry { private Attribute key; private Object value; @@ -1098,7 +1111,7 @@ class AttributeEntry implements Map.Entry { (value == null ? other.value == null : other.value.equals(value)); } - public Object getKey() { + public Attribute getKey() { return key; } diff --git a/src/share/classes/java/text/BreakDictionary.java b/src/share/classes/java/text/BreakDictionary.java index 1e345030a..bc0fcccdf 100644 --- a/src/share/classes/java/text/BreakDictionary.java +++ b/src/share/classes/java/text/BreakDictionary.java @@ -145,9 +145,9 @@ class BreakDictionary { BufferedInputStream in; try { - in = (BufferedInputStream)AccessController.doPrivileged( - new PrivilegedExceptionAction() { - public Object run() throws Exception { + in = AccessController.doPrivileged( + new PrivilegedExceptionAction() { + public BufferedInputStream run() throws Exception { return new BufferedInputStream(getClass().getResourceAsStream("/sun/text/resources/" + dictionaryName)); } } diff --git a/src/share/classes/java/text/BreakIterator.java b/src/share/classes/java/text/BreakIterator.java index 6010784db..7520cd11b 100644 --- a/src/share/classes/java/text/BreakIterator.java +++ b/src/share/classes/java/text/BreakIterator.java @@ -439,7 +439,9 @@ public abstract class BreakIterator implements Cloneable private static final int WORD_INDEX = 1; private static final int LINE_INDEX = 2; private static final int SENTENCE_INDEX = 3; - private static final SoftReference[] iterCache = new SoftReference[4]; + + @SuppressWarnings("unchecked") + private static final SoftReference[] iterCache = (SoftReference[]) new SoftReference[4]; /** * Returns a new BreakIterator instance @@ -554,7 +556,7 @@ public abstract class BreakIterator implements Cloneable String dataName, String dictionaryName) { if (iterCache[type] != null) { - BreakIteratorCache cache = (BreakIteratorCache) iterCache[type].get(); + BreakIteratorCache cache = iterCache[type].get(); if (cache != null) { if (cache.getLocale().equals(locale)) { return cache.createBreakInstance(); @@ -567,13 +569,13 @@ public abstract class BreakIterator implements Cloneable dataName, dictionaryName); BreakIteratorCache cache = new BreakIteratorCache(locale, result); - iterCache[type] = new SoftReference(cache); + iterCache[type] = new SoftReference<>(cache); return result; } private static ResourceBundle getBundle(final String baseName, final Locale locale) { - return (ResourceBundle) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + return AccessController.doPrivileged(new PrivilegedAction() { + public ResourceBundle run() { return ResourceBundle.getBundle(baseName, locale); } }); diff --git a/src/share/classes/java/text/CharacterIteratorFieldDelegate.java b/src/share/classes/java/text/CharacterIteratorFieldDelegate.java index 019bfe79c..284108c59 100644 --- a/src/share/classes/java/text/CharacterIteratorFieldDelegate.java +++ b/src/share/classes/java/text/CharacterIteratorFieldDelegate.java @@ -41,7 +41,7 @@ class CharacterIteratorFieldDelegate implements Format.FieldDelegate { * for existing regions result in invoking addAttribute on the existing * AttributedStrings. */ - private ArrayList attributedStrings; + private ArrayList attributedStrings; /** * Running count of the number of characters that have * been encountered. @@ -50,7 +50,7 @@ class CharacterIteratorFieldDelegate implements Format.FieldDelegate { CharacterIteratorFieldDelegate() { - attributedStrings = new ArrayList(); + attributedStrings = new ArrayList<>(); } public void formatted(Format.Field attr, Object value, int start, int end, @@ -62,7 +62,7 @@ class CharacterIteratorFieldDelegate implements Format.FieldDelegate { int asIndex = attributedStrings.size() - 1; while (start < index) { - AttributedString as = (AttributedString)attributedStrings. + AttributedString as = attributedStrings. get(asIndex--); int newIndex = index - as.length(); int aStart = Math.max(0, start - newIndex); @@ -116,8 +116,8 @@ class CharacterIteratorFieldDelegate implements Format.FieldDelegate { AttributedCharacterIterator[iCount]; for (int counter = 0; counter < iCount; counter++) { - iterators[counter] = ((AttributedString)attributedStrings. - get(counter)).getIterator(); + iterators[counter] = attributedStrings. + get(counter).getIterator(); } return new AttributedString(iterators).getIterator(); } diff --git a/src/share/classes/java/text/ChoiceFormat.java b/src/share/classes/java/text/ChoiceFormat.java index f513cd9de..4d5e00628 100644 --- a/src/share/classes/java/text/ChoiceFormat.java +++ b/src/share/classes/java/text/ChoiceFormat.java @@ -457,8 +457,8 @@ public class ChoiceFormat extends NumberFormat { { ChoiceFormat other = (ChoiceFormat) super.clone(); // for primitives or immutables, shallow clone is enough - other.choiceLimits = (double[]) choiceLimits.clone(); - other.choiceFormats = (String[]) choiceFormats.clone(); + other.choiceLimits = choiceLimits.clone(); + other.choiceFormats = choiceFormats.clone(); return other; } diff --git a/src/share/classes/java/text/CollationElementIterator.java b/src/share/classes/java/text/CollationElementIterator.java index 94fc84e9b..62b6a12c3 100644 --- a/src/share/classes/java/text/CollationElementIterator.java +++ b/src/share/classes/java/text/CollationElementIterator.java @@ -412,6 +412,7 @@ public final class CollationElementIterator * @param newOffset The new character offset into the original text. * @since 1.2 */ + @SuppressWarnings("deprecation") // getBeginIndex, getEndIndex and setIndex are deprecated public void setOffset(int newOffset) { if (text != null) { @@ -645,14 +646,14 @@ public final class CollationElementIterator { // First get the ordering of this single character, // which is always the first element in the list - Vector list = ordering.getContractValues(ch); - EntryPair pair = (EntryPair)list.firstElement(); + Vector list = ordering.getContractValues(ch); + EntryPair pair = list.firstElement(); int order = pair.value; // find out the length of the longest contracting character sequence in the list. // There's logic in the builder code to make sure the longest sequence is always // the last. - pair = (EntryPair)list.lastElement(); + pair = list.lastElement(); int maxLength = pair.entryName.length(); // (the Normalizer is cloned here so that the seeking we do in the next loop @@ -684,7 +685,7 @@ public final class CollationElementIterator // to this sequence maxLength = 1; for (int i = list.size() - 1; i > 0; i--) { - pair = (EntryPair)list.elementAt(i); + pair = list.elementAt(i); if (!pair.fwd) continue; @@ -721,11 +722,11 @@ public final class CollationElementIterator // rather than off. Notice that we still use append() and startsWith() when // working on the fragment. This is because the entry pairs that are used // in reverse iteration have their names reversed already. - Vector list = ordering.getContractValues(ch); - EntryPair pair = (EntryPair)list.firstElement(); + Vector list = ordering.getContractValues(ch); + EntryPair pair = list.firstElement(); int order = pair.value; - pair = (EntryPair)list.lastElement(); + pair = list.lastElement(); int maxLength = pair.entryName.length(); NormalizerBase tempText = (NormalizerBase)text.clone(); @@ -747,7 +748,7 @@ public final class CollationElementIterator maxLength = 1; for (int i = list.size() - 1; i > 0; i--) { - pair = (EntryPair)list.elementAt(i); + pair = list.elementAt(i); if (pair.fwd) continue; diff --git a/src/share/classes/java/text/DateFormat.java b/src/share/classes/java/text/DateFormat.java index 38ef9706b..964fca946 100644 --- a/src/share/classes/java/text/DateFormat.java +++ b/src/share/classes/java/text/DateFormat.java @@ -798,7 +798,7 @@ public abstract class DateFormat extends Format { private static final long serialVersionUID = 7441350119349544720L; // table of all instances in this class, used by readResolve - private static final Map instanceMap = new HashMap(18); + private static final Map instanceMap = new HashMap<>(18); // Maps from Calendar constant (such as Calendar.ERA) to Field // constant (such as Field.ERA). private static final Field[] calendarToFieldMapping = diff --git a/src/share/classes/java/text/DecimalFormat.java b/src/share/classes/java/text/DecimalFormat.java index 3dd9a5be9..2ac67b204 100644 --- a/src/share/classes/java/text/DecimalFormat.java +++ b/src/share/classes/java/text/DecimalFormat.java @@ -2051,7 +2051,7 @@ public class DecimalFormat extends NumberFormat { * @return FieldPosition array of the resulting fields. */ private FieldPosition[] expandAffix(String pattern) { - ArrayList positions = null; + ArrayList positions = null; int stringIndex = 0; for (int i=0; i 0) { if (positions == null) { - positions = new ArrayList(2); + positions = new ArrayList<>(2); } FieldPosition fp = new FieldPosition(Field.CURRENCY); fp.setBeginIndex(stringIndex); @@ -2098,7 +2098,7 @@ public class DecimalFormat extends NumberFormat { } if (fieldID != null) { if (positions == null) { - positions = new ArrayList(2); + positions = new ArrayList<>(2); } FieldPosition fp = new FieldPosition(fieldID, field); fp.setBeginIndex(stringIndex); @@ -2109,7 +2109,7 @@ public class DecimalFormat extends NumberFormat { stringIndex++; } if (positions != null) { - return (FieldPosition[])positions.toArray(EmptyFieldPositionArray); + return positions.toArray(EmptyFieldPositionArray); } return EmptyFieldPositionArray; } diff --git a/src/share/classes/java/text/DictionaryBasedBreakIterator.java b/src/share/classes/java/text/DictionaryBasedBreakIterator.java index 78d7e4a6e..4911eb530 100644 --- a/src/share/classes/java/text/DictionaryBasedBreakIterator.java +++ b/src/share/classes/java/text/DictionaryBasedBreakIterator.java @@ -356,9 +356,9 @@ class DictionaryBasedBreakIterator extends RuleBasedBreakIterator { // continues in this way until we either successfully make it all the way // across the range, or exhaust all of our combinations of break // positions.) - Stack currentBreakPositions = new Stack(); - Stack possibleBreakPositions = new Stack(); - Vector wrongBreakPositions = new Vector(); + Stack currentBreakPositions = new Stack<>(); + Stack possibleBreakPositions = new Stack<>(); + Vector wrongBreakPositions = new Vector<>(); // the dictionary is implemented as a trie, which is treated as a state // machine. -1 represents the end of a legal word. Every word in the @@ -374,7 +374,7 @@ class DictionaryBasedBreakIterator extends RuleBasedBreakIterator { // farthest as real break positions, and then start over from scratch with // the character where the error occurred. int farthestEndPoint = text.getIndex(); - Stack bestBreakPositions = null; + Stack bestBreakPositions = null; // initialize (we always exit the loop with a break statement) c = getCurrent(); @@ -409,7 +409,11 @@ class DictionaryBasedBreakIterator extends RuleBasedBreakIterator { // case there's an error in the text if (text.getIndex() > farthestEndPoint) { farthestEndPoint = text.getIndex(); - bestBreakPositions = (Stack)(currentBreakPositions.clone()); + + @SuppressWarnings("unchecked") + Stack currentBreakPositionsCopy = (Stack) currentBreakPositions.clone(); + + bestBreakPositions = currentBreakPositionsCopy; } // wrongBreakPositions is a list of all break positions @@ -448,7 +452,7 @@ class DictionaryBasedBreakIterator extends RuleBasedBreakIterator { } else { if ((currentBreakPositions.size() == 0 || - ((Integer)(currentBreakPositions.peek())).intValue() != text.getIndex()) + currentBreakPositions.peek().intValue() != text.getIndex()) && text.getIndex() != startPos) { currentBreakPositions.push(new Integer(text.getIndex())); } @@ -463,15 +467,15 @@ class DictionaryBasedBreakIterator extends RuleBasedBreakIterator { // it. Then back up to that position and start over from there (i.e., // treat that position as the beginning of a new word) else { - Integer temp = (Integer)possibleBreakPositions.pop(); - Object temp2 = null; + Integer temp = possibleBreakPositions.pop(); + Integer temp2 = null; while (!currentBreakPositions.isEmpty() && temp.intValue() < - ((Integer)currentBreakPositions.peek()).intValue()) { + currentBreakPositions.peek().intValue()) { temp2 = currentBreakPositions.pop(); wrongBreakPositions.addElement(temp2); } currentBreakPositions.push(temp); - text.setIndex(((Integer)currentBreakPositions.peek()).intValue()); + text.setIndex(currentBreakPositions.peek().intValue()); } // re-sync "c" for the next go-round, and drop out of the loop if @@ -507,7 +511,7 @@ class DictionaryBasedBreakIterator extends RuleBasedBreakIterator { cachedBreakPositions[0] = startPos; for (int i = 0; i < currentBreakPositions.size(); i++) { - cachedBreakPositions[i + 1] = ((Integer)currentBreakPositions.elementAt(i)).intValue(); + cachedBreakPositions[i + 1] = currentBreakPositions.elementAt(i).intValue(); } positionInCache = 0; } diff --git a/src/share/classes/java/text/MergeCollation.java b/src/share/classes/java/text/MergeCollation.java index d764f03d2..1a07fe517 100644 --- a/src/share/classes/java/text/MergeCollation.java +++ b/src/share/classes/java/text/MergeCollation.java @@ -88,19 +88,19 @@ final class MergeCollation { public String getPattern(boolean withWhiteSpace) { StringBuffer result = new StringBuffer(); PatternEntry tmp = null; - ArrayList extList = null; + ArrayList extList = null; int i; for (i = 0; i < patterns.size(); ++i) { - PatternEntry entry = (PatternEntry) patterns.get(i); + PatternEntry entry = patterns.get(i); if (entry.extension.length() != 0) { if (extList == null) - extList = new ArrayList(); + extList = new ArrayList<>(); extList.add(entry); } else { if (extList != null) { PatternEntry last = findLastWithNoExtension(i-1); for (int j = extList.size() - 1; j >= 0 ; j--) { - tmp = (PatternEntry)(extList.get(j)); + tmp = extList.get(j); tmp.addToBuffer(result, false, withWhiteSpace, last); } extList = null; @@ -111,7 +111,7 @@ final class MergeCollation { if (extList != null) { PatternEntry last = findLastWithNoExtension(i-1); for (int j = extList.size() - 1; j >= 0 ; j--) { - tmp = (PatternEntry)(extList.get(j)); + tmp = extList.get(j); tmp.addToBuffer(result, false, withWhiteSpace, last); } extList = null; @@ -121,7 +121,7 @@ final class MergeCollation { private final PatternEntry findLastWithNoExtension(int i) { for (--i;i >= 0; --i) { - PatternEntry entry = (PatternEntry) patterns.get(i); + PatternEntry entry = patterns.get(i); if (entry.extension.length() == 0) { return entry; } @@ -149,7 +149,7 @@ final class MergeCollation { StringBuffer result = new StringBuffer(); for (int i = 0; i < patterns.size(); ++i) { - PatternEntry entry = (PatternEntry) patterns.get(i); + PatternEntry entry = patterns.get(i); if (entry != null) { entry.addToBuffer(result, true, withWhiteSpace, null); } @@ -198,13 +198,13 @@ final class MergeCollation { * @return the requested pattern entry */ public PatternEntry getItemAt(int index) { - return (PatternEntry) patterns.get(index); + return patterns.get(index); } //============================================================ // privates //============================================================ - ArrayList patterns = new ArrayList(); // a list of PatternEntries + ArrayList patterns = new ArrayList<>(); // a list of PatternEntries private transient PatternEntry saveEntry = null; private transient PatternEntry lastEntry = null; @@ -326,7 +326,7 @@ final class MergeCollation { } else { int i; for (i = patterns.size() - 1; i >= 0; --i) { - PatternEntry e = (PatternEntry) patterns.get(i); + PatternEntry e = patterns.get(i); if (e.chars.regionMatches(0,entry.chars,0, e.chars.length())) { excessChars.append(entry.chars.substring(e.chars.length(), diff --git a/src/share/classes/java/text/MessageFormat.java b/src/share/classes/java/text/MessageFormat.java index 6590e7677..0b7b1faa6 100644 --- a/src/share/classes/java/text/MessageFormat.java +++ b/src/share/classes/java/text/MessageFormat.java @@ -422,6 +422,7 @@ public class MessageFormat extends Format { * @param pattern the pattern for this message format * @exception IllegalArgumentException if the pattern is invalid */ + @SuppressWarnings("fallthrough") // fallthrough in switch is expected, suppress it public void applyPattern(String pattern) { StringBuilder[] segments = new StringBuilder[4]; // Allocate only segments[SEG_RAW] here. The rest are @@ -897,7 +898,7 @@ public class MessageFormat extends Format { */ public AttributedCharacterIterator formatToCharacterIterator(Object arguments) { StringBuffer result = new StringBuffer(); - ArrayList iterators = new ArrayList(); + ArrayList iterators = new ArrayList<>(); if (arguments == null) { throw new NullPointerException( @@ -908,7 +909,7 @@ public class MessageFormat extends Format { return createAttributedCharacterIterator(""); } return createAttributedCharacterIterator( - (AttributedCharacterIterator[])iterators.toArray( + iterators.toArray( new AttributedCharacterIterator[iterators.size()])); } @@ -1074,14 +1075,14 @@ public class MessageFormat extends Format { MessageFormat other = (MessageFormat) super.clone(); // clone arrays. Can't do with utility because of bug in Cloneable - other.formats = (Format[]) formats.clone(); // shallow clone + other.formats = formats.clone(); // shallow clone for (int i = 0; i < formats.length; ++i) { if (formats[i] != null) other.formats[i] = (Format)formats[i].clone(); } // for primitives or immutables, shallow clone is enough - other.offsets = (int[]) offsets.clone(); - other.argumentNumbers = (int[]) argumentNumbers.clone(); + other.offsets = offsets.clone(); + other.argumentNumbers = argumentNumbers.clone(); return other; } @@ -1224,7 +1225,7 @@ public class MessageFormat extends Format { * expected by the format element(s) that use it. */ private StringBuffer subformat(Object[] arguments, StringBuffer result, - FieldPosition fp, List characterIterators) { + FieldPosition fp, List characterIterators) { // note: this implementation assumes a fast substring & index. // if this is not true, would be better to append chars one by one. int lastOffset = 0; diff --git a/src/share/classes/java/text/NumberFormat.java b/src/share/classes/java/text/NumberFormat.java index 59f8e1fc0..43dfea48f 100644 --- a/src/share/classes/java/text/NumberFormat.java +++ b/src/share/classes/java/text/NumberFormat.java @@ -756,7 +756,7 @@ public abstract class NumberFormat extends Format { } /* try the cache first */ - String[] numberPatterns = (String[])cachedLocaleData.get(desiredLocale); + String[] numberPatterns = cachedLocaleData.get(desiredLocale); if (numberPatterns == null) { /* cache miss */ ResourceBundle resource = LocaleData.getNumberFormatData(desiredLocale); numberPatterns = resource.getStringArray("NumberPatterns"); @@ -844,7 +844,7 @@ public abstract class NumberFormat extends Format { /** * Cache to hold the NumberPatterns of a Locale. */ - private static final Hashtable cachedLocaleData = new Hashtable(3); + private static final Hashtable cachedLocaleData = new Hashtable<>(3); // Constants used by factory methods to specify a style of format. private static final int NUMBERSTYLE = 0; @@ -1035,7 +1035,7 @@ public abstract class NumberFormat extends Format { private static final long serialVersionUID = 7494728892700160890L; // table of all instances in this class, used by readResolve - private static final Map instanceMap = new HashMap(11); + private static final Map instanceMap = new HashMap<>(11); /** * Creates a Field instance with the specified diff --git a/src/share/classes/java/text/ParseException.java b/src/share/classes/java/text/ParseException.java index ee0fd5c21..abcebfd35 100644 --- a/src/share/classes/java/text/ParseException.java +++ b/src/share/classes/java/text/ParseException.java @@ -49,6 +49,8 @@ package java.text; public class ParseException extends Exception { + private static final long serialVersionUID = 2703218443322787634L; + /** * Constructs a ParseException with the specified detail message and * offset. diff --git a/src/share/classes/java/text/RBCollationTables.java b/src/share/classes/java/text/RBCollationTables.java index 321e1c1d4..aa349e68d 100644 --- a/src/share/classes/java/text/RBCollationTables.java +++ b/src/share/classes/java/text/RBCollationTables.java @@ -112,8 +112,8 @@ final class RBCollationTables { void fillInTables(boolean f2ary, boolean swap, UCompactIntArray map, - Vector cTbl, - Vector eTbl, + Vector> cTbl, + Vector eTbl, IntHashtable cFlgs, short mso, short mto) { @@ -155,18 +155,18 @@ final class RBCollationTables { * table. * @param ch the starting character of the contracting string */ - Vector getContractValues(int ch) + Vector getContractValues(int ch) { int index = mapping.elementAt(ch); return getContractValuesImpl(index - CONTRACTCHARINDEX); } //get contract values from contractTable by index - private Vector getContractValuesImpl(int index) + private Vector getContractValuesImpl(int index) { if (index >= 0) { - return (Vector)contractTable.elementAt(index); + return contractTable.elementAt(index); } else // not found { @@ -202,7 +202,7 @@ final class RBCollationTables { // this could cause a performance problem, but in practise that // rarely happens for (int i = 0; i < expandTable.size(); i++) { - int[] valueList = (int [])expandTable.elementAt(i); + int[] valueList = expandTable.elementAt(i); int length = valueList.length; if (length > result && valueList[length-1] == order) { @@ -220,7 +220,7 @@ final class RBCollationTables { * @param idx the index of the expanding string value list */ final int[] getExpandValueList(int order) { - return (int[])expandTable.elementAt(order - EXPANDCHARINDEX); + return expandTable.elementAt(order - EXPANDCHARINDEX); } /** @@ -260,9 +260,9 @@ final class RBCollationTables { } } - final static int getEntry(Vector list, String name, boolean fwd) { + final static int getEntry(Vector list, String name, boolean fwd) { for (int i = 0; i < list.size(); i++) { - EntryPair pair = (EntryPair)list.elementAt(i); + EntryPair pair = list.elementAt(i); if (pair.fwd == fwd && pair.entryName.equals(name)) { return i; } @@ -294,8 +294,8 @@ final class RBCollationTables { private boolean seAsianSwapping = false; private UCompactIntArray mapping = null; - private Vector contractTable = null; - private Vector expandTable = null; + private Vector> contractTable = null; + private Vector expandTable = null; private IntHashtable contractFlags = null; private short maxSecOrder = 0; diff --git a/src/share/classes/java/text/RBTableBuilder.java b/src/share/classes/java/text/RBTableBuilder.java index fe35ab51a..a78872949 100644 --- a/src/share/classes/java/text/RBTableBuilder.java +++ b/src/share/classes/java/text/RBTableBuilder.java @@ -85,7 +85,7 @@ final class RBTableBuilder { throw new ParseException("Build rules empty.", 0); // This array maps Unicode characters to their collation ordering - mapping = new UCompactIntArray((int)RBCollationTables.UNMAPPED); + mapping = new UCompactIntArray(RBCollationTables.UNMAPPED); // Normalize the build rules. Find occurances of all decomposed characters // and normalize the rules before feeding into the builder. By "normalize", // we mean that all precomposed Unicode characters must be converted into @@ -263,7 +263,7 @@ final class RBTableBuilder { { if (expandTable != null) { for (int i = 0; i < expandTable.size(); i++) { - int[] valueList = (int [])expandTable.elementAt(i); + int[] valueList = expandTable.elementAt(i); for (int j = 0; j < valueList.length; j++) { int order = valueList[j]; if (order < RBCollationTables.EXPANDCHARINDEX && order > CHARINDEX) { @@ -354,7 +354,7 @@ final class RBTableBuilder { boolean fwd) { if (contractTable == null) { - contractTable = new Vector(INITIALTABLESIZE); + contractTable = new Vector<>(INITIALTABLESIZE); } //initial character @@ -366,12 +366,12 @@ final class RBTableBuilder { */ // See if the initial character of the string already has a contract table. int entry = mapping.elementAt(ch); - Vector entryTable = getContractValuesImpl(entry - RBCollationTables.CONTRACTCHARINDEX); + Vector entryTable = getContractValuesImpl(entry - RBCollationTables.CONTRACTCHARINDEX); if (entryTable == null) { // We need to create a new table of contract entries for this base char int tableIndex = RBCollationTables.CONTRACTCHARINDEX + contractTable.size(); - entryTable = new Vector(INITIALTABLESIZE); + entryTable = new Vector<>(INITIALTABLESIZE); contractTable.addElement(entryTable); // Add the initial character's current ordering first. then @@ -383,10 +383,10 @@ final class RBTableBuilder { // Now add (or replace) this string in the table int index = RBCollationTables.getEntry(entryTable, groupChars, fwd); if (index != RBCollationTables.UNMAPPED) { - EntryPair pair = (EntryPair) entryTable.elementAt(index); + EntryPair pair = entryTable.elementAt(index); pair.value = anOrder; } else { - EntryPair pair = (EntryPair)entryTable.lastElement(); + EntryPair pair = entryTable.lastElement(); // NOTE: This little bit of logic is here to speed CollationElementIterator // .nextContractChar(). This code ensures that the longest sequence in @@ -426,11 +426,11 @@ final class RBTableBuilder { int ch = Character.isHighSurrogate(ch0)? Character.toCodePoint(ch0, groupChars.charAt(1)):ch0; */ - Vector entryTable = getContractValues(ch); + Vector entryTable = getContractValues(ch); if (entryTable != null) { int index = RBCollationTables.getEntry(entryTable, groupChars, true); if (index != RBCollationTables.UNMAPPED) { - EntryPair pair = (EntryPair) entryTable.elementAt(index); + EntryPair pair = entryTable.elementAt(index); result = pair.value; } } @@ -442,8 +442,8 @@ final class RBTableBuilder { int order = mapping.elementAt(ch); if (order >= RBCollationTables.CONTRACTCHARINDEX) { - Vector groupList = getContractValuesImpl(order - RBCollationTables.CONTRACTCHARINDEX); - EntryPair pair = (EntryPair)groupList.firstElement(); + Vector groupList = getContractValuesImpl(order - RBCollationTables.CONTRACTCHARINDEX); + EntryPair pair = groupList.firstElement(); order = pair.value; } return order; @@ -454,17 +454,17 @@ final class RBTableBuilder { * table. * @param ch the starting character of the contracting string */ - private Vector getContractValues(int ch) + private Vector getContractValues(int ch) { int index = mapping.elementAt(ch); return getContractValuesImpl(index - RBCollationTables.CONTRACTCHARINDEX); } - private Vector getContractValuesImpl(int index) + private Vector getContractValuesImpl(int index) { if (index >= 0) { - return (Vector)contractTable.elementAt(index); + return contractTable.elementAt(index); } else // not found { @@ -513,7 +513,7 @@ final class RBTableBuilder { */ private int addExpansion(int anOrder, String expandChars) { if (expandTable == null) { - expandTable = new Vector(INITIALTABLESIZE); + expandTable = new Vector<>(INITIALTABLESIZE); } // If anOrder is valid, we want to add it at the beginning of the list @@ -610,8 +610,8 @@ final class RBTableBuilder { private boolean seAsianSwapping = false; private UCompactIntArray mapping = null; - private Vector contractTable = null; - private Vector expandTable = null; + private Vector> contractTable = null; + private Vector expandTable = null; private short maxSecOrder = 0; private short maxTerOrder = 0; diff --git a/src/share/classes/java/text/RuleBasedBreakIterator.java b/src/share/classes/java/text/RuleBasedBreakIterator.java index 201eee71a..7f1c1b8a9 100644 --- a/src/share/classes/java/text/RuleBasedBreakIterator.java +++ b/src/share/classes/java/text/RuleBasedBreakIterator.java @@ -444,9 +444,9 @@ class RuleBasedBreakIterator extends BreakIterator { BufferedInputStream is; try { - is = (BufferedInputStream)AccessController.doPrivileged( - new PrivilegedExceptionAction() { - public Object run() throws Exception { + is = AccessController.doPrivileged( + new PrivilegedExceptionAction() { + public BufferedInputStream run() throws Exception { return new BufferedInputStream(getClass().getResourceAsStream("/sun/text/resources/" + datafile)); } } -- GitLab