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 java.lang.Object

The `Graph.Builder` can be used to construct a new `Graph` little by little.

### Nested Class Summary

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

### Constructor Summary

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

### Method Summary

All Methods Instance Methods Concrete Methods
`<T> Graph.Builder` `attr(java.util.function.BiConsumer<Graph,T> setter, T value)` Uses the given setter to set the attribute value.
`Graph.Builder` `attr(java.lang.String key, java.lang.Object value)` Puts the given key-value-pair into the `attributes map` of the `Graph` which is constructed by this `Graph.Builder`.
`Graph` `build()` Constructs a new `Graph` from the values which have been supplied to this `Graph.Builder`.
`Edge.Builder` `edge(java.lang.Object sourceNodeOrKey, java.lang.Object targetNodeOrKey)` Constructs a new `Edge.Builder`.
`Graph.Builder` `edges(java.util.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(java.lang.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(java.lang.Object key)` Constructs a new (identifiable) `Node.Builder`.
`Graph.Builder` `nodes(java.util.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 Detail

#### Builder

    public Builder()

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

### Method Detail

#### attr

    public <T> Graph.Builder attr(java.util.function.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(java.lang.String key,
                              java.lang.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(java.lang.Object sourceNodeOrKey,
                             java.lang.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(java.util.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(java.lang.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(java.lang.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(java.util.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.