Class StateBuilder
java.lang.Object
org.opendaylight.yang.gen.v1.http.openconfig.net.yang.local.routing.rev151009.local.routes.top.local.routes.StateBuilder
Class that builds
State
instances. Overall design of the class is that of a
fluent interface, where method chaining is used.
In general, this class is supposed to be used like this template:
State createState(int fooXyzzy, int barBaz) {
return new StateBuilder()
.setFoo(new FooBuilder().setXyzzy(fooXyzzy).build())
.setBar(new BarBuilder().setBaz(barBaz).build())
.build();
}
This pattern is supported by the immutable nature of State, as instances can be freely passed around without worrying about synchronization issues.
As a side note: method chaining results in:
- very efficient Java bytecode, as the method invocation result, in this case the Builder reference, is
on the stack, so further method invocations just need to fill method arguments for the next method
invocation, which is terminated by
build()
, which is then returned from the method - better understanding by humans, as the scope of mutable state (the builder) is kept to a minimum and is very localized
- better optimization opportunities, as the object scope is minimized in terms of invocation (rather than method) stack, making escape analysis a lot easier. Given enough compiler (JIT/AOT) prowess, the cost of th builder object can be completely eliminated
- See Also:
-
Constructor Summary
ConstructorDescriptionConstruct an empty builder.StateBuilder
(State base) Construct a builder initialized with state from specifiedState
.Construct a new builder initialized from specifiedLocalRoutesConfig
.Construct a new builder initialized from specifiedLocalRoutesState
. -
Method Summary
Modifier and TypeMethodDescriptionaddAugmentation
(org.opendaylight.yangtools.yang.binding.Augmentation<State> augmentation) Add an augmentation to this builder's product.<E$$ extends org.opendaylight.yangtools.yang.binding.Augmentation<State>>
E$$augmentation
(Class<E$$> augmentationType) Return the specified augmentation, if it is present in this builder.@NonNull State
build()
A newState
instance.static @NonNull State
empty()
Get empty instance of State.void
fieldsFrom
(org.opendaylight.yangtools.yang.binding.DataObject arg) Set fields from given grouping argument.removeAugmentation
(Class<? extends org.opendaylight.yangtools.yang.binding.Augmentation<State>> augmentationType) Remove an augmentation from this builder's product.
-
Constructor Details
-
StateBuilder
public StateBuilder()Construct an empty builder. -
StateBuilder
Construct a new builder initialized from specifiedLocalRoutesConfig
.- Parameters:
arg
- LocalRoutesConfig from which the builder should be initialized
-
StateBuilder
Construct a new builder initialized from specifiedLocalRoutesState
.- Parameters:
arg
- LocalRoutesState from which the builder should be initialized
-
StateBuilder
Construct a builder initialized with state from specifiedState
.- Parameters:
base
- State from which the builder should be initialized
-
-
Method Details
-
fieldsFrom
public void fieldsFrom(org.opendaylight.yangtools.yang.binding.DataObject arg) Set fields from given grouping argument. Valid argument is instance of one of following types:- Parameters:
arg
- grouping object- Throws:
IllegalArgumentException
- if given argument is none of valid types or has property with incompatible value
-
empty
Get empty instance of State.- Returns:
- An empty
State
-
augmentation
public <E$$ extends org.opendaylight.yangtools.yang.binding.Augmentation<State>> E$$ augmentation(Class<E$$> augmentationType) Return the specified augmentation, if it is present in this builder.- Type Parameters:
E$$
- augmentation type- Parameters:
augmentationType
- augmentation type class- Returns:
- Augmentation object from this builder, or
null
if not present - Throws:
NullPointerException
- ifaugmentType
isnull
-
addAugmentation
public StateBuilder addAugmentation(org.opendaylight.yangtools.yang.binding.Augmentation<State> augmentation) Add an augmentation to this builder's product.- Parameters:
augmentation
- augmentation to be added- Returns:
- this builder
- Throws:
NullPointerException
- ifaugmentation
is null
-
removeAugmentation
public StateBuilder removeAugmentation(Class<? extends org.opendaylight.yangtools.yang.binding.Augmentation<State>> augmentationType) Remove an augmentation from this builder's product. If this builder does not track such an augmentation type, this method does nothing.- Parameters:
augmentationType
- augmentation type to be removed- Returns:
- this builder
-
build
A newState
instance.- Returns:
- A new
State
instance.
-