Package groovy.xml.slurpersupport

# Class GPathResult

java.lang.Object
groovy.lang.GroovyObjectSupport
groovy.xml.slurpersupport.GPathResult

All Implemented Interfaces:
  `Buildable`, `GroovyObject`, `Writable`, `Iterable`

Direct Known Subclasses:
  `Attribute`, `NoChildren`, `NodeChild`, `NodeChildren`

public abstract class GPathResult extends GroovyObjectSupport implements Writable, Buildable, Iterable
Base class for representing lazy evaluated GPath expressions.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected final String`
  `name`
  Node or attribute name selected by this result.
  `protected final Map`
  `namespaceMap`
  Namespace declarations added while traversing or rebuilding this result.
  `protected final String`
  `namespacePrefix`
  Namespace prefix constraint applied to this result, if any.
  `protected final Map<String,String>`
  `namespaceTagHints`
  Namespace prefix hints captured while parsing for stable QName rendering.
  `protected final GPathResult`
  `parent`
  Previous step in the lazy GPath chain, used for expression backtracking.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `GPathResult(GPathResult parent, String name, String namespacePrefix, Map<String,String> namespaceTagHints)`
  Creates a new GPathResult named `name` with the parent `parent`, the namespacePrefix `namespacePrefix` and the namespaceTagHints specified in the `namespaceTagHints` Map.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected abstract void`
  `appendNode(Object newValue)`
  Lazily appends content to the nodes represented by this result.
  `Iterator`
  `breadthFirst()`
  Provides an Iterator over all the nodes of this GPathResult using a breadth-first traversal.
  `abstract Iterator`
  `childNodes()`
  Returns an iterator over the child nodes of this GPathResult.
  `GPathResult`
  `children()`
  Returns the children of this GPathResult as a GPathResult object.
  `protected Iterator`
  `createIterator(Object obj)`
  Creates a single-element iterator used by scalar GPath results.
  `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)`
  `abstract GPathResult`
  `find(Closure closure)`
  Returns the first child of this GPathResult matching the condition(s) specified in the passed closure.
  `abstract GPathResult`
  `findAll(Closure closure)`
  Returns the children of this GPathResult matching the condition(s) specified in the passed 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()`
  Creates a Closure representing the body of this GPathResult.
  `Object`
  `getProperty(String property)`
  Returns the specified Property of this GPathResult.
  `int`
  `hashCode()`
  `boolean`
  `isEmpty()`
  Returns true if the GPathResult is empty, i.e.
  `abstract 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()`
  Returns the name of this GPathResult.
  `abstract Iterator`
  `nodeIterator()`
  Returns the raw node iterator backing this lazy result.
  `GPathResult`
  `parent()`
  Returns as GPathResult with the parent nodes of the current GPathResult
  `abstract GPathResult`
  `parents()`
  Returns the parents of this GPathResult as a `GPathResult`.
  `Object`
  `plus(Closure newValue)`
  Delegates to `plus(Object)` while preserving XmlSlurper replacement semantics for closures.
  `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)`
  A helper method to allow GPathResults to work with subscript operators
  `protected abstract void`
  `replaceBody(Object newValue)`
  Lazily replaces the body content represented by this result.
  `protected abstract void`
  `replaceNode(Closure newValue)`
  Lazily replaces the nodes represented by this result.
  `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.
  `abstract int`
  `size()`
  Returns the size of this GPathResult.
  `abstract String`
  `text()`
  Returns the text of this GPathResult as a `String`.
  `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 an 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 groovy.lang.GroovyObjectSupport

  `getMetaClass`

  ### Methods inherited from class java.lang.Object

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

  ### Methods inherited from interface groovy.lang.Buildable

  `build`

  ### Methods inherited from interface groovy.lang.GroovyObject

  `invokeMethod`

  ### Methods inherited from interface java.lang.Iterable

  `forEach, spliterator`

  ### Methods inherited from interface groovy.lang.Writable

  `writeTo`

- ## Field Details

  - ### parent

    protected final GPathResult parent
    Previous step in the lazy GPath chain, used for expression backtracking.

  - ### name

    protected final String name
    Node or attribute name selected by this result.

  - ### namespacePrefix

    protected final String namespacePrefix
    Namespace prefix constraint applied to this result, if any.

  - ### namespaceMap

    protected final Map namespaceMap
    Namespace declarations added while traversing or rebuilding this result.

  - ### namespaceTagHints

    protected final Map<String,String> namespaceTagHints
    Namespace prefix hints captured while parsing for stable QName rendering.

- ## Constructor Details

  - ### GPathResult

    public GPathResult(GPathResult parent, String name, String namespacePrefix, Map<String,String> 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 Details

  - ### setMetaClass

    public void setMetaClass(MetaClass metaClass)
    Replaces the MetaClass of this GPathResult.
    Specified by:
      `setMetaClass` in interface `GroovyObject`
    Overrides:
      `setMetaClass` in class `GroovyObjectSupport`
    Parameters:
      `metaClass` - the new MetaClass

  - ### getProperty

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

    Realizes the follow shortcuts:

    - `'..'` for `parent()`
    - `'*'` for `children()`
    - `'**'` for `depthFirst()`
    - `'@'` for attribute access
    Specified by:
      `getProperty` in interface `GroovyObject`
    Parameters:
      `property` - the Property to fetch
    Returns:
      the given property

  - ### setProperty

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

  - ### 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`

  - ### plus

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

  - ### plus

    public Object plus(Closure newValue)
    Delegates to `plus(Object)` while preserving XmlSlurper replacement semantics for closures.
    Parameters:
      `newValue` - closure supplying replacement markup
    Returns:
      `this`

  - ### replaceNode

    protected abstract void replaceNode(Closure newValue)
    Lazily replaces the nodes represented by this result.
    Parameters:
      `newValue` - closure generating the replacement content

  - ### replaceBody

    protected abstract void replaceBody(Object newValue)
    Lazily replaces the body content represented by this result.
    Parameters:
      `newValue` - replacement body content

  - ### appendNode

    protected abstract void appendNode(Object newValue)
    Lazily appends content to the nodes represented by this result.
    Parameters:
      `newValue` - content to append

  - ### name

    public String name()
    Returns the name of this GPathResult.
    Returns:
      the name of this GPathResult

  - ### 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 behavior 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`

  - ### parent

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

  - ### children

    public GPathResult children()
    Returns the children of this GPathResult as a GPathResult object.
    Returns:
      the children 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

  - ### toString

    public String toString()
    Returns the text of this GPathResult.
    Overrides:
      `toString` in class `Object`
    Returns:
      the GPathResult, converted to a `String`

  - ### toInteger

    public Integer toInteger()
    Converts the text of this GPathResult to an 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`

  - ### toFloat

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

  - ### toDouble

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

  - ### 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`

  - ### toURL

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

  - ### toURI

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

  - ### toBoolean

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

  - ### 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`

  - ### hashCode

    public int hashCode()
    Overrides:
      `hashCode` in class `Object`

  - ### equals

    public boolean equals(Object obj)
    Overrides:
      `equals` in class `Object`

  - ### getAt

    public Object getAt(int index)
    Supports the subscript operator for a GPathResult.

         import groovy.xml.slurpersupport.*
         import groovy.xml.XmlSlurper
         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.

         import groovy.xml.slurpersupport.*
         import groovy.xml.XmlSlurper
         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

  - ### putAt

    public void putAt(int index, Object newValue)
    A helper method to allow GPathResults to work with subscript operators
    Parameters:
      `index` - an index
      `newValue` - the value to put at the given index

  - ### 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

  - ### 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

  - ### list

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

  - ### 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

  - ### getBody

    public Closure getBody()
    Creates a Closure representing the body of this GPathResult.
    Returns:
      the body of this GPathResult, converted to a `Closure`

  - ### size

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

  - ### text

    public abstract String text()
    Returns the text of this GPathResult as a `String`.
    Returns:
      the text of this GPathResult

  - ### parents

    public abstract GPathResult parents()
    Returns the parents of this GPathResult as a `GPathResult`. Warning: The subclasses of this package do not implement this method yet.
    Returns:
      the parents of this GPathResult

  - ### childNodes

    public abstract Iterator childNodes()
    Returns an iterator over the child nodes of this GPathResult.
    Returns:
      an iterator over the child nodes of this GPathResult

  - ### iterator

    public abstract Iterator iterator()
    Specified by:
      `iterator` in interface `Iterable`

  - ### find

    public abstract GPathResult find(Closure closure)
    Returns the first child of this GPathResult matching the condition(s) specified in the passed closure.
    Parameters:
      `closure` - a closure to filters the children of this GPathResult
    Returns:
      the first child matching the closure

  - ### findAll

    public abstract GPathResult findAll(Closure closure)
    Returns the children of this GPathResult matching the condition(s) specified in the passed closure.
    Parameters:
      `closure` - a closure to filters the children of this GPathResult
    Returns:
      the children matching the closure

  - ### nodeIterator

    public abstract Iterator nodeIterator()
    Returns the raw node iterator backing this lazy result.
    Returns:
      the underlying node iterator

  - ### createIterator

    protected Iterator createIterator(Object obj)
    Creates a single-element iterator used by scalar GPath results.
    Parameters:
      `obj` - the sole element to expose
    Returns:
      an iterator yielding `obj` once