Class ThingBuilder
java.lang.Object
org.openhab.core.thing.binding.builder.ThingBuilder
- Direct Known Subclasses:
BridgeBuilder
This class allows the easy construction of a
Thing
instance using the builder pattern.- Author:
- Dennis Nobel - Initial contribution, Kai Kreuzer - Refactoring to make BridgeBuilder a subclass
-
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionprotected
ThingBuilder
(ThingTypeUID thingTypeUID, ThingUID thingUID) -
Method Summary
Modifier and TypeMethodDescriptionbuild()
Build the thingstatic ThingBuilder
Create a new thingThingBuilder
for a copy of the given thingstatic ThingBuilder
create
(ThingTypeUID thingTypeUID, String thingId) Create a newThingBuilder
static ThingBuilder
create
(ThingTypeUID thingTypeUID, ThingUID thingUID) Create a newThingBuilder
protected Thing
populate
(org.openhab.core.thing.internal.ThingImpl thing) withBridge
(@Nullable ThingUID bridgeUID) Set the bridge for this thingwithChannel
(Channel channel) Adds the given channel to the thingwithChannels
(List<Channel> channels) Replaces all channels of this thing with the given channelswithChannels
(Channel... channels) Replaces all channels of this thing with the given channelswithConfiguration
(Configuration configuration) Set (or replace) the configuration of the thingSets thelabel
for the thingwithLocation
(@Nullable String location) Set the location for this thingwithoutChannel
(ChannelUID channelUID) Removes the channel with the given UID from the thingwithoutChannels
(List<Channel> channels) Removes the given channels from the thingwithoutChannels
(Channel... channels) Removes the given channels from the thingwithProperties
(Map<String, String> properties) Set/replace the properties for this thingwithProperty
(String key, String value) Set / replace a single property for this thing
-
Field Details
-
thingUID
-
thingTypeUID
-
-
Constructor Details
-
ThingBuilder
-
-
Method Details
-
create
Create a newThingBuilder
- Parameters:
thingTypeUID
- theThingTypeUID
of the new thingthingId
- the id part of theThingUID
of the new thing- Returns:
- the created
ThingBuilder
-
create
Create a newThingBuilder
- Parameters:
thingTypeUID
- theThingTypeUID
of the new thingthingUID
- theThingUID
of the new thing- Returns:
- the created
ThingBuilder
-
create
Create a new thingThingBuilder
for a copy of the given thing- Parameters:
thing
- theThing
to create this builder from- Returns:
- the created
ThingBuilder
-
build
Build the thing- Returns:
- the
Thing
-
withLabel
Sets thelabel
for the thing- Parameters:
label
- a string containing the label- Returns:
- the
ThingBuilder
itself
-
withChannel
Adds the given channel to the thing- Parameters:
channel
- theChannel
- Returns:
- the
ThingBuilder
itself - Throws:
IllegalArgumentException
- if a channel with the same UID is already present or theChannelUID
is not valid
-
withChannels
Replaces all channels of this thing with the given channels- Parameters:
channels
- one or moreChannel
s- Returns:
- the
ThingBuilder
itself - Throws:
IllegalArgumentException
- if a channel with the same UID is already present or theChannelUID
is not valid
-
withChannels
Replaces all channels of this thing with the given channels- Parameters:
channels
- aList
ofChannel
s- Returns:
- the
ThingBuilder
itself - Throws:
IllegalArgumentException
- if a channel with the same UID is already present or theChannelUID
is not valid
-
withoutChannel
Removes the channel with the given UID from the thing- Parameters:
channelUID
- theChannelUID
of the channel- Returns:
- the
ThingBuilder
itself
-
withoutChannels
Removes the given channels from the thing- Parameters:
channels
- one or moreChannel
s- Returns:
- the
ThingBuilder
itself
-
withoutChannels
Removes the given channels from the thing- Parameters:
channels
- aList
ofChannel
s- Returns:
- the
ThingBuilder
itself
-
withConfiguration
Set (or replace) the configuration of the thing- Parameters:
configuration
- aConfiguration
for this thing- Returns:
- the
ThingBuilder
itself
-
withBridge
Set the bridge for this thing- Parameters:
bridgeUID
- theThingUID
of the bridge for the thing- Returns:
- the
ThingBuilder
itself
-
withProperty
Set / replace a single property for this thing- Parameters:
key
- the key / name of the propertyvalue
- the value of the property- Returns:
- the
ThingBuilder
itself
-
withProperties
Set/replace the properties for this thing- Parameters:
properties
- aMap<String,
containing the propertiesString> - Returns:
- the
ThingBuilder
itself
-
withLocation
Set the location for this thing- Parameters:
location
- a string wih the location of the thing- Returns:
- the
ThingBuilder
itself
-
populate
-