An AttributeList implementation that can perform more operations
than the attribute list helper supplied with the standard SAX
distribution.
| Method from sax.helpers.AttributeListImpl Detail: |
public void addAttribute(String name,
String type,
String value) {
ListNode node = new ListNode(name, type, value);
if (length == 0) {
head = node;
}
else {
tail.next = node;
}
tail = node;
length++;
}
|
public int getLength() {
return length;
}
Returns the number of attributes. |
public String getName(int index) {
ListNode node = getNodeAt(index);
return (node != null) ? node.name : null;
}
Returns the attribute name by index. |
public String getType(int index) {
ListNode node = getNodeAt(index);
return (node != null) ? node.type : null;
}
Returns the attribute type by index. |
public String getType(String name) {
ListNode node = getNodeAt(name);
return (node != null) ? node.type : null;
}
Returns the attribute type by name. |
public String getValue(int index) {
ListNode node = getNodeAt(index);
return (node != null) ? node.value : null;
}
Returns the attribute value by index. |
public String getValue(String name) {
ListNode node = getNodeAt(name);
return (node != null) ? node.value : null;
}
Returns the attribute value by name. |
public void insertAttributeAt(int index,
String name,
String type,
String value) {
// if list is empty, add attribute
if (length == 0 || index >= length) {
addAttribute(name, type, value);
return;
}
// insert at beginning of list
ListNode node = new ListNode(name, type, value);
if (index < 1) {
node.next = head;
head = node;
}
else {
ListNode prev = getNodeAt(index - 1);
node.next = prev.next;
prev.next = node;
}
length++;
}
|
public void removeAttributeAt(int index) {
if (length == 0) {
return;
}
if (index == 0) {
head = head.next;
if (head == null) {
tail = null;
}
length--;
}
else {
ListNode prev = getNodeAt(index - 1);
ListNode node = getNodeAt(index);
if (node != null) {
prev.next = node.next;
if (node == tail) {
tail = prev;
}
length--;
}
}
}
|
public String toString() {
StringBuffer str = new StringBuffer();
str.append('[");
str.append("len=");
str.append(length);
str.append(", {");
for (ListNode place = head; place != null; place = place.next) {
str.append(place.name);
if (place.next != null) {
str.append(", ");
}
}
str.append("}]");
return str.toString();
}
Returns a string representation of this object. |