24
24
25
25
package li.klass.fhem.domain.setlist
26
26
27
+ import li.klass.fhem.domain.setlist.typeEntry.NoArgSetListEntry
27
28
import li.klass.fhem.domain.setlist.typeEntry.NotFoundSetListEntry
28
29
import li.klass.fhem.domain.setlist.typeEntry.TextFieldSetListEntry
29
30
import org.apache.commons.lang3.StringUtils
@@ -42,11 +43,11 @@ class SetList constructor(val entries: Map<String, SetListEntry>) : Serializable
42
43
43
44
fun contains (vararg keys : String ): Boolean = contains(keys.toList())
44
45
45
- fun contains (keys : Iterable <String >): Boolean =
46
- keys.any { entries.containsKey(it) }
46
+ fun contains (keys : Iterable <String >): Boolean = keys.any { entries.containsKey(it) }
47
47
48
- fun existingStatesOf (toSearch : Set <String >): Set <String > =
49
- entries.keys.filter { toSearch.contains(it) }.toSet()
48
+ fun existingStatesOf (toSearch : Set <String >): Set <String > = entries.keys.filter {
49
+ toSearch.contains(it)
50
+ }.toSet()
50
51
51
52
fun size (): Int = entries.size
52
53
@@ -59,23 +60,26 @@ class SetList constructor(val entries: Map<String, SetListEntry>) : Serializable
59
60
.joinToString(separator = " " ) { it.asText() }
60
61
}
61
62
62
- fun getFirstPresentStateOf (vararg states : String ): String? =
63
- states.asSequence().firstOrNull { contains(it) }
63
+ fun getFirstPresentStateOf (
64
+ vararg states : String ): String? = states.asSequence().firstOrNull { contains(it) }
64
65
65
66
companion object {
66
67
fun parse (inputText : String ): SetList {
67
68
if (isEmpty(inputText)) return SetList (emptyMap())
68
69
69
- val parts = inputText.trim()
70
- .split(" " .toRegex()).toTypedArray()
70
+ val parts = inputText.trim().split(" " .toRegex()).toTypedArray()
71
71
72
72
return SetList (parts.mapNotNull { handlePart(it) }.toMap())
73
73
}
74
74
75
75
private fun handlePart (part : String ): Pair <String , SetListEntry >? {
76
76
77
77
if (! part.contains(" :" )) {
78
- return Pair (part, TextFieldSetListEntry (part))
78
+ val entry = when (part) {
79
+ " on" , " off" -> NoArgSetListEntry (part)
80
+ else -> TextFieldSetListEntry (part)
81
+ }
82
+ return Pair (part, entry)
79
83
}
80
84
81
85
val keyValue = part.split(" :" .toRegex(), 2 ).toTypedArray()
@@ -101,10 +105,9 @@ class SetList constructor(val entries: Map<String, SetListEntry>) : Serializable
101
105
return type
102
106
}
103
107
}
104
- return if (parts.isEmpty() || parts.isNotEmpty() && " colorpicker" .equals(parts[0 ], ignoreCase = true ))
105
- SetListItemType .NO_ARG
106
- else
107
- SetListItemType .GROUP
108
+ return if (parts.isEmpty() || parts.isNotEmpty() && " colorpicker" .equals(parts[0 ],
109
+ ignoreCase = true )) SetListItemType .NO_ARG
110
+ else SetListItemType .GROUP
108
111
}
109
112
}
110
113
}
0 commit comments