Package org.geotools.referencing.wkt
Class Element
- Object
-
- Element
-
public final class Element extends Object
An element in a Well Know Text (WKT). AElementis made ofString,Numberand otherElement. For example:
EachPRIMEM["Greenwich", 0.0, AUTHORITY["some authority", "Greenwich"]]
Elementobject can contains an arbitrary amount of other elements. The result is a tree, which can be printed withprint(java.io.PrintWriter, int). Elements can be pull in a first in, first out order.- Since:
- 2.0
- Author:
- Remi Eve, Martin Desruisseaux (IRD)
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Close this element.booleanisRoot()Returnstrueif this element is the root element.ParseExceptionparseFailed(Exception cause, String message)Returns aParseExceptionwith the specified cause.Objectpeek()Returns the next element, ornullif there is no more element.voidprint(PrintWriter out, int level)Print thisElementas a tree.doublepullDouble(String key)Removes the nextNumberfrom the list and returns it.ElementpullElement(String key)Removes the nextElementfrom the list and returns it.intpullInteger(String key)Removes the nextNumberfrom the list and returns it as an integer.ElementpullOptionalElement(String key)Removes the nextElementfrom the list and returns it.StringpullOptionalString(String key)Removes the nextStringfrom the list and returns it.ElementpullOptionalVoidElement()Removes and returns the nextElementwith no bracket, if available, or null otherwise.StringpullString(String key)Removes the nextStringfrom the list and returns it.ElementpullVoidElement(String key)Removes and returns the nextElementwith no bracket.StringtoString()Returns the keyword.
-
-
-
Field Detail
-
keyword
public final String keyword
Keyword of this entity. For example: "PRIMEM".
-
-
Method Detail
-
parseFailed
public ParseException parseFailed(Exception cause, String message)
Returns aParseExceptionwith the specified cause. A localized string"Error in <will be prepend to the message. The error index will be the starting index of thiskeyword>"Element.- Parameters:
cause- The cause of the failure, ornullif none.message- The message explaining the cause of the failure, ornullfor reusing the same message thancause.- Returns:
- The exception to be thrown.
-
isRoot
public boolean isRoot()
Returnstrueif this element is the root element. For example in a WKT like"GEOGCS["name", DATUM["name, ...]]", this is true for"GEOGCS"and false for all other elements inside, like"DATUM".- Returns:
trueif this element is the root element.- Since:
- 2.3
-
pullDouble
public double pullDouble(String key) throws ParseException
Removes the nextNumberfrom the list and returns it.- Parameters:
key- The parameter name. Used for formatting an error message if no number are found.- Returns:
- The next
Numberon the list as adouble. - Throws:
ParseException- if no more number is available.
-
pullInteger
public int pullInteger(String key) throws ParseException
Removes the nextNumberfrom the list and returns it as an integer.- Parameters:
key- The parameter name. Used for formatting an error message if no number are found.- Returns:
- The next
Numberon the list as anint. - Throws:
ParseException- if no more number is available, or the number is not an integer.
-
pullString
public String pullString(String key) throws ParseException
Removes the nextStringfrom the list and returns it.- Parameters:
key- The parameter name. Used for formatting an error message if no number are found.- Returns:
- The next
Stringon the list. - Throws:
ParseException- if no more string is available.
-
pullOptionalString
public String pullOptionalString(String key)
Removes the nextStringfrom the list and returns it.- Parameters:
key- The parameter name. Used for formatting an error message if no number are found.- Returns:
- The next
Stringon the list ornullif no more element is available.
-
pullElement
public Element pullElement(String key) throws ParseException
Removes the nextElementfrom the list and returns it.- Parameters:
key- The element name (e.g."PRIMEM").- Returns:
- The next
Elementon the list. - Throws:
ParseException- if no more element is available.
-
pullOptionalElement
public Element pullOptionalElement(String key)
Removes the nextElementfrom the list and returns it.- Parameters:
key- The element name (e.g."PRIMEM").- Returns:
- The next
Elementon the list, ornullif no more element is available.
-
pullVoidElement
public Element pullVoidElement(String key) throws ParseException
Removes and returns the nextElementwith no bracket. The key is used only for only for formatting an error message.- Parameters:
key- The parameter name. Used only for formatting an error message.- Returns:
- The next
Elementin the list, with no bracket. - Throws:
ParseException- if no more void element is available.
-
pullOptionalVoidElement
public Element pullOptionalVoidElement() throws ParseException
Removes and returns the nextElementwith no bracket, if available, or null otherwise.- Returns:
- The next
Elementin the list, with no bracket, or null if none was found - Throws:
ParseException- if no more void element is available.
-
peek
public Object peek()
Returns the next element, ornullif there is no more element. The element is not removed from the list.- Returns:
- The next element, or
nullif there is no more elements.
-
close
public void close() throws ParseExceptionClose this element.- Throws:
ParseException- If the list still contains some unprocessed elements.
-
toString
public String toString()
Returns the keyword. This overriding is needed for correct formatting of the error message inclose().
-
print
public void print(PrintWriter out, int level)
Print thisElementas a tree. This method is used for debugging purpose only.- Parameters:
out- The output stream.level- The indentation level (usually 0).
-
-