public class

Path

extends Object
java.lang.Object
   ↳ com.google.gdata.model.Path

Class Overview

The Path class represents an immutable path to a model entity in the GData DOM. A path can be absolute (the root ElementMetadata for the path is specified at construction time or relative (the root element type is unknown at construction time).

The toAbsolute(ElementMetadata) method can be used to produce an absolute path from a relative path by interpreting it relative to a root.

New paths can be constructed using the of(MetadataKey) or #to(ElementMetadata, MetadataKey...) methods as well as using the builder() method to obtain a new Path.Builder instance that can be used for incremental path construction.

Summary

Nested Classes
class Path.Builder The Builder class provides a model for incrementally constructing new Path relative or absolute instances. 
Fields
public static final Path ROOT A simple relative path that selects the root of the path.
private final ElementMetadata<?, ?> root root element type of the path (if absolute) or null (if relative)
private final AttributeMetadata<?> selectedAttribute attribute selected by the path or null (if relative or an element path
private final ElementMetadata<?, ?> selectedElement element selected by the path or null (if relative)
private final boolean selectsAttribute true if the path selects an attribute, false otherwise
private final List<MetadataKey<?>> steps path steps
Public Methods
static Path.Builder builder()
boolean equals(Object o)
The equals method will return true if the target object is also a Path, has the same root or is also relative, and has the same list of path steps.
ElementKey<?, ?> getParentKey()
Returns the element key for the second-to-last key in the path.
AttributeMetadata<?> getSelectedAttribute()
Returns the attribute type currently selected by the path or null if the path selects an element or is relative.
AttributeKey<?> getSelectedAttributeKey()
Returns the attribute key at the end of the path.
ElementMetadata<?, ?> getSelectedElement()
Returns the element type currently selected by the path or null if the path is relative.
ElementKey<?, ?> getSelectedElementKey()
Returns the element key at the end of the path.
List<MetadataKey<?>> getSteps()
Returns the list of path steps.
int hashCode()
boolean isRelative()
Returns true if path is relative
static Path of(MetadataKey...<?> steps)
Constructs a new relative Path that selects an element defined by the set of path steps to the element.
boolean selectsAttribute()
Returns true if the path selects an attribute.
boolean selectsElement()
Returns true if the path selects an element.
static Path to(ElementMetadata<?, ?> root, MetadataKey...<?> keys)
Constructs a new absolute Path to an element type as defined by a root type and the relative steps from it to the selected type.
Path toAbsolute(ElementMetadata<?, ?> root)
Constructs a new Path instance by interpreting the steps in the current path relative to the provided root ElementMetadata.
String toString()
The toString() implementation is overridden to return the XPath string that represents the path.
[Expand]
Inherited Methods
From class java.lang.Object

Fields

public static final Path ROOT

A simple relative path that selects the root of the path.

private final ElementMetadata<?, ?> root

root element type of the path (if absolute) or null (if relative)

private final AttributeMetadata<?> selectedAttribute

attribute selected by the path or null (if relative or an element path

private final ElementMetadata<?, ?> selectedElement

element selected by the path or null (if relative)

private final boolean selectsAttribute

true if the path selects an attribute, false otherwise

private final List<MetadataKey<?>> steps

path steps

Public Methods

public static Path.Builder builder ()

public boolean equals (Object o)

The equals method will return true if the target object is also a Path, has the same root or is also relative, and has the same list of path steps.

Parameters
o

public ElementKey<?, ?> getParentKey ()

Returns the element key for the second-to-last key in the path. If the path is only a single step this method will return null.

public AttributeMetadata<?> getSelectedAttribute ()

Returns the attribute type currently selected by the path or null if the path selects an element or is relative.

public AttributeKey<?> getSelectedAttributeKey ()

Returns the attribute key at the end of the path.

Throws
IllegalStateException if this path is not to an attribute.

public ElementMetadata<?, ?> getSelectedElement ()

Returns the element type currently selected by the path or null if the path is relative.

public ElementKey<?, ?> getSelectedElementKey ()

Returns the element key at the end of the path.

Throws
IllegalStateException if this path is not to an element.

public List<MetadataKey<?>> getSteps ()

Returns the list of path steps.

public int hashCode ()

public boolean isRelative ()

Returns true if path is relative

public static Path of (MetadataKey...<?> steps)

Constructs a new relative Path that selects an element defined by the set of path steps to the element.

Parameters
steps Keys defining steps to the selected element
Returns
  • selection path to element

public boolean selectsAttribute ()

Returns true if the path selects an attribute.

public boolean selectsElement ()

Returns true if the path selects an element.

public static Path to (ElementMetadata<?, ?> root, MetadataKey...<?> keys)

Constructs a new absolute Path to an element type as defined by a root type and the relative steps from it to the selected type.

Parameters
root
keys Keys defining steps to the selected element
Returns
  • selection path to element
Throws
PathException if this path has been bound to a metadata instance and no key with the given step can be found, or if the path is an attribute path. Once a path has an attribute key no more steps may be added.
NullPointerException if root is null.

public Path toAbsolute (ElementMetadata<?, ?> root)

Constructs a new Path instance by interpreting the steps in the current path relative to the provided root ElementMetadata.

Parameters
root Root of returned path
Returns
  • new absolute Path bound to the root element metadata.
Throws
PathException if the path is not found in the metadata.
NullPointerException if root is null.

public String toString ()

The toString() implementation is overridden to return the XPath string that represents the path.