1 /* This file is part of the project "Hilbert II" - http://www.qedeq.org" target="alexandria_uri">http://www.qedeq.org
2 *
3 * Copyright 2000-2014, Michael Meyling <mime@qedeq.org>.
4 *
5 * "Hilbert II" is free software; you can redistribute
6 * it and/or modify it under the terms of the GNU General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16 package org.qedeq.kernel.bo.logic.model;
17
18 import org.qedeq.base.utility.Enumerator;
19 import org.qedeq.kernel.bo.logic.common.SubjectVariable;
20
21 /**
22 * One subject variable allocation for our model.
23 *
24 * @author Michael Meyling
25 */
26 public class SubjectVariableAllocation {
27
28 /** This subject variable. */
29 private final SubjectVariable variable;
30
31 /** Reference to current interpretation entity. */
32 private final Enumerator value;
33
34 /** Is this a fixed interpretatin? */
35 private boolean fixed;
36
37 /**
38 * Constructor.
39 *
40 * @param variable Subject variable.
41 */
42 public SubjectVariableAllocation(final SubjectVariable variable) {
43 this.variable = variable;
44 this.value = new Enumerator();
45 this.fixed = false;
46 }
47
48 /**
49 * Constructor.
50 *
51 * @param variable Subject variable.
52 * @param value Value for subject variable.
53 */
54 public SubjectVariableAllocation(final SubjectVariable variable, final int value) {
55 this.variable = variable;
56 this.value = new Enumerator(value);
57 this.fixed = true;
58 }
59
60 /**
61 * Get subject variable.
62 *
63 * @return Subject variable.
64 */
65 public SubjectVariable getVariable() {
66 return variable;
67 }
68
69 /**
70 * Is this a fixed interpretation?
71 *
72 * @return Is this a fixed interpretation?
73 */
74 public boolean isFixed() {
75 return fixed;
76 }
77
78 /**
79 * Get reference to current model entity.
80 *
81 * @return Entity number.
82 */
83 public int getValue() {
84 return value.getNumber();
85 }
86
87 /**
88 * Increase model entity number.
89 */
90 public void increaseNumber() {
91 if (fixed) {
92 throw new IllegalStateException("variable could not iterate: " + toString());
93 }
94 value.increaseNumber();
95 }
96
97 /**
98 * Reset model entity number.
99 */
100 public void resetNumber() {
101 if (fixed) {
102 throw new IllegalStateException("variable could not iterate: " + toString());
103 }
104 value.reset();
105 }
106
107 public String toString() {
108 return variable.toString() + "=" + value.getNumber();
109 }
110
111 }