Top Description Fields Constructors Methods
org.postgresql.util

public Class PGtokenizer

extends Object
Class Inheritance
Imports
java.util.ArrayDeque, .ArrayList, .Deque, .HashMap, .List, .Map

This class is used to tokenize the text output of org.postgres. It's mainly used by the geometric classes, but is useful in parsing any output from custom data types output from org.postgresql.
See Also
org.postgresql.geometric.PGbox, org.postgresql.geometric.PGcircle, org.postgresql.geometric.PGlseg, org.postgresql.geometric.PGpath, org.postgresql.geometric.PGpoint, org.postgresql.geometric.PGpolygon

Field Summary

Modifier and TypeField and Description
private static final Map<Character, Character>
protected List<String>

Constructor Summary

AccessConstructor and Description
public
PGtokenizer(String
containing tokens
string
,
char
single character to split the tokens
delim
)

Create a tokeniser.

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

the number of tokens available
getSize
()

public String

Returns:

The token value
getToken
(int
Token number ( 0 ... getSize()-1 )
n
)

public static String

Returns:

String without the lead/trailing strings
remove
(String
Source string
s
,
String
Leading string to remove
l
,
String
Trailing string to remove
t
)

This removes the lead/trailing strings from a string.

public void
remove(String
Leading string to remove
l
,
String
Trailing string to remove
t
)

This removes the lead/trailing strings from all tokens.

public static String

Returns:

String without the < or >
removeAngle
(String
String to remove from
s
)

Removes < and > from the beginning and end of a string.

public void
removeAngle()

Removes < and > from the beginning and end of all tokens.

public static String

Returns:

String without the [ or ]
removeBox
(String
String to remove from
s
)

Removes [ and ] from the beginning and end of a string.

public void
removeBox()

Removes [ and ] from the beginning and end of all tokens.

public static String

Returns:

String without the { or }
removeCurlyBrace
(String
String to remove from
s
)

Removes curly braces { and } from the beginning and end of a string.

public void
removeCurlyBrace()

Removes < and > from the beginning and end of all tokens.

public static String

Returns:

String without the ( or )
removePara
(String
String to remove from
s
)

Removes ( and ) from the beginning and end of a string.

public void
removePara()

Removes ( and ) from the beginning and end of all tokens.

public int

Returns:

number of tokens
tokenize
(String
containing tokens
string
,
char
single character to split the tokens
delim
)

This resets this tokenizer with a new string and/or delimiter.

public PGtokenizer

Returns:

A new instance of PGtokenizer based on the token
tokenizeToken
(int
Token number ( 0 ... getSize()-1 )
n
,
char
The delimiter to use
delim
)

This returns a new tokenizer based on one of our tokens.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CLOSING_TO_OPENING_CHARACTERback to summary
private static final Map<Character, Character> CLOSING_TO_OPENING_CHARACTER
tokensback to summary
protected List<String> tokens

Constructor Detail

PGtokenizerback to summary
public PGtokenizer(String string, char delim)

Create a tokeniser.

We could have used StringTokenizer to do this, however, we needed to handle nesting of '(' ')' '[' ']' '<' and '>' as these are used by the geometric data types.

Parameters
string:String

containing tokens

delim:char

single character to split the tokens

Annotations
@SuppressWarnings:method.invocation

Method Detail

getSizeback to summary
public int getSize()
Returns:int

the number of tokens available

getTokenback to summary
public String getToken(int n)
Parameters
n:int

Token number ( 0 ... getSize()-1 )

Returns:String

The token value

removeback to summary
public static String remove(String s, String l, String t)

This removes the lead/trailing strings from a string.

Parameters
s:String

Source string

l:String

Leading string to remove

t:String

Trailing string to remove

Returns:String

String without the lead/trailing strings

removeback to summary
public void remove(String l, String t)

This removes the lead/trailing strings from all tokens.

Parameters
l:String

Leading string to remove

t:String

Trailing string to remove

removeAngleback to summary
public static String removeAngle(String s)

Removes < and > from the beginning and end of a string.

Parameters
s:String

String to remove from

Returns:String

String without the < or >

removeAngleback to summary
public void removeAngle()

Removes < and > from the beginning and end of all tokens.

removeBoxback to summary
public static String removeBox(String s)

Removes [ and ] from the beginning and end of a string.

Parameters
s:String

String to remove from

Returns:String

String without the [ or ]

removeBoxback to summary
public void removeBox()

Removes [ and ] from the beginning and end of all tokens.

removeCurlyBraceback to summary
public static String removeCurlyBrace(String s)

Removes curly braces { and } from the beginning and end of a string.

Parameters
s:String

String to remove from

Returns:String

String without the { or }

removeCurlyBraceback to summary
public void removeCurlyBrace()

Removes < and > from the beginning and end of all tokens.

removeParaback to summary
public static String removePara(String s)

Removes ( and ) from the beginning and end of a string.

Parameters
s:String

String to remove from

Returns:String

String without the ( or )

removeParaback to summary
public void removePara()

Removes ( and ) from the beginning and end of all tokens.

tokenizeback to summary
public int tokenize(String string, char delim)

This resets this tokenizer with a new string and/or delimiter.

Parameters
string:String

containing tokens

delim:char

single character to split the tokens

Returns:int

number of tokens

tokenizeTokenback to summary
public PGtokenizer tokenizeToken(int n, char delim)

This returns a new tokenizer based on one of our tokens.

The geometric datatypes use this to process nested tokens (usually PGpoint).

Parameters
n:int

Token number ( 0 ... getSize()-1 )

delim:char

The delimiter to use

Returns:PGtokenizer

A new instance of PGtokenizer based on the token