com.sonyericsson.hudson.plugins.metadata.model.values
Class TreeStructureUtil

java.lang.Object
  extended by com.sonyericsson.hudson.plugins.metadata.model.values.TreeStructureUtil

public abstract class TreeStructureUtil
extends Object

Utility methods for easier creation of tree structures of values.

Author:
Robert Sandell <robert.sandell@sonyericsson.com>

Method Summary
static boolean addValue(MetadataParent root, AbstractMetadataValue value, boolean generated, String... parentPath)
          Adds a value with the specified path to the root.
static boolean addValue(MetadataParent root, AbstractMetadataValue value, String... parentPath)
          Adds a value with the specified path to the root.
static boolean addValue(MetadataParent root, Date value, String description, boolean exposedToEnvironment, String... path)
          Adds a DateMetadataValue to the root node with the specified path.
static boolean addValue(MetadataParent root, String value, String description, boolean generated, boolean exposedToEnvironment, String... path)
          Adds a StringMetadataValue to the root node with the specified path.
static boolean addValue(MetadataParent root, String value, String description, String... path)
          Adds a StringMetadataValue to the root node with the specified path.
static TreeNodeMetadataValue createPath(AbstractMetadataValue leaf, boolean generated, String... parentPath)
          Creates a tree structured path with the provided leaf at the end.
static TreeNodeMetadataValue createPath(AbstractMetadataValue leaf, String... parentPath)
          Creates a tree structured path with the provided leaf at the end.
static TreeNodeMetadataValue createPath(Date value, String description, boolean exposedToEnvironment, String... path)
          Creates a path where the last element is a string with the provided value and description.
static TreeNodeMetadataValue createPath(String value, String description, boolean generated, boolean exposedToEnvironment, String... path)
          Creates a path where the last element is a string with the provided value and description.
static TreeNodeMetadataValue createPath(String value, String description, String... path)
          Creates a path where the last element is a string with the provided value and description.
static TreeNodeMetadataValue[] createTreePath(String description, boolean generated, String... path)
          Creates a straight tree-path.
static TreeNodeMetadataValue[] createTreePath(String description, String... path)
          Creates a straight tree-path.
static
<T extends Metadata>
void
findLeaves(Collection<T> collection, Collection<T> newCollection)
          Adds all the leaves in the collection to the newCollection.
static MetadataContainer getContainer(Metadata metadata)
          Find the first MetadataContainer that is an ancestor to the given Metadata.
static
<T extends Metadata>
T
getLeaf(Collection<T> collection, String... path)
          Returns the leaf with the given path.
static
<T extends Metadata>
T
getLeaf(MetadataParent<T> root, String... path)
          Returns the leaf with the given path.
static
<T extends Metadata>
T
getPath(Collection<T> collection, String... path)
          Returns the node with the given path.
static
<T extends Metadata>
T
getPath(MetadataParent<T> root, String... path)
          Returns the node with the given path.
static String prettyPrint(Collection<MetadataValue> values, String tabs)
          Prints the values and their children if any into a structured string.
static String prettyPrint(MetadataValue value, String tabs)
          Prints the value and it's child if any into a structured string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

addValue

public static boolean addValue(MetadataParent root,
                               String value,
                               String description,
                               String... path)
Adds a StringMetadataValue to the root node with the specified path.

Parameters:
root - the root to add the tree to.
value - the string value of the leaf node.
description - the description of the leaf node.
path - the path to the leaf from the root.
Returns:
true if there was no merge conflicts.

addValue

public static boolean addValue(MetadataParent root,
                               String value,
                               String description,
                               boolean generated,
                               boolean exposedToEnvironment,
                               String... path)
Adds a StringMetadataValue to the root node with the specified path.

Parameters:
root - the root to add the tree to.
value - the string value of the leaf node.
description - the description of the leaf node.
generated - what the value's MetadataValue.isGenerated() should be.
exposedToEnvironment - if this value should be exposed to the build as an environment variable.
path - the path to the leaf from the root.
Returns:
true if there was no merge conflicts.

addValue

public static boolean addValue(MetadataParent root,
                               Date value,
                               String description,
                               boolean exposedToEnvironment,
                               String... path)
Adds a DateMetadataValue to the root node with the specified path.

Parameters:
root - the root to add the tree to.
value - the date value of the leaf node.
description - the description of the leaf node.
exposedToEnvironment - if this value should be exposed to the build as an environment variable.
path - the path to the leaf from the root.
Returns:
true if there was no merge conflicts.

addValue

public static boolean addValue(MetadataParent root,
                               AbstractMetadataValue value,
                               String... parentPath)
Adds a value with the specified path to the root.

Parameters:
root - the root to add the tree to.
value - the value of the leaf.
parentPath - the path of the parent of the leaf from the root.
Returns:
true if there was no merge conflicts.

addValue

public static boolean addValue(MetadataParent root,
                               AbstractMetadataValue value,
                               boolean generated,
                               String... parentPath)
Adds a value with the specified path to the root.

Parameters:
root - the root to add the tree to.
value - the value of the leaf.
generated - the parentPath should be marked as generated or not.
parentPath - the path of the parent of the leaf from the root.
Returns:
true if there was no merge conflicts.

createPath

public static TreeNodeMetadataValue createPath(String value,
                                               String description,
                                               String... path)
Creates a path where the last element is a string with the provided value and description.

Parameters:
value - the value
description - the description
path - the full path to the leaf.
Returns:
the tree.

createPath

public static TreeNodeMetadataValue createPath(String value,
                                               String description,
                                               boolean generated,
                                               boolean exposedToEnvironment,
                                               String... path)
Creates a path where the last element is a string with the provided value and description.

Parameters:
value - the value
description - the description
generated - what the value's MetadataValue.isGenerated() should be.
exposedToEnvironment - if this value should be exposed to the build as an environment variable.
path - the full path to the leaf.
Returns:
the tree.

createPath

public static TreeNodeMetadataValue createPath(Date value,
                                               String description,
                                               boolean exposedToEnvironment,
                                               String... path)
Creates a path where the last element is a string with the provided value and description.

Parameters:
value - the value
description - the description
exposedToEnvironment - if this value should be exposed to the build as an environment variable.
path - the full path to the leaf.
Returns:
the tree.

createPath

public static TreeNodeMetadataValue createPath(AbstractMetadataValue leaf,
                                               String... parentPath)
Creates a tree structured path with the provided leaf at the end. The value's MetadataValue.isGenerated() will be true.

Parameters:
leaf - the leaf to put in the end.
parentPath - the path to the leaf.
Returns:
the root node of the path.

createPath

public static TreeNodeMetadataValue createPath(AbstractMetadataValue leaf,
                                               boolean generated,
                                               String... parentPath)
Creates a tree structured path with the provided leaf at the end.

Parameters:
leaf - the leaf to put in the end.
generated - what the value's MetadataValue.isGenerated() should be.
parentPath - the path to the leaf.
Returns:
the root node of the path.

createTreePath

public static TreeNodeMetadataValue[] createTreePath(String description,
                                                     String... path)
Creates a straight tree-path. The method returns an array where index 0 is the root and index 1 is the leaf. The value's MetadataValue.isGenerated() will be true.

Parameters:
description - the description of the root.
path - the path to create.
Returns:
the root and the leaf.

createTreePath

public static TreeNodeMetadataValue[] createTreePath(String description,
                                                     boolean generated,
                                                     String... path)
Creates a straight tree-path. The method returns an array where index 0 is the root and index 1 is the leaf.

Parameters:
description - the description of the root.
generated - what the value's MetadataValue.isGenerated() should be.
path - the path to create.
Returns:
the root and the leaf.

getPath

public static <T extends Metadata> T getPath(MetadataParent<T> root,
                                             String... path)
Returns the node with the given path.

Type Parameters:
T - The type of metadata.
Parameters:
root - the root to start from when searching for the node with the given path.
path - the path for which a node should be returned.
Returns:
the value or null if it wasn't found.

getPath

public static <T extends Metadata> T getPath(Collection<T> collection,
                                             String... path)
Returns the node with the given path.

Type Parameters:
T - The type of metadata.
Parameters:
collection - a collection of nodes to use as root nodes when searching for the node with the given path.
path - the path for which a node should be returned.
Returns:
the value or null if it wasn't found.

getLeaf

public static <T extends Metadata> T getLeaf(MetadataParent<T> root,
                                             String... path)
Returns the leaf with the given path.

Type Parameters:
T - The type of metadata.
Parameters:
root - the root to start from when searching for the leaf node with the given path.
path - the path for which a leaf node should be returned.
Returns:
the leaf or null if it wasn't found or if the path doesn't represent a leaf.

getLeaf

public static <T extends Metadata> T getLeaf(Collection<T> collection,
                                             String... path)
Returns the leaf with the given path.

Type Parameters:
T - The type of metadata.
Parameters:
collection - the collection to start from.
path - the path for which a leaf node should be returned.
Returns:
the leaf or null if it wasn't found or if the path doesn't represent a leaf.

findLeaves

public static <T extends Metadata> void findLeaves(Collection<T> collection,
                                                   Collection<T> newCollection)
Adds all the leaves in the collection to the newCollection.

Type Parameters:
T - the type of Metadata.
Parameters:
collection - the Collection to find the leaves in.
newCollection - the result.

prettyPrint

public static String prettyPrint(MetadataValue value,
                                 String tabs)
Prints the value and it's child if any into a structured string.

Parameters:
value - the value to print
tabs - the current level
Returns:
a pretty string.

prettyPrint

public static String prettyPrint(Collection<MetadataValue> values,
                                 String tabs)
Prints the values and their children if any into a structured string.

Parameters:
values - the values to print
tabs - the current level.
Returns:
a pretty string.

getContainer

public static MetadataContainer getContainer(Metadata metadata)
Find the first MetadataContainer that is an ancestor to the given Metadata.

Parameters:
metadata - the Metadata to find a MetadataContainer for.
Returns:
the first MetadataContainer ancestor.


Copyright © 2004-2013. All Rights Reserved.