Method from org.apache.tomcat.util.collections.MultiMap Detail: |
public int addField() {
int len = fields.length;
int pos=count;
if (count >= len) {
// expand header list array
Field tmp[] = new Field[pos * 2];
System.arraycopy(fields, 0, tmp, 0, len);
fields = tmp;
}
if (fields[pos] == null) {
fields[pos] = new Field();
}
count++;
return pos;
}
Create a new, unitialized entry. |
public int find(String name,
int starting) {
// We can use a hash - but it's not clear how much
// benefit you can get - there is an overhead
// and the number of headers is small (4-5 ?)
// Another problem is that we'll pay the overhead
// of constructing the hashtable
// A custom search tree may be better
for (int i = starting; i < count; i++) {
if (fields[i].name.equals(name)) {
return i;
}
}
return -1;
}
Find the index of a field with the given name. |
public int findFirst(String name) {
for (int i = 0; i < count; i++) {
if (fields[i].name.equals(name)) {
return i;
}
}
return -1;
}
|
public int findIgnoreCase(String name,
int starting) {
// We can use a hash - but it's not clear how much
// benefit you can get - there is an overhead
// and the number of headers is small (4-5 ?)
// Another problem is that we'll pay the overhead
// of constructing the hashtable
// A custom search tree may be better
for (int i = starting; i < count; i++) {
if (fields[i].name.equalsIgnoreCase(name)) {
return i;
}
}
return -1;
}
Find the index of a field with the given name. |
public int findNext(int startPos) {
int next= fields[startPos].nextPos;
if( next != MultiMap.NEED_NEXT ) {
return next;
}
// next==NEED_NEXT, we never searched for this header
MessageBytes name=fields[startPos].name;
for (int i = startPos; i < count; i++) {
if (fields[i].name.equals(name)) {
// cache the search result
fields[startPos].nextPos=i;
return i;
}
}
fields[startPos].nextPos= MultiMap.LAST;
return -1;
}
|
public MessageBytes get(String name) {
for (int i = 0; i < count; i++) {
if (fields[i].name.equals(name)) {
return fields[i].value;
}
}
return null;
}
|
public MessageBytes getName(int n) {
// n >= 0 && n < count ? headers[n].getName() : null
return fields[n].name;
}
Returns the Nth header name
This may be used to iterate through all header fields.
An exception is thrown if the index is not valid ( <0 or >size ) |
public MessageBytes getValue(int n) {
return fields[n].value;
}
Returns the Nth header value
This may be used to iterate through all header fields. |
public void recycle() {
for (int i = 0; i < count; i++) {
fields[i].recycle();
}
count = 0;
}
Clears all header fields. |
public void remove(int i) {
// reset and swap with last header
Field mh = fields[i];
// reset the field
mh.recycle();
fields[i] = fields[count - 1];
fields[count - 1] = mh;
count--;
}
Removes the field at the specified position.
MultiMap will preserve the order of field add unless remove()
is called. This is not thread-safe, and will invalidate all
iterators.
This is not a frequent operation for Headers and Parameters -
there are better ways ( like adding a "isValid" field ) |
public int size() {
return count;
}
Returns the current number of header fields. |