aboutsummaryrefslogtreecommitdiff
path: root/libjava/classpath/gnu/java/text/AttributedFormatBuffer.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/classpath/gnu/java/text/AttributedFormatBuffer.java')
-rw-r--r--libjava/classpath/gnu/java/text/AttributedFormatBuffer.java61
1 files changed, 32 insertions, 29 deletions
diff --git a/libjava/classpath/gnu/java/text/AttributedFormatBuffer.java b/libjava/classpath/gnu/java/text/AttributedFormatBuffer.java
index 2a89ae0972e..3633be92017 100644
--- a/libjava/classpath/gnu/java/text/AttributedFormatBuffer.java
+++ b/libjava/classpath/gnu/java/text/AttributedFormatBuffer.java
@@ -1,5 +1,5 @@
/* AttributedFormatBuffer.java -- Implements an attributed FormatBuffer.
- Copyright (C) 2004 Free Software Foundation, Inc.
+ Copyright (C) 2004, 2012 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -41,6 +41,10 @@ import gnu.java.lang.CPStringBuilder;
import java.text.AttributedCharacterIterator;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static java.text.AttributedCharacterIterator.Attribute;
/**
* This class is an implementation of a FormatBuffer with attributes.
@@ -53,12 +57,12 @@ import java.util.HashMap;
public class AttributedFormatBuffer implements FormatBuffer
{
private final CPStringBuilder buffer;
- private final ArrayList ranges;
- private final ArrayList attributes;
- private int[] a_ranges;
- private HashMap[] a_attributes;
+ private final ArrayList<Integer> ranges;
+ private final ArrayList<Map<Attribute,Object>> attributes;
+ private int[] aRanges;
+ private List<Map<Attribute,Object>> aAttributes;
private int startingRange;
- AttributedCharacterIterator.Attribute defaultAttr;
+ Attribute defaultAttr;
/**
* This constructor accepts a StringBuffer. If the buffer contains
@@ -67,8 +71,8 @@ public class AttributedFormatBuffer implements FormatBuffer
public AttributedFormatBuffer(CPStringBuilder buffer)
{
this.buffer = new CPStringBuilder(buffer);
- this.ranges = new ArrayList();
- this.attributes = new ArrayList();
+ this.ranges = new ArrayList<Integer>();
+ this.attributes = new ArrayList<Map<Attribute,Object>>();
this.defaultAttr = null;
if (buffer.length() != 0)
{
@@ -94,23 +98,23 @@ public class AttributedFormatBuffer implements FormatBuffer
* and attributes it adds exactly one attribute for the range of characters
* comprised between the last entry in 'ranges' and the specified new range.
*
- * @param new_range A new range to insert in the list.
+ * @param newRange A new range to insert in the list.
* @param attr A new attribute to insert in the list.
*/
- private final void addAttribute(int new_range, AttributedCharacterIterator.Attribute attr)
+ private final void addAttribute(int newRange, Attribute attr)
{
- HashMap map;
+ Map<Attribute,Object> map;
if (attr != null)
{
- map = new HashMap();
+ map = new HashMap<Attribute,Object>();
map.put(attr, attr);
attributes.add(map);
}
else
attributes.add(null);
- ranges.add(new Integer(new_range));
+ ranges.add(Integer.valueOf(newRange));
}
public void append(String s)
@@ -120,7 +124,7 @@ public class AttributedFormatBuffer implements FormatBuffer
buffer.append(s);
}
- public void append(String s, AttributedCharacterIterator.Attribute attr)
+ public void append(String s, Attribute attr)
{
setDefaultAttribute(attr);
startingRange = buffer.length();
@@ -128,7 +132,7 @@ public class AttributedFormatBuffer implements FormatBuffer
setDefaultAttribute(null);
}
- public void append(String s, int[] ranges, HashMap[] attrs)
+ public void append(String s, int[] ranges, List<Map<Attribute,Object>> attrs)
{
int curPos = buffer.length();
@@ -137,8 +141,8 @@ public class AttributedFormatBuffer implements FormatBuffer
{
for (int i = 0; i < ranges.length; i++)
{
- this.ranges.add(new Integer(ranges[i] + curPos));
- this.attributes.add(attrs[i]);
+ this.ranges.add(Integer.valueOf(ranges[i] + curPos));
+ this.attributes.add(attrs.get(i));
}
}
startingRange = buffer.length();
@@ -152,14 +156,14 @@ public class AttributedFormatBuffer implements FormatBuffer
buffer.append(c);
}
- public void append(char c, AttributedCharacterIterator.Attribute attr)
+ public void append(char c, Attribute attr)
{
setDefaultAttribute(attr);
buffer.append(c);
setDefaultAttribute(null);
}
- public void setDefaultAttribute(AttributedCharacterIterator.Attribute attr)
+ public void setDefaultAttribute(Attribute attr)
{
if (attr == defaultAttr)
return;
@@ -174,7 +178,7 @@ public class AttributedFormatBuffer implements FormatBuffer
startingRange = currentPos;
}
- public AttributedCharacterIterator.Attribute getDefaultAttribute()
+ public Attribute getDefaultAttribute()
{
return defaultAttr;
}
@@ -209,12 +213,11 @@ public class AttributedFormatBuffer implements FormatBuffer
addAttribute(buffer.length(), defaultAttr);
- a_ranges = new int[ranges.size()];
- for (int i = 0; i < a_ranges.length; i++)
- a_ranges[i] = ((Integer)(ranges.get (i))).intValue();
+ aRanges = new int[ranges.size()];
+ for (int i = 0; i < aRanges.length; i++)
+ aRanges[i] = ranges.get (i).intValue();
- a_attributes = new HashMap[attributes.size()];
- System.arraycopy(attributes.toArray(), 0, a_attributes, 0, a_attributes.length);
+ aAttributes = new ArrayList<Map<Attribute,Object>>(attributes);
}
/**
@@ -235,17 +238,17 @@ public class AttributedFormatBuffer implements FormatBuffer
*/
public int[] getRanges()
{
- return a_ranges;
+ return aRanges;
}
/**
* This method returns the array containing the map on the
* attributes.
*
- * @return An array of {@link java.util.Map} containing the attributes.
+ * @return A {@link java.util.List} of {@link java.util.Map}s containing the attributes.
*/
- public HashMap[] getAttributes()
+ public List<Map<Attribute,Object>> getAttributes()
{
- return a_attributes;
+ return aAttributes;
}
}