From 2d7d0550b59ebdf21b3297d0083654b054cf581f Mon Sep 17 00:00:00 2001 From: Christoph Weitkamp Date: Thu, 6 Sep 2018 08:36:39 +0200 Subject: [PATCH 1/2] ChannelGroupUID without '#' Signed-off-by: Christoph Weitkamp --- .../core/thing/ChannelGroupUIDTest.java | 14 ++----------- .../smarthome/core/thing/ChannelGroupUID.java | 20 ++----------------- 2 files changed, 4 insertions(+), 30 deletions(-) diff --git a/bundles/core/org.eclipse.smarthome.core.thing.test/src/test/java/org/eclipse/smarthome/core/thing/ChannelGroupUIDTest.java b/bundles/core/org.eclipse.smarthome.core.thing.test/src/test/java/org/eclipse/smarthome/core/thing/ChannelGroupUIDTest.java index 00d0d3728f2..f1a80e088b9 100644 --- a/bundles/core/org.eclipse.smarthome.core.thing.test/src/test/java/org/eclipse/smarthome/core/thing/ChannelGroupUIDTest.java +++ b/bundles/core/org.eclipse.smarthome.core.thing.test/src/test/java/org/eclipse/smarthome/core/thing/ChannelGroupUIDTest.java @@ -37,23 +37,13 @@ public void testInvalidCharacters() { @Test(expected = IllegalArgumentException.class) public void testNotEnoughNumberOfSegments() { - new ChannelUID("binding:thing-type:group#"); - } - - @Test(expected = IllegalArgumentException.class) - public void testMissingChannelGroupSeparator() { - new ChannelGroupUID("binding:thing-type:thing:group"); - } - - @Test(expected = IllegalArgumentException.class) - public void testMultipleChannelGroupSeparators() { - new ChannelGroupUID("binding:thing-type:thing:group#id#what_ever"); + new ChannelUID("binding:thing-type:group"); } @Test public void testChannelGroupUID() { ChannelGroupUID channelGroupUID = new ChannelGroupUID(THING_UID, GROUP_ID); - assertEquals("binding:thing-type:thing:group#", channelGroupUID.toString()); + assertEquals("binding:thing-type:thing:group", channelGroupUID.toString()); assertEquals(GROUP_ID, channelGroupUID.getId()); assertEquals(THING_UID, channelGroupUID.getThingUID()); } diff --git a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/ChannelGroupUID.java b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/ChannelGroupUID.java index db09062ea60..e10877305a5 100644 --- a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/ChannelGroupUID.java +++ b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/ChannelGroupUID.java @@ -25,9 +25,6 @@ @NonNullByDefault public class ChannelGroupUID extends UID { - private static final String CHANNEL_GROUP_SEGMENT_PATTERN = "[\\w-]*#"; - private static final String CHANNEL_GROUP_SEPERATOR = "#"; - /** * Default constructor in package scope only. Will allow to instantiate this * class by reflection. Not intended to be used for normal instantiation. @@ -50,7 +47,7 @@ public ChannelGroupUID(ThingUID thingUID, String id) { private static List toSegments(ThingUID thingUID, String id) { List ret = new ArrayList<>(thingUID.getAllSegments()); - ret.add(id + CHANNEL_GROUP_SEPERATOR); + ret.add(id); return ret; } @@ -61,7 +58,7 @@ private static List toSegments(ThingUID thingUID, String id) { */ public String getId() { List segments = getAllSegments(); - return segments.get(segments.size() - 1).replaceAll(CHANNEL_GROUP_SEPERATOR, ""); + return segments.get(segments.size() - 1); } @Override @@ -69,19 +66,6 @@ protected int getMinimalNumberOfSegments() { return 4; } - @Override - protected void validateSegment(String segment, int index, int length) { - if (index < length - 1) { - super.validateSegment(segment, index, length); - } else { - if (!segment.matches(CHANNEL_GROUP_SEGMENT_PATTERN)) { - throw new IllegalArgumentException(String.format( - "UID segment '%s' contains invalid characters. The last segment of the channel UID must match the pattern '%s'.", - segment, CHANNEL_GROUP_SEGMENT_PATTERN)); - } - } - } - /** * Returns the thing UID * From 7a467797c5c8ea5d3cddb0b1f76928e1072aa268 Mon Sep 17 00:00:00 2001 From: Christoph Weitkamp Date: Thu, 6 Sep 2018 08:45:49 +0200 Subject: [PATCH 2/2] Changed spelling of 'SEPARATOR' Signed-off-by: Christoph Weitkamp --- .../org/eclipse/smarthome/core/thing/ChannelUID.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/ChannelUID.java b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/ChannelUID.java index 93ac3850ba9..0a6490dd00e 100644 --- a/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/ChannelUID.java +++ b/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/ChannelUID.java @@ -31,7 +31,7 @@ public class ChannelUID extends UID { private static final String CHANNEL_SEGMENT_PATTERN = "[\\w-]*|[\\w-]*#[\\w-]*"; - private static final String CHANNEL_GROUP_SEPERATOR = "#"; + private static final String CHANNEL_GROUP_SEPARATOR = "#"; /** * Default constructor in package scope only. Will allow to instantiate this @@ -120,7 +120,7 @@ private static List toSegments(ThingUID thingUID, @Nullable String group } private static String getChannelId(@Nullable String groupId, String id) { - return groupId != null ? groupId + CHANNEL_GROUP_SEPERATOR + id : id; + return groupId != null ? groupId + CHANNEL_GROUP_SEPARATOR + id : id; } /** @@ -142,12 +142,12 @@ public String getIdWithoutGroup() { if (!isInGroup()) { return getId(); } else { - return getId().split(CHANNEL_GROUP_SEPERATOR)[1]; + return getId().split(CHANNEL_GROUP_SEPARATOR)[1]; } } public boolean isInGroup() { - return getId().contains(CHANNEL_GROUP_SEPERATOR); + return getId().contains(CHANNEL_GROUP_SEPARATOR); } /** @@ -156,7 +156,7 @@ public boolean isInGroup() { * @return group id or null if channel is not in a group */ public @Nullable String getGroupId() { - return isInGroup() ? getId().split(CHANNEL_GROUP_SEPERATOR)[0] : null; + return isInGroup() ? getId().split(CHANNEL_GROUP_SEPARATOR)[0] : null; } @Override