@@ -87,16 +87,10 @@ public boolean getLabelValue(State state, String label) throws PrismLangExceptio
8787 * @return Returns a {@link Map} containing all label-values for the given state, indexed by their name.
8888 * @throws PrismLangException In case a label couldn't be evaluated.
8989 */
90- public Map <String , Boolean > getLabelValues (State state ) throws PrismLangException
90+ public Predicate <String > getLabelValues (State state ) throws PrismLangException
9191 {
92- // convert BitSet to Map to provide intuitiv interface
93- BitSet value = getStateValues (state );
94- Map <String , Boolean > labelValueMap = new HashMap <>();
95- for (int i = 0 , numLabels = labelList .size (); i < numLabels ; i ++){
96- labelValueMap .put (labelList .getLabelName (i ), value .get (i ));
97- }
98- return labelValueMap ;
99- }
92+ return asPredicate (getStateValues (state ));
93+ }
10094
10195 /**
10296 * This method provides all values of a certain label. They will be ordered by the given statesList. <br>
@@ -146,15 +140,35 @@ protected BitSet getStateValues(State state) throws PrismLangException
146140 private BitSet evaluateState (State state ) throws PrismLangException
147141 {
148142 int numLabels = labelList .size ();
149- Map <String , Boolean > labelValues = new HashMap <>(numLabels );
150143 BitSet values = new BitSet ();
144+ Predicate <String > labelValues = asPredicate (values );
151145 for (int i : evaluationOrder ) {
152146 Expression label = labelList .getLabel (i );
153147 boolean labelValue = label .evaluateBoolean (null , labelValues , state );
154- labelValues .put (labelList .getLabelName (i ), labelValue );
155148 values .set (i , labelValue );
156149 }
157150 stateValues .put (state , values );
158151 return values ;
159152 }
153+
154+ /**
155+ * Convert the label values for a state to a predicate on the label names.
156+ *
157+ * @param values the label values for some state
158+ * @return a Predicate evaluating to {@code true} for a label name iff the Bit at the corresponding index in {@code values} is set
159+ */
160+ public Predicate <String > asPredicate (BitSet values )
161+ {
162+ return new Predicate <String >() {
163+ @ Override
164+ public boolean test (String name )
165+ {
166+ int index = labelList .getLabelIndex (name );
167+ if (index == -1 ) {
168+ throw new NoSuchElementException ("Unknown label \" " + name + "\" " );
169+ }
170+ return values .get (index );
171+ }
172+ };
173+ }
160174}
0 commit comments