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

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

public final class ParentUtil
extends Object

Utility class for handling merge operation inside MetadataParents.

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

Method Summary
static
<T extends Metadata>
Collection<T>
addChildValue(MetadataParent<T> parent, Collection<T> children, T value)
          Adds a value as a child to the parent.
static
<T extends Metadata>
Collection<T>
addChildValues(MetadataParent parent, Collection<T> children, Collection<T> values)
          Adds the values as children to the parent.
static
<T extends Metadata>
int
getChildIndex(List<T> children, String name)
          Utility method for MetadataParent.indexOf(String) }.
static Collection<String> getChildNames(MetadataParent<MetadataValue> parent)
          Gets the child names of the given parent.
static
<T extends Metadata>
T
getChildValue(Collection<T> values, String name)
          Utility method for MetadataParent.getChild(String).
static void removeChild(Collection<? extends Metadata> list, Metadata value)
          Removes a child from a list of children.
static void removeChild(MetadataParent parent, Metadata child)
          Removes a child from a parent.
static
<T extends Metadata>
void
removeEmptyBranches(Collection<T> collection)
          Removes all tree nodes without children from the collection.
static void removeEmptyBranches(MetadataParent parent)
          Removes all tree nodes without children from the parent.
static void replaceChild(MetadataParent<MetadataValue> parent, MetadataValue value)
          Replaces an existing value amongst the parent's children.
static void replaceChildren(MetadataParent<MetadataValue> parent, List<MetadataValue> children)
          Adds the children in a list to a parent, replacing any existing children already present.
static net.sf.json.JSON toJson(MetadataContainer<MetadataValue> container)
          Converts the container into a JSON object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

removeChild

public static void removeChild(MetadataParent parent,
                               Metadata child)
Removes a child from a parent.

Parameters:
parent - the parent.
child - the child to remove.

removeChild

public static void removeChild(Collection<? extends Metadata> list,
                               Metadata value)
Removes a child from a list of children.

Parameters:
list - the list.
value - the child to remove.

removeEmptyBranches

public static void removeEmptyBranches(MetadataParent parent)
Removes all tree nodes without children from the parent.

Parameters:
parent - the parent to start with.

removeEmptyBranches

public static <T extends Metadata> void removeEmptyBranches(Collection<T> collection)
Removes all tree nodes without children from the collection.

Type Parameters:
T - the Metadata type.
Parameters:
collection - the collection to remove empty trees from.

replaceChild

public static void replaceChild(MetadataParent<MetadataValue> parent,
                                MetadataValue value)
Replaces an existing value amongst the parent's children.

Parameters:
parent - the parent to add/replace the child to
value - the value to replace

replaceChildren

public static void replaceChildren(MetadataParent<MetadataValue> parent,
                                   List<MetadataValue> children)
Adds the children in a list to a parent, replacing any existing children already present.

Parameters:
parent - the parent to add to.
children - the children to add/replace

addChildValue

public static <T extends Metadata> Collection<T> addChildValue(MetadataParent<T> parent,
                                                               Collection<T> children,
                                                               T value)
Adds a value as a child to the parent. Help utility for those who implement MetadataParent.addChild(Metadata)

Type Parameters:
T - the type for parent, children, value and the return value.
Parameters:
parent - the parent
children - the direct list of the parents children.
value - the value to add.
Returns:
the value(s) that failed to be added.

addChildValues

public static <T extends Metadata> Collection<T> addChildValues(MetadataParent parent,
                                                                Collection<T> children,
                                                                Collection<T> values)
Adds the values as children to the parent. Help utility for those who implement addChild(com.sonyericsson.hudson.plugins.metadata.model.Metadata)

Type Parameters:
T - the type for parent, children, values and the return value.
Parameters:
parent - the parent to add the values to
children - the direct list of the parents children.
values - the values to add.
Returns:
the values that failed to be added.

getChildValue

public static <T extends Metadata> T getChildValue(Collection<T> values,
                                                   String name)
Utility method for MetadataParent.getChild(String).

Type Parameters:
T - the type for values, name and the return value.
Parameters:
values - the list of children.
name - the name to search.
Returns:
the child if found or null if not.

getChildIndex

public static <T extends Metadata> int getChildIndex(List<T> children,
                                                     String name)
Utility method for MetadataParent.indexOf(String) }.

Type Parameters:
T - the type for values, name and the return value.
Parameters:
children - the list of children.
name - the name to search.
Returns:
the index of the child if found or -1 if not.

toJson

public static net.sf.json.JSON toJson(MetadataContainer<MetadataValue> container)
Converts the container into a JSON object. This processing is different from MetadataValue.toJson() because it will only convert the children not the entire object, since a container (like MetadataJobProperty) in essence doesn't have a name.

Parameters:
container - the container
Returns:
the JSON representation.

getChildNames

public static Collection<String> getChildNames(MetadataParent<MetadataValue> parent)
Gets the child names of the given parent.

Parameters:
parent - the parent to get the child names from.
Returns:
the child names.


Copyright © 2004-2013. All Rights Reserved.