Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
  • Loading branch information
jimtng committed Mar 1, 2025
1 parent 1c8229a commit 7bdfc2b
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions bundles/org.openhab.core.semantics/model/generateTagClasses.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ import java.util.stream.Collectors

baseDir = Paths.get(getClass().protectionDomain.codeSource.location.toURI()).getParent().getParent().toAbsolutePath()
header = header()
tagsByType = [:]

def tagSets = new TreeMap<String, String>()
def tagsCsv() {
return parseCsv(new FileReader("${baseDir}/model/SemanticTags.csv"), separator: ',')
}

def labelsFile = new FileWriter("${baseDir}/src/main/resources/tags.properties")
labelsFile.write("# Generated content - do not edit!\n")
Expand All @@ -37,6 +35,11 @@ for (line in tagsCsv()) {

appendLabelsFile(labelsFile, line, tagSet)

if (!tagsByType.containsKey(line.Type)) {
tagsByType[line.Type] = []
}
tagsByType[line.Type].add(line)

switch(line.Type) {
case "Location" : break;
case "Equipment" : break;
Expand All @@ -56,6 +59,10 @@ for (String tagSet : tagSets) {
println tagSet
}

def tagsCsv() {
return parseCsv(new FileReader("${baseDir}/model/SemanticTags.csv"), separator: ',')
}

def appendLabelsFile(FileWriter file, def line, String tagSet) {
file.write(tagSet + "=" + line.Label)
if (line.Synonyms) {
Expand Down Expand Up @@ -90,18 +97,11 @@ public class DefaultSemanticTags {
public static final SemanticTag POINT = new SemanticTagImpl("Point", "", "", "");
public static final SemanticTag PROPERTY = new SemanticTagImpl("Property", "", "", "");
""")
def tags = [:]
for (line in tagsCsv()) {
if (!tags.containsKey(line.Type)) {
tags[line.Type] = []
}
tags[line.Type].add(line)
}

for (type in tags.keySet()) {
for (type in tagsByType.keySet()) {
file.write("""
public static class ${type} {""")
for (line in tags[type]) {
for (line in tagsByType[type]) {
def tagId = (line.Parent ? tagSets.get(line.Parent) : line.Type) + "_" + line.Tag
def constantName = camelToUpperCasedSnake(line.Tag)
file.write("""
Expand Down

0 comments on commit 7bdfc2b

Please sign in to comment.