Groovy 2.2.0

groovy.util.slurpersupport
[Java] Class GPathResult

java.lang.Object
  groovy.lang.GroovyObjectSupport
      groovy.util.slurpersupport.GPathResult
All Implemented Interfaces:
Buildable, Writable, Iterable

public abstract class GPathResult
extends GroovyObjectSupport

Base class for representing lazy evaluated GPath expressions.

Authors:
John Wilson


Field Summary
protected String name

protected Map namespaceMap

protected String namespacePrefix

protected Map namespaceTagHints

protected GPathResult parent

 
Constructor Summary
GPathResult(GPathResult parent, String name, String namespacePrefix, Map namespaceTagHints)

Creates a new GPathResult named name with the parent parent, the namespacePrefix namespacePrefix and the namespaceTagHints specified in the namespaceTagHints Map.

 
Method Summary
protected void appendNode(Object newValue)

Iterator breadthFirst()

Provides an Iterator over all the nodes of this GPathResult using a breadth-first traversal.

Iterator childNodes()

GPathResult children()

Returns the children of this GPathResult as a GPathResult object.

GPathResult declareNamespace(Map newNamespaceMapping)

Adds the specified map of prefix to namespace mappings to this GPathResult.

Iterator depthFirst()

Provides an Iterator over all the nodes of this GPathResult using a depth-first traversal.

boolean equals(Object obj)

GPathResult find(Closure closure)

GPathResult findAll(Closure closure)

Object getAt(int index)

Supports the subscript operator for a GPathResult.

Object getAt(IntRange range)

Supports the range subscript operator for a GPathResult.

Closure getBody()

Object getProperty(String property)

Returns the specified Property of this GPathResult.

boolean isEmpty()

Returns true if the GPathResult is empty, i.e. if, and only if, size() is 0.

Iterator iterator()

Object leftShift(Object newValue)

Overloads the left shift operator to provide an easy way to lazily append Objects to this GPathResult.

List list()

Creates a list of objects representing this GPathResult.

String lookupNamespace(String prefix)

Returns the namespace mapped to the specified prefix.

String name()

Iterator nodeIterator()

GPathResult parent()

Returns as GPathResult with the parent nodes of the current GPathResult

GPathResult parents()

Object plus(Object newValue)

Lazily adds the specified Object to this GPathResult.

GPathResult pop()

Returns the parent of this GPathResult.

void putAt(int index, Object newValue)

protected void replaceBody(Object newValue)

protected void replaceNode(Closure newValue)

void setMetaClass(MetaClass metaClass)

Replaces the MetaClass of this GPathResult.

void setProperty(String property, Object newValue)

Replaces the specified property of this GPathResult with a new value.

int size()

Returns the size of this GPathResult.

String text()

BigDecimal toBigDecimal()

Converts the text of this GPathResult to a BigDecimal object.

BigInteger toBigInteger()

Converts the text of this GPathResult to a BigInteger object.

Boolean toBoolean()

Converts the text of this GPathResult to a Boolean object.

Double toDouble()

Converts the text of this GPathResult to a Double object.

Float toFloat()

Converts the text of this GPathResult to a Float object.

Integer toInteger()

Converts the text of this GPathResult to a Integer object.

Long toLong()

Converts the text of this GPathResult to a Long object.

String toString()

Returns the text of this GPathResult.

URI toURI()

Converts the text of this GPathResult to a URI object.

URL toURL()

Converts the text of this GPathResult to a URL object.

 
Methods inherited from class GroovyObjectSupport
getMetaClass, getProperty, invokeMethod, setMetaClass, setProperty
 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Field Detail

name

protected final String name


namespaceMap

protected final Map namespaceMap


namespacePrefix

protected final String namespacePrefix


namespaceTagHints

protected final Map namespaceTagHints


parent

protected final GPathResult parent


 
Constructor Detail

GPathResult

public GPathResult(GPathResult parent, String name, String namespacePrefix, Map namespaceTagHints)
Creates a new GPathResult named name with the parent parent, the namespacePrefix namespacePrefix and the namespaceTagHints specified in the namespaceTagHints Map.
Parameters:
parent - the GPathResult prior to the application of the expression creating this GPathResult
name - if the GPathResult corresponds to something with a name, e.g. a node
namespacePrefix - the namespace prefix if any
namespaceTagHints - the known tag to namespace mappings


 
Method Detail

appendNode

protected void appendNode(Object newValue)


breadthFirst

public Iterator breadthFirst()
Provides an Iterator over all the nodes of this GPathResult using a breadth-first traversal.
Returns:
the Iterator of (breadth-first) ordered GPathResults


childNodes

public Iterator childNodes()


children

public GPathResult children()
Returns the children of this GPathResult as a GPathResult object.
Returns:
the children of this GPathResult


declareNamespace

public GPathResult declareNamespace(Map newNamespaceMapping)
Adds the specified map of prefix to namespace mappings to this GPathResult. Already existing prefixes are overwritten.
Parameters:
newNamespaceMapping - the mappings to add
Returns:
this


depthFirst

public Iterator depthFirst()
Provides an Iterator over all the nodes of this GPathResult using a depth-first traversal.
Returns:
the Iterator of (depth-first) ordered GPathResults


equals

public boolean equals(Object obj)


find

public GPathResult find(Closure closure)


findAll

public GPathResult findAll(Closure closure)


getAt

public Object getAt(int index)
Supports the subscript operator for a GPathResult.
 def text = """
 <characterList>
   <character/>
   <character>
     <name>Gromit</name>
   </character>
 </characterList>"""

 GPathResult characterList = new XmlSlurper().parseText(text)

 assert characterList.character[1].name == 'Gromit'
 
Parameters:
index - an index
Returns:
the value at the given index


getAt

public Object getAt(IntRange range)
Supports the range subscript operator for a GPathResult.
 def text = """
 <characterList>
   <character>Wallace</character>
   <character>Gromit</character>
   <character>Shaun</character>
 </characterList>"""

 GPathResult characterList = new XmlSlurper().parseText(text)

 assert characterList.character[1..2].join(',') == 'Gromit,Shaun'
 
Parameters:
range - a Range indicating the items to get
Returns:
a new list based on range borders


getBody

public Closure getBody()


getProperty

public Object getProperty(String property)
Returns the specified Property of this GPathResult.

Realizes the follow shortcuts:

Parameters:
property - the Property to fetch


isEmpty

public boolean isEmpty()
Returns true if the GPathResult is empty, i.e. if, and only if, size() is 0.
Returns:
true if the GPathResult is empty


iterator

public Iterator iterator()


leftShift

public Object leftShift(Object newValue)
Overloads the left shift operator to provide an easy way to lazily append Objects to this GPathResult.
Parameters:
newValue - the Object to append
Returns:
this


list

public List list()
Creates a list of objects representing this GPathResult.
Returns:
a list representing of this GPathResult


lookupNamespace

public String lookupNamespace(String prefix)
Returns the namespace mapped to the specified prefix.
Parameters:
prefix - the prefix lookup
Returns:
the namespace of the prefix


name

public String name()


nodeIterator

public Iterator nodeIterator()


parent

public GPathResult parent()
Returns as GPathResult with the parent nodes of the current GPathResult
Returns:
the parents GPathResult or this for the root


parents

public GPathResult parents()


plus

public Object plus(Object newValue)
Lazily adds the specified Object to this GPathResult.
Parameters:
newValue - the Object to add
Returns:
this


pop

public GPathResult pop()
Returns the parent of this GPathResult. If this GPathResult has no parent the GPathResult itself is returned. This is no navigation in the XML tree. It is backtracking on the GPath expression chain. It is the bevavior of parent() prior to 2.2.0. Backtracking on '..' actually goes down one level in the tree again. find() and findAll() are popped along with the level they have been applied to.
Returns:
the parent or this


putAt

public void putAt(int index, Object newValue)


replaceBody

protected void replaceBody(Object newValue)


replaceNode

protected void replaceNode(Closure newValue)


setMetaClass

@Override
public void setMetaClass(MetaClass metaClass)
Replaces the MetaClass of this GPathResult.
Parameters:
metaClass - the new MetaClass


setProperty

public void setProperty(String property, Object newValue)
Replaces the specified property of this GPathResult with a new value.
Parameters:
property - the property of this GPathResult to replace
newValue - the new value of the property


size

public int size()
Returns the size of this GPathResult.
Returns:
the size of this GPathResult


text

public String text()


toBigDecimal

public BigDecimal toBigDecimal()
Converts the text of this GPathResult to a BigDecimal object.
Returns:
the GPathResult, converted to a BigDecimal


toBigInteger

public BigInteger toBigInteger()
Converts the text of this GPathResult to a BigInteger object.
Returns:
the GPathResult, converted to a BigInteger


toBoolean

public Boolean toBoolean()
Converts the text of this GPathResult to a Boolean object.
Returns:
the GPathResult, converted to a Boolean


toDouble

public Double toDouble()
Converts the text of this GPathResult to a Double object.
Returns:
the GPathResult, converted to a Double


toFloat

public Float toFloat()
Converts the text of this GPathResult to a Float object.
Returns:
the GPathResult, converted to a Float


toInteger

public Integer toInteger()
Converts the text of this GPathResult to a Integer object.
Returns:
the GPathResult, converted to a Integer


toLong

public Long toLong()
Converts the text of this GPathResult to a Long object.
Returns:
the GPathResult, converted to a Long


toString

public String toString()
Returns the text of this GPathResult.
Returns:
the GPathResult, converted to a String


toURI

public URI toURI()
Converts the text of this GPathResult to a URI object.
Returns:
the GPathResult, converted to a URI


toURL

public URL toURL()
Converts the text of this GPathResult to a URL object.
Returns:
the GPathResult, converted to a URL


 

Copyright &copy; 2003-2013 The Codehaus. All rights reserved.