Skip to content

Commit f5d341c

Browse files
authored
Merge pull request #147 from jkbelcher/tagsUnmod
Refinements to registry tags
2 parents 44829fd + f70571d commit f5d341c

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

src/main/java/heronarts/lx/LXRegistry.java

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
import heronarts.lx.pattern.LXPattern;
7272
import heronarts.lx.pattern.PatternRack;
7373
import heronarts.lx.structure.LXFixture;
74+
import heronarts.lx.utils.LXUtils;
7475

7576
/**
7677
* Registry container for content classes used by the LX implementation
@@ -290,8 +291,8 @@ public LXRegistry removeListener(Listener listener) {
290291
/**
291292
* Globally registered tags
292293
*/
293-
public final Map<Class<? extends LXComponent>, List<String>> tags =
294-
Collections.unmodifiableMap(this.mutableTags);
294+
private final Map<Class<? extends LXComponent>, List<String>> tags =
295+
new HashMap<>();
295296

296297
private final List<Class<? extends LXBlend>> mutableChannelBlends =
297298
new ArrayList<Class<? extends LXBlend>>(DEFAULT_CHANNEL_BLENDS);
@@ -400,7 +401,6 @@ private JsonFixture(File file, String prefix) {
400401
*/
401402
public final List<LXClassLoader.Package> packages = Collections.unmodifiableList(this.mutablePackages);
402403

403-
404404
private final List<Plugin> mutablePlugins = new ArrayList<Plugin>();
405405

406406
/**
@@ -556,6 +556,19 @@ public void dispose() {
556556
public LXRegistry(LX lx) {
557557
this.lx = lx;
558558
this.classLoader = new LXClassLoader(lx);
559+
560+
for (Class<? extends LXPattern> pattern : DEFAULT_PATTERNS) {
561+
addDefaultTags(pattern);
562+
}
563+
for (Class<? extends LXEffect> effect : DEFAULT_EFFECTS) {
564+
addDefaultTags(effect);
565+
}
566+
for (Class<? extends LXModulator> modulator : DEFAULT_MODULATORS) {
567+
addDefaultTags(modulator);
568+
}
569+
for (Class<? extends LXFixture> fixture : DEFAULT_FIXTURES) {
570+
addDefaultTags(fixture);
571+
}
559572
}
560573

561574
public LXClassLoader getClassLoader() {
@@ -1186,10 +1199,17 @@ private void addDefaultTags(Class<? extends LXComponent> component) {
11861199
* @return this
11871200
*/
11881201
public LXRegistry addTag(Class<? extends LXComponent> component, String tag) {
1202+
if (tag == null) {
1203+
throw new IllegalArgumentException("Tag may not be null for class " + component.getName());
1204+
} else if (!tag.matches("^[a-zA-Z0-9/]+$")) {
1205+
throw new IllegalArgumentException("Tag '" + tag + "' for class " + component.getName() + " contains illegal characters - only alphanumerics and slashes allowed");
1206+
}
11891207
List<String> tags = this.mutableTags.get(component);
11901208
if (tags == null) {
11911209
tags = new ArrayList<String>();
1210+
List<String> unmodifiableTags = Collections.unmodifiableList(tags);
11921211
this.mutableTags.put(component, tags);
1212+
this.tags.put(component, unmodifiableTags);
11931213
}
11941214
if (tags.contains(tag)) {
11951215
LX.error("Cannot add duplicate tag \"" + tag + "\" to class " + component.getName());
@@ -1215,6 +1235,7 @@ public LXRegistry removeTag(Class<? extends LXComponent> component, String tag)
12151235
tags.remove(tag);
12161236
if (tags.isEmpty()) {
12171237
this.mutableTags.remove(component);
1238+
this.tags.remove(component);
12181239
}
12191240
return this;
12201241
}
@@ -1223,10 +1244,10 @@ public LXRegistry removeTag(Class<? extends LXComponent> component, String tag)
12231244
* Get the set of tags for a given component class
12241245
*
12251246
* @param component Component type
1226-
* @return this
1247+
* @return An unmodifiable list of tags, or null if no tags exist
12271248
*/
12281249
public List<String> getTags(Class<? extends LXComponent> component) {
1229-
return this.mutableTags.get(component);
1250+
return this.tags.get(component);
12301251
}
12311252

12321253
/**

0 commit comments

Comments
 (0)