aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/logic/src/main/java/tools/refinery/logic/valuation/MapBasedValuation.java
blob: be1862d2d84bba5500e53c61841aa381c068b259 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*
 * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/>
 *
 * SPDX-License-Identifier: EPL-2.0
 */
package tools.refinery.logic.valuation;

import tools.refinery.logic.term.AnyDataVariable;
import tools.refinery.logic.term.DataVariable;

import java.util.Map;

record MapBasedValuation(Map<AnyDataVariable, Object> values) implements Valuation {
	@Override
	public <T> T getValue(DataVariable<T> variable) {
		if (!values.containsKey(variable)) {
			throw new IllegalArgumentException("No value for variable %s".formatted(variable));
		}
		var value = values.get(variable);
		return variable.getType().cast(value);
	}
}