
org.camunda.bpm.dmn.engine.impl.DmnDecisionRuleResultImpl Maven / Gradle / Ivy
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.camunda.bpm.dmn.engine.impl;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.camunda.bpm.dmn.engine.DmnDecisionRuleResult;
import org.camunda.bpm.engine.variable.value.TypedValue;
public class DmnDecisionRuleResultImpl implements DmnDecisionRuleResult {
private static final long serialVersionUID = 1L;
public static final DmnEngineLogger LOG = DmnLogger.ENGINE_LOGGER;
protected final Map outputValues = new LinkedHashMap();
public void putValue(String name, TypedValue value) {
outputValues.put(name, value);
}
@SuppressWarnings("unchecked")
@Override
public T getEntry(String name) {
return (T) outputValues.get(name).getValue();
}
@SuppressWarnings("unchecked")
@Override
public T getEntryTyped(String name) {
return (T) outputValues.get(name);
}
@SuppressWarnings("unchecked")
@Override
public T getFirstEntryTyped() {
if (!outputValues.isEmpty()) {
return (T) outputValues.values().iterator().next();
} else {
return null;
}
}
@Override
public T getSingleEntryTyped() {
if (outputValues.size() > 1) {
throw LOG.decisionOutputHasMoreThanOneValue(this);
} else {
return getFirstEntryTyped();
}
}
@SuppressWarnings("unchecked")
public T getFirstEntry() {
if (!outputValues.isEmpty()) {
return (T) getFirstEntryTyped().getValue();
} else {
return null;
}
}
@SuppressWarnings("unchecked")
public T getSingleEntry() {
if (!outputValues.isEmpty()) {
return (T) getSingleEntryTyped().getValue();
} else {
return null;
}
}
@Override
public Map getEntryMap() {
Map valueMap = new HashMap();
for (String key : outputValues.keySet()) {
valueMap.put(key, get(key));
}
return valueMap;
}
public Map getEntryMapTyped() {
return outputValues;
}
@Override
public int size() {
return outputValues.size();
}
@Override
public boolean isEmpty() {
return outputValues.isEmpty();
}
@Override
public boolean containsKey(Object key) {
return outputValues.containsKey(key);
}
@Override
public Set keySet() {
return outputValues.keySet();
}
@Override
public Collection