Revert ThingImpl and BridgeImpl changes as the storage uses those implementations (#719)
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>pull/723/head
parent
48ce8357f5
commit
0aa7661764
|
@ -15,8 +15,7 @@ package org.eclipse.smarthome.core.thing.internal;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
@ -32,14 +31,18 @@ import org.slf4j.LoggerFactory;
|
|||
/**
|
||||
*
|
||||
* @author Denis Nobel - Initial contribution
|
||||
* @author Christoph Weitkamp - Changed internal handling of things and added method `getThing(ThingUID)`
|
||||
* @author Christoph Weitkamp - Added method `getThing(ThingUID)`
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class BridgeImpl extends ThingImpl implements Bridge {
|
||||
|
||||
private final transient Logger logger = LoggerFactory.getLogger(BridgeImpl.class);
|
||||
|
||||
private final transient Map<ThingUID, Thing> things = new ConcurrentHashMap<>();
|
||||
/*
|
||||
* !!! DO NOT CHANGE - We are not allowed to change the members of the BridgeImpl implementation as the storage for
|
||||
* things uses this implementation itself to store and restore the data.
|
||||
*/
|
||||
private transient List<Thing> things = new CopyOnWriteArrayList<>();
|
||||
|
||||
/**
|
||||
* Package protected default constructor to allow reflective instantiation.
|
||||
|
@ -73,21 +76,26 @@ public class BridgeImpl extends ThingImpl implements Bridge {
|
|||
}
|
||||
|
||||
public void addThing(Thing thing) {
|
||||
things.put(thing.getUID(), thing);
|
||||
things.add(thing);
|
||||
}
|
||||
|
||||
public void removeThing(Thing thing) {
|
||||
things.remove(thing.getUID(), thing);
|
||||
things.remove(thing);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Thing getThing(ThingUID thingUID) {
|
||||
return things.get(thingUID);
|
||||
for (Thing thing : things) {
|
||||
if (thing.getUID().equals(thingUID)) {
|
||||
return thing;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Thing> getThings() {
|
||||
return Collections.unmodifiableList(new ArrayList<>(things.values()));
|
||||
return Collections.unmodifiableList(new ArrayList<>(things));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -45,16 +45,20 @@ import org.eclipse.smarthome.core.thing.binding.builder.ThingStatusInfoBuilder;
|
|||
* ThingType Description
|
||||
* @author Thomas Höfer - Added thing and thing type properties
|
||||
* @author Simon Kaufmann - Added label
|
||||
* @author Christoph Weitkamp - Changed internal handling of things and added method `getChannel(ChannelUID)`
|
||||
* @author Christoph Weitkamp - Added method `getChannel(ChannelUID)`
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class ThingImpl implements Thing {
|
||||
|
||||
/*
|
||||
* !!! DO NOT CHANGE - We are not allowed to change the members of the ThingImpl implementation as the storage for
|
||||
* things uses this implementation itself to store and restore the data.
|
||||
*/
|
||||
private @Nullable String label;
|
||||
|
||||
private @Nullable ThingUID bridgeUID;
|
||||
|
||||
private final Map<ChannelUID, Channel> channels = new HashMap<>();
|
||||
private List<Channel> channels = new ArrayList<>();
|
||||
|
||||
private Configuration configuration = new Configuration();
|
||||
|
||||
|
@ -133,13 +137,13 @@ public class ThingImpl implements Thing {
|
|||
|
||||
@Override
|
||||
public List<Channel> getChannels() {
|
||||
return Collections.unmodifiableList(new ArrayList<>(this.channels.values()));
|
||||
return Collections.unmodifiableList(new ArrayList<>(this.channels));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Channel> getChannelsOfGroup(String channelGroupId) {
|
||||
List<Channel> channels = new ArrayList<>();
|
||||
for (Channel channel : this.channels.values()) {
|
||||
for (Channel channel : this.channels) {
|
||||
if (channelGroupId.equals(channel.getUID().getGroupId())) {
|
||||
channels.add(channel);
|
||||
}
|
||||
|
@ -149,13 +153,17 @@ public class ThingImpl implements Thing {
|
|||
|
||||
@Override
|
||||
public @Nullable Channel getChannel(String channelId) {
|
||||
ChannelUID channelUID = new ChannelUID(uid, channelId);
|
||||
return getChannel(channelUID);
|
||||
for (Channel channel : this.channels) {
|
||||
if (channel.getUID().getId().equals(channelId)) {
|
||||
return channel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Channel getChannel(ChannelUID channelUID) {
|
||||
return this.channels.get(channelUID);
|
||||
return getChannel(channelUID.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -189,7 +197,7 @@ public class ThingImpl implements Thing {
|
|||
}
|
||||
|
||||
public void addChannel(Channel channel) {
|
||||
this.channels.put(channel.getUID(), channel);
|
||||
this.channels.add(channel);
|
||||
}
|
||||
|
||||
public void setChannels(List<Channel> channels) {
|
||||
|
|
Loading…
Reference in New Issue