diff options
Diffstat (limited to 'libjava/classpath/gnu/java/text/FormatCharacterIterator.java')
-rw-r--r-- | libjava/classpath/gnu/java/text/FormatCharacterIterator.java | 270 |
1 files changed, 135 insertions, 135 deletions
diff --git a/libjava/classpath/gnu/java/text/FormatCharacterIterator.java b/libjava/classpath/gnu/java/text/FormatCharacterIterator.java index 60773aa1eb7..889394ca451 100644 --- a/libjava/classpath/gnu/java/text/FormatCharacterIterator.java +++ b/libjava/classpath/gnu/java/text/FormatCharacterIterator.java @@ -1,4 +1,4 @@ -/* FormatCharacter.java -- Implementation of AttributedCharacterIterator for +/* FormatCharacter.java -- Implementation of AttributedCharacterIterator for formatters. Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004, 2005 Free Software Foundation, Inc. @@ -8,7 +8,7 @@ GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + GNU Classpath 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 @@ -78,7 +78,7 @@ public class FormatCharacterIterator implements AttributedCharacterIterator } /** - * This constructor take a string <code>s</code>, a set of ranges + * This constructor take a string <code>s</code>, a set of ranges * and the corresponding attributes. This is used to build an iterator. * The array <code>ranges</code> should be formatted as follow: * each element of <code>ranges</code> specifies the index in the string @@ -98,10 +98,10 @@ public class FormatCharacterIterator implements AttributedCharacterIterator this.ranges = ranges; this.attributes = attributes; } - - /* + + /* * The following methods are inherited from AttributedCharacterIterator, - * and thus are already documented. + * and thus are already documented. */ public Set getAllAttributeKeys() @@ -111,7 +111,7 @@ public class FormatCharacterIterator implements AttributedCharacterIterator else return new HashSet(); } - + public Map getAttributes() { if (attributes != null && attributes[attributeIndex] != null) @@ -119,7 +119,7 @@ public class FormatCharacterIterator implements AttributedCharacterIterator else return new HashMap(); } - + public Object getAttribute (AttributedCharacterIterator.Attribute attrib) { if (attributes != null && attributes[attributeIndex] != null) @@ -127,7 +127,7 @@ public class FormatCharacterIterator implements AttributedCharacterIterator else return null; } - + public int getRunLimit(Set reqAttrs) { if (attributes == null) @@ -138,19 +138,19 @@ public class FormatCharacterIterator implements AttributedCharacterIterator do { - currentAttrIndex++; - if (currentAttrIndex == attributes.length) - return formattedString.length(); - if (attributes[currentAttrIndex] == null) - break; - newKeys = attributes[currentAttrIndex].keySet(); + currentAttrIndex++; + if (currentAttrIndex == attributes.length) + return formattedString.length(); + if (attributes[currentAttrIndex] == null) + break; + newKeys = attributes[currentAttrIndex].keySet(); } while (newKeys.containsAll (reqAttrs)); return ranges[currentAttrIndex-1]; } - - public int getRunLimit (AttributedCharacterIterator.Attribute attribute) + + public int getRunLimit (AttributedCharacterIterator.Attribute attribute) { Set s = new HashSet(); @@ -164,38 +164,38 @@ public class FormatCharacterIterator implements AttributedCharacterIterator return formattedString.length(); if (attributes[attributeIndex] == null) { - for (int i=attributeIndex+1;i<attributes.length;i++) - if (attributes[i] != null) - return ranges[i-1]; - return formattedString.length(); + for (int i=attributeIndex+1;i<attributes.length;i++) + if (attributes[i] != null) + return ranges[i-1]; + return formattedString.length(); } return getRunLimit (attributes[attributeIndex].keySet()); } - + public int getRunStart (Set reqAttrs) { if (attributes == null) return formattedString.length(); - + int currentAttrIndex = attributeIndex; Set newKeys = null; do { - if (currentAttrIndex == 0) - return 0; + if (currentAttrIndex == 0) + return 0; - currentAttrIndex--; - if (attributes[currentAttrIndex] == null) - break; - newKeys = attributes[currentAttrIndex].keySet(); + currentAttrIndex--; + if (attributes[currentAttrIndex] == null) + break; + newKeys = attributes[currentAttrIndex].keySet(); } while (newKeys.containsAll (reqAttrs)); - + return (currentAttrIndex > 0) ? ranges[currentAttrIndex-1] : 0; - } - + } + public int getRunStart() { if (attributes == null) @@ -203,19 +203,19 @@ public class FormatCharacterIterator implements AttributedCharacterIterator if (attributes[attributeIndex] == null) { - for (int i=attributeIndex;i>0;i--) - if (attributes[i] != null) - return ranges[attributeIndex-1]; - return 0; + for (int i=attributeIndex;i>0;i--) + if (attributes[i] != null) + return ranges[attributeIndex-1]; + return 0; } return getRunStart (attributes[attributeIndex].keySet()); } - - public int getRunStart (AttributedCharacterIterator.Attribute attribute) + + public int getRunStart (AttributedCharacterIterator.Attribute attribute) { Set s = new HashSet(); - + s.add (attribute); return getRunStart (s); } @@ -224,7 +224,7 @@ public class FormatCharacterIterator implements AttributedCharacterIterator { return new FormatCharacterIterator (formattedString, ranges, attributes); } - + /* * The following methods are inherited from CharacterIterator and thus * are already documented. @@ -234,29 +234,29 @@ public class FormatCharacterIterator implements AttributedCharacterIterator { return formattedString.charAt (charIndex); } - + public char first() { charIndex = 0; attributeIndex = 0; return formattedString.charAt (0); } - + public int getBeginIndex() { return 0; } - + public int getEndIndex() { return formattedString.length(); } - + public int getIndex() { return charIndex; } - + public char last() { charIndex = formattedString.length()-1; @@ -264,53 +264,53 @@ public class FormatCharacterIterator implements AttributedCharacterIterator attributeIndex = attributes.length-1; return formattedString.charAt (charIndex); } - + public char next() { charIndex++; if (charIndex >= formattedString.length()) { - charIndex = getEndIndex(); - return DONE; + charIndex = getEndIndex(); + return DONE; } if (attributes != null) { - if (charIndex >= ranges[attributeIndex]) - attributeIndex++; + if (charIndex >= ranges[attributeIndex]) + attributeIndex++; } return formattedString.charAt (charIndex); } - + public char previous() { charIndex--; if (charIndex < 0) { - charIndex = 0; - return DONE; + charIndex = 0; + return DONE; } - + if (attributes != null) { - if (charIndex < ranges[attributeIndex]) - attributeIndex--; + if (charIndex < ranges[attributeIndex]) + attributeIndex--; } return formattedString.charAt (charIndex); } - + public char setIndex (int position) { if (position < 0 || position > formattedString.length()) throw new IllegalArgumentException ("position is out of range"); - + charIndex = position; if (attributes != null) { - for (attributeIndex=0;attributeIndex<attributes.length; - attributeIndex++) - if (ranges[attributeIndex] > charIndex) - break; - attributeIndex--; + for (attributeIndex=0;attributeIndex<attributes.length; + attributeIndex++) + if (ranges[attributeIndex] > charIndex) + break; + attributeIndex--; } if (charIndex == formattedString.length()) return DONE; @@ -334,64 +334,64 @@ public class FormatCharacterIterator implements AttributedCharacterIterator int i = 0, j = 0; debug("merging " + attributes.length + " attrs"); - + while (i < this.ranges.length && j < ranges.length) { - if (this.attributes[i] != null) - { - new_attributes.add (this.attributes[i]); - if (attributes[j] != null) - this.attributes[i].putAll (attributes[j]); - } - else - { - new_attributes.add (attributes[j]); - } - if (this.ranges[i] == ranges[j]) - { - new_ranges.add (new Integer (ranges[j])); - i++; - j++; - } - else if (this.ranges[i] < ranges[j]) - { - new_ranges.add (new Integer (this.ranges[i])); - i++; - } - else - { - new_ranges.add (new Integer (ranges[j])); - j++; - } + if (this.attributes[i] != null) + { + new_attributes.add (this.attributes[i]); + if (attributes[j] != null) + this.attributes[i].putAll (attributes[j]); + } + else + { + new_attributes.add (attributes[j]); + } + if (this.ranges[i] == ranges[j]) + { + new_ranges.add (new Integer (ranges[j])); + i++; + j++; + } + else if (this.ranges[i] < ranges[j]) + { + new_ranges.add (new Integer (this.ranges[i])); + i++; + } + else + { + new_ranges.add (new Integer (ranges[j])); + j++; + } } - + if (i != this.ranges.length) { - for (;i<this.ranges.length;i++) - { - new_attributes.add (this.attributes[i]); - new_ranges.add (new Integer (this.ranges[i])); - } + for (;i<this.ranges.length;i++) + { + new_attributes.add (this.attributes[i]); + new_ranges.add (new Integer (this.ranges[i])); + } } if (j != ranges.length) { - for (;j<ranges.length;j++) - { - new_attributes.add (attributes[j]); - new_ranges.add (new Integer (ranges[j])); - } + for (;j<ranges.length;j++) + { + new_attributes.add (attributes[j]); + new_ranges.add (new Integer (ranges[j])); + } } this.attributes = new HashMap[new_attributes.size()]; this.ranges = new int[new_ranges.size()]; System.arraycopy (new_attributes.toArray(), 0, this.attributes, - 0, this.attributes.length); + 0, this.attributes.length); for (i=0;i<new_ranges.size();i++) { - this.ranges[i] = ((Integer)new_ranges.elementAt (i)).intValue(); + this.ranges[i] = ((Integer)new_ranges.elementAt (i)).intValue(); } - + dumpTable(); } @@ -410,22 +410,22 @@ public class FormatCharacterIterator implements AttributedCharacterIterator do { - formattedString = formattedString + String.valueOf (c); - // TODO: Reduce the size of the output array. - more_attributes.add (iterator.getAttributes()); - more_ranges.add (new Integer (formattedString.length())); - // END TOOD - c = iterator.next(); - } + formattedString = formattedString + String.valueOf (c); + // TODO: Reduce the size of the output array. + more_attributes.add (iterator.getAttributes()); + more_ranges.add (new Integer (formattedString.length())); + // END TOOD + c = iterator.next(); + } while (c != DONE); HashMap[] new_attributes = new HashMap[attributes.length - + more_attributes.size()]; + + more_attributes.size()]; int[] new_ranges = new int[ranges.length + more_ranges.size()]; - + System.arraycopy (attributes, 0, new_attributes, 0, attributes.length); System.arraycopy (more_attributes.toArray(), 0, new_attributes, - attributes.length, more_attributes.size()); + attributes.length, more_attributes.size()); System.arraycopy (ranges, 0, new_ranges, 0, ranges.length); Object[] new_ranges_array = more_ranges.toArray(); @@ -458,7 +458,7 @@ public class FormatCharacterIterator implements AttributedCharacterIterator ranges = new_ranges; attributes = new_attributes; - } + } /** * This method appends a string without attributes. It is completely @@ -470,7 +470,7 @@ public class FormatCharacterIterator implements AttributedCharacterIterator public void append (String text) { append (text, null); - } + } /** * This method adds a set of attributes to a range of character. The @@ -481,7 +481,7 @@ public class FormatCharacterIterator implements AttributedCharacterIterator * @param range_start Lower bound of the range of characters which will receive the * attribute. * @param range_end Upper bound of the range of characters which will receive the - * attribute. + * attribute. * * @throws IllegalArgumentException if ranges are out of bounds. */ @@ -502,30 +502,30 @@ public class FormatCharacterIterator implements AttributedCharacterIterator private void dumpTable() { int start_range = 0; - + if (!DEBUG) return; System.out.println("Dumping internal table:"); for (int i = 0; i < ranges.length; i++) { - System.out.print("\t" + start_range + " => " + ranges[i] + ":"); - if (attributes[i] == null) - System.out.println("null"); - else - { - Set keyset = attributes[i].keySet(); - if (keyset != null) - { - Iterator keys = keyset.iterator(); - - while (keys.hasNext()) - System.out.print(" " + keys.next()); - } - else - System.out.println("keySet null"); - System.out.println(); - } + System.out.print("\t" + start_range + " => " + ranges[i] + ":"); + if (attributes[i] == null) + System.out.println("null"); + else + { + Set keyset = attributes[i].keySet(); + if (keyset != null) + { + Iterator keys = keyset.iterator(); + + while (keys.hasNext()) + System.out.print(" " + keys.next()); + } + else + System.out.println("keySet null"); + System.out.println(); + } } System.out.println(); System.out.flush(); |