import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
+import java.util.List;
import java.util.Iterator;
* The attributes of this node, keyed by attribute name,
* Instantiated only if required.
*/
- protected HashMap attributes = null;
+ protected HashMap<String,String> attributes = null;
/**
public void addAttribute(String name, String value) {
if (attributes == null)
- attributes = new HashMap();
+ attributes = new HashMap<String,String>();
attributes.put(name, value);
}
public String findAttribute(String name) {
if (attributes == null)
- return (null);
+ return null;
else
- return ((String) attributes.get(name));
+ return attributes.get(name);
}
* Return an Iterator of the attribute names of this node. If there are
* no attributes, an empty Iterator is returned.
*/
- public Iterator findAttributes() {
+ public Iterator<String> findAttributes() {
- if (attributes == null)
- return (Collections.EMPTY_LIST.iterator());
- else
- return (attributes.keySet().iterator());
+ if (attributes == null) {
+ List<String> empty = Collections.emptyList();
+ return empty.iterator();
+ } else
+ return attributes.keySet().iterator();
}
if (children == null)
return (null);
- Iterator items = children.iterator();
+ Iterator<TreeNode> items = children.iterator();
while (items.hasNext()) {
- TreeNode item = (TreeNode) items.next();
+ TreeNode item = items.next();
if (name.equals(item.getName()))
return (item);
}
*/
public Iterator<TreeNode> findChildren() {
- if (children == null)
- return (Collections.EMPTY_LIST.iterator());
- else
- return (children.iterator());
+ if (children == null) {
+ List<TreeNode> empty = Collections.emptyList();
+ return empty.iterator();
+ } else
+ return children.iterator();
}
*/
public Iterator<TreeNode> findChildren(String name) {
- if (children == null)
- return (Collections.EMPTY_LIST.iterator());
+ if (children == null) {
+ List<TreeNode> empty = Collections.emptyList();
+ return empty.iterator();
+ }
ArrayList<TreeNode> results = new ArrayList<TreeNode>();
Iterator<TreeNode> items = children.iterator();
sb.append(' ');
sb.append('<');
sb.append(node.getName());
- Iterator names = node.findAttributes();
+ Iterator<String> names = node.findAttributes();
while (names.hasNext()) {
sb.append(' ');
- String name = (String) names.next();
+ String name = names.next();
sb.append(name);
sb.append("=\"");
String value = node.findAttribute(name);
}
// Reconstruct child nodes with extra indentation
- Iterator children = node.findChildren();
+ Iterator<TreeNode> children = node.findChildren();
while (children.hasNext()) {
- TreeNode child = (TreeNode) children.next();
+ TreeNode child = children.next();
toString(sb, indent2, child);
}
expectedByte(2, 2);
}
if ((b1 & 0xC0) != 0x80) {
- invalidByte(2, 2, b1);
+ invalidByte(2, 2);
}
c = ((b0 << 6) & 0x07C0) | (b1 & 0x003F);
}
expectedByte(2, 3);
}
if ((b1 & 0xC0) != 0x80) {
- invalidByte(2, 3, b1);
+ invalidByte(2, 3);
}
int b2 = index == fOffset
? fInputStream.read() : fBuffer[index++] & 0x00FF;
expectedByte(3, 3);
}
if ((b2 & 0xC0) != 0x80) {
- invalidByte(3, 3, b2);
+ invalidByte(3, 3);
}
c = ((b0 << 12) & 0xF000) | ((b1 << 6) & 0x0FC0) |
(b2 & 0x003F);
expectedByte(2, 4);
}
if ((b1 & 0xC0) != 0x80) {
- invalidByte(2, 3, b1);
+ invalidByte(2, 3);
}
int b2 = index == fOffset
? fInputStream.read() : fBuffer[index++] & 0x00FF;
expectedByte(3, 4);
}
if ((b2 & 0xC0) != 0x80) {
- invalidByte(3, 3, b2);
+ invalidByte(3, 3);
}
int b3 = index == fOffset
? fInputStream.read() : fBuffer[index++] & 0x00FF;
expectedByte(4, 4);
}
if ((b3 & 0xC0) != 0x80) {
- invalidByte(4, 4, b3);
+ invalidByte(4, 4);
}
int uuuuu = ((b0 << 2) & 0x001C) | ((b1 >> 4) & 0x0003);
if (uuuuu > 0x10) {
// error
else {
- invalidByte(1, 1, b0);
+ invalidByte(1, 1);
}
}
fOffset = 2;
return out - offset;
}
- invalidByte(2, 2, b1);
+ invalidByte(2, 2);
}
int c = ((b0 << 6) & 0x07C0) | (b1 & 0x003F);
ch[out++] = (char)c;
fOffset = 2;
return out - offset;
}
- invalidByte(2, 3, b1);
+ invalidByte(2, 3);
}
int b2 = -1;
if (++in < total) {
fOffset = 3;
return out - offset;
}
- invalidByte(3, 3, b2);
+ invalidByte(3, 3);
}
int c = ((b0 << 12) & 0xF000) | ((b1 << 6) & 0x0FC0) |
(b2 & 0x003F);
fOffset = 2;
return out - offset;
}
- invalidByte(2, 4, b1);
+ invalidByte(2, 4);
}
int b2 = -1;
if (++in < total) {
fOffset = 3;
return out - offset;
}
- invalidByte(3, 4, b2);
+ invalidByte(3, 4);
}
int b3 = -1;
if (++in < total) {
fOffset = 4;
return out - offset;
}
- invalidByte(4, 4, b2);
+ invalidByte(4, 4);
}
// decode bytes into surrogate characters
fOffset = 1;
return out - offset;
}
- invalidByte(1, 1, b0);
+ invalidByte(1, 1);
}
// return number of characters converted
Integer.toString(position),
Integer.toString(count)));
- } // expectedByte(int,int,int)
+ }
/** Throws an exception for invalid byte. */
- private void invalidByte(int position, int count, int c)
+ private void invalidByte(int position, int count)
throws UTFDataFormatException {
throw new UTFDataFormatException(
Localizer.getMessage("jsp.error.xml.invalidByte",
Integer.toString(position),
Integer.toString(count)));
- } // invalidByte(int,int,int,int)
+ }
/** Throws an exception for invalid surrogate bits. */
private void invalidSurrogate(int uuuuu) throws UTFDataFormatException {
throw new UTFDataFormatException(
Localizer.getMessage("jsp.error.xml.invalidHighSurrogate",
Integer.toHexString(uuuuu)));
- } // invalidSurrogate(int)
+ }
} // class UTF8Reader