public class TvList
extends java.lang.Object
This class parses and holds tag-value string pairs. It's methods are modeled after the java.util.list interface.
The string format that is parsed is of the form tag=value.
This is the same as the query string portion of a URL, or the body
of an HTTP POST. When multiple tag-value paires are contained in a
single string the form is
tag1=value1&tag2=value2
The tag and value are typically URLencoded, but unencoded strings can
be handled as long as they don't contain = or & characters.
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
CHAR_ENCODING
Claracter encoding for URLEncoder
|
static java.lang.String[] |
DEP_LIST
Class dependencies
|
static java.lang.String |
VERSION
Class version
|
| Constructor and Description |
|---|
TvList()
Create a new empty tag-value list
|
TvList(java.lang.String[] pair)
Create a new tag-value list, with a single tag-value pair
|
TvList(java.lang.String tag,
java.lang.String value)
Create a new tag-value list, with a single tag-value pair
|
| Modifier and Type | Method and Description |
|---|---|
void |
addFirst(java.lang.String[] pair)
Add a tag-value pair to the beginning of the list
|
void |
addFirst(java.lang.String tag,
java.lang.String value)
Add a tag and value to the beginning of the list.
|
boolean |
addFirst(TvList newList)
Add another tag-value list to the beginning of the list.
|
void |
addLast(java.lang.String[] pair)
Add a tag and value to the end of the list.
|
void |
addLast(java.lang.String tag,
java.lang.String value)
Add a tag and value to the end of the list.
|
boolean |
addLast(TvList newList)
Add another tag-value list to the end of the list.
|
void |
clear()
Remove all elements from the list.
|
java.lang.String[] |
getFirst()
Get the first tag-value pair from the list.
|
int |
indexOfTag(java.lang.String tag)
Get the location of the first occurrence of a tag.
|
boolean |
isEmpty()
Determine if the list is empty.
|
java.util.Iterator<java.lang.String[]> |
iterator()
Get an iterator of the elements in the list.
|
static TvList |
parseTagValue(java.lang.String tagValStr)
Parse a tag-value string.
|
static TvList |
parseTagValue(java.lang.String tagValStr,
boolean urlDecode)
Parse a tag-value string.
|
void |
readFrom(java.io.BufferedReader source)
Read a tag-value list from a BufferedReader.
|
java.lang.String[] |
remove(int idx)
Remove the tag-value pair at the specified location from the list.
|
java.lang.String[] |
removeFirst()
Remove the first tag-value pair from the list.
|
int |
size()
Get the number of tag-value pairs in the list.
|
java.lang.String |
toString()
Return the list as a String.
|
java.lang.String |
urlEncode()
Return the list as a URL Encoded String.
|
void |
writeTo(java.io.PrintWriter dest)
Write a tag-value list to a PrintWriter.
|
public static final java.lang.String VERSION
public static final java.lang.String[] DEP_LIST
public static final java.lang.String CHAR_ENCODING
public TvList()
public TvList(java.lang.String[] pair)
pair - A two element string array with a tag-value pairpublic TvList(java.lang.String tag,
java.lang.String value)
tag - Tag for tag-value pairvalue - Value for tag-value pairpublic static TvList parseTagValue(java.lang.String tagValStr)
tagValStr - The string to be decoded.public static TvList parseTagValue(java.lang.String tagValStr, boolean urlDecode)
tagValStr - The string to be decoded.urlDecode - If true, the results are URL decoded.public void addFirst(java.lang.String tag,
java.lang.String value)
tag - Tag for tag-value pairvalue - Value for tag-value pairpublic void addFirst(java.lang.String[] pair)
pair - A two element string array with a tag-value pairpublic boolean addFirst(TvList newList)
newList - The list to be addedpublic void addLast(java.lang.String tag,
java.lang.String value)
tag - Tag for tag-value pairvalue - Value for tag-value pairpublic void addLast(java.lang.String[] pair)
pair - A two element string array with a tag-value pairpublic boolean addLast(TvList newList)
newList - The list to be addedpublic java.lang.String[] getFirst()
public java.lang.String[] removeFirst()
public java.lang.String[] remove(int idx)
idx - The location of the pair to be removedpublic int indexOfTag(java.lang.String tag)
tag - The tag to be locatedpublic java.util.Iterator<java.lang.String[]> iterator()
public void clear()
public boolean isEmpty()
public int size()
public void readFrom(java.io.BufferedReader source)
throws java.io.IOException
source - The source to read the list fromjava.io.IOException - If an I/O error occurspublic void writeTo(java.io.PrintWriter dest)
dest - The destination to write the list topublic java.lang.String urlEncode()
public java.lang.String toString()
toString in class java.lang.Object