aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/logic/src/main/java/tools/refinery/logic/valuation/Valuation.java
blob: 95ee887ec0000096883d5002352aec8c815a3c22 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
 * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/>
 *
 * SPDX-License-Identifier: EPL-2.0
 */
package tools.refinery.logic.valuation;

import org.jetbrains.annotations.Nullable;
import tools.refinery.logic.substitution.Substitution;
import tools.refinery.logic.term.AnyDataVariable;
import tools.refinery.logic.term.DataVariable;

import java.util.Map;
import java.util.Set;

public interface Valuation {
	<T> T getValue(DataVariable<T> variable);

	default Valuation substitute(@Nullable Substitution substitution) {
		if (substitution == null) {
			return this;
		}
		return new SubstitutedValuation(this, substitution);
	}

	default Valuation restrict(Set<? extends AnyDataVariable> allowedVariables) {
		return new RestrictedValuation(this, Set.copyOf(allowedVariables));
	}

	static ValuationBuilder builder() {
		return new ValuationBuilder();
	}

	static Valuation empty() {
		return new MapBasedValuation(Map.of());
	}
}