Package org.eclipse.gef.graph

# Class Graph.Builder

java.lang.Object
org.eclipse.gef.graph.Graph.Builder

Enclosing class:
  Graph

public static class Graph.Builder extends Object
The `Graph.Builder` can be used to construct a new `Graph` little by little.

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`protected class`
`Graph.Builder.Context`
A context object passed to nested builders when creating a builder chain.

## Constructor Summary

Constructors
Constructor
Description
`Builder()`
Constructs a new `Graph.Builder` without `Node`s and `Edge`s.

## Method Summary

Modifier and Type
Method
Description
`Graph.Builder`
`attr(String key, Object value)`
Puts the given key-value-pair into the `attributes map` of the `Graph` which is constructed by this `Graph.Builder`.
`<T> Graph.Builder`
`attr(BiConsumer<Graph,T> setter, T value)`
Uses the given setter to set the attribute value.
`Graph`
`build()`
Constructs a new `Graph` from the values which have been supplied to this `Graph.Builder`.
`Edge.Builder`
`edge(Object sourceNodeOrKey, Object targetNodeOrKey)`
Constructs a new `Edge.Builder`.
`Graph.Builder`
`edges(Collection<Edge> edges)`
Adds the given `Edge`s to the `Graph` which is constructed by this `Graph.Builder`.
`Graph.Builder`
`edges(Edge... edges)`
Adds the given `Edge`s to the `Graph` which is constructed by this `Graph.Builder`.
`protected Node`
`findOrCreateNode(Object key)`
Retrieves the node already created by a builder for the given key, or creates a new one via the respective `Node.Builder`.
`Node.Builder`
`node()`
Constructs a new (anonymous) `Node.Builder`.
`Node.Builder`
`node(Object key)`
Constructs a new (identifiable) `Node.Builder`.
`Graph.Builder`
`nodes(Collection<Node> nodes)`
Adds the given `Node`s to the `Graph` which is constructed by this `Graph.Builder`.
`Graph.Builder`
`nodes(Node... nodes)`
Adds the given `Node`s to the `Graph` which is constructed by this `Graph.Builder`.

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

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### Builder

public Builder()
Constructs a new `Graph.Builder` without `Node`s and `Edge`s.

## Method Details

### attr

public <T> Graph.Builder attr(BiConsumer<Graph,T> setter, T value)
Uses the given setter to set the attribute value.

Type Parameters:
  `T` - The type of the attribute.
Parameters:
  `setter` - The setter to apply.
  `value` - The value to apply.
Returns:
  `this` for convenience.

### attr

public Graph.Builder attr(String key, Object value)
Puts the given key-value-pair into the `attributes map` of the `Graph` which is constructed by this `Graph.Builder`.

Parameters:
  `key` - The attribute name which is inserted.
  `value` - The attribute value which is inserted.
Returns:
  `this` for convenience.

### build

public Graph build()
Constructs a new `Graph` from the values which have been supplied to this `Graph.Builder`.

Returns:
  A new `Graph` from the values which have been supplied to this `Graph.Builder`.

### edge

public Edge.Builder edge(Object sourceNodeOrKey, Object targetNodeOrKey)
Constructs a new `Edge.Builder`.

Parameters:
  `sourceNodeOrKey` - The source `Node` or a key to identify the source `Node` (or its `Node.Builder`).
  `targetNodeOrKey` - The target `Node` or a key to identify the target `Node` (or its `Node.Builder`).
Returns:
  A new `Edge.Builder`.

### edges

public Graph.Builder edges(Collection<Edge> edges)
Adds the given `Edge`s to the `Graph` which is constructed by this `Graph.Builder`.

Parameters:
  `edges` - The `Edge`s which are added to the `Graph` which is constructed by this `Graph.Builder`.
Returns:
  `this` for convenience.

### edges

public Graph.Builder edges(Edge... edges)
Adds the given `Edge`s to the `Graph` which is constructed by this `Graph.Builder`.

Parameters:
  `edges` - The `Edge`s which are added to the `Graph` which is constructed by this `Graph.Builder`.
Returns:
  `this` for convenience.

### findOrCreateNode

protected Node findOrCreateNode(Object key)
Retrieves the node already created by a builder for the given key, or creates a new one via the respective `Node.Builder`.

Parameters:
  `key` - The key to identify the `Node` or `Node.Builder`.
Returns:
  An existing or newly created `Node`.

### node

public Node.Builder node()
Constructs a new (anonymous) `Node.Builder`.

Returns:
  A new `Node.Builder`.

### node

public Node.Builder node(Object key)
Constructs a new (identifiable) `Node.Builder`.

Parameters:
  `key` - The key that can be used to identify the `Node.Builder`
Returns:
  A new `Node.Builder`.

### nodes

public Graph.Builder nodes(Collection<Node> nodes)
Adds the given `Node`s to the `Graph` which is constructed by this `Graph.Builder`.

Parameters:
  `nodes` - The `Node`s which are added to the `Graph` which is constructed by this `Graph.Builder`.
Returns:
  `this` for convenience.

### nodes

public Graph.Builder nodes(Node... nodes)
Adds the given `Node`s to the `Graph` which is constructed by this `Graph.Builder`.

Parameters:
  `nodes` - The `Node`s which are added to the `Graph` which is constructed by this `Graph.Builder`.
Returns:
  `this` for convenience.