001 /* This file is part of the project "Hilbert II" - http://www.qedeq.org
002 *
003 * Copyright 2000-2011, Michael Meyling <mime@qedeq.org>.
004 *
005 * "Hilbert II" is free software; you can redistribute
006 * it and/or modify it under the terms of the GNU General Public
007 * License as published by the Free Software Foundation; either
008 * version 2 of the License, or (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013 * GNU General Public License for more details.
014 */
015
016 package org.qedeq.kernel.bo.logic.model;
017
018 import org.qedeq.base.utility.Enumerator;
019 import org.qedeq.kernel.bo.logic.common.SubjectVariable;
020
021 /**
022 * One subject variable allocation for our model.
023 *
024 * @author Michael Meyling
025 */
026 public class SubjectVariableAllocation {
027
028 /** This subject variable. */
029 private final SubjectVariable variable;
030
031 /** Reference to current interpretation entity. */
032 private final Enumerator value;
033
034 /** Is this a fixed interpretatin? */
035 private boolean fixed;
036
037 /**
038 * Constructor.
039 *
040 * @param variable Subject variable.
041 */
042 public SubjectVariableAllocation(final SubjectVariable variable) {
043 this.variable = variable;
044 this.value = new Enumerator();
045 this.fixed = false;
046 }
047
048 /**
049 * Constructor.
050 *
051 * @param variable Subject variable.
052 * @param value Value for subject variable.
053 */
054 public SubjectVariableAllocation(final SubjectVariable variable, final int value) {
055 this.variable = variable;
056 this.value = new Enumerator(value);
057 this.fixed = true;
058 }
059
060 /**
061 * Get subject variable.
062 *
063 * @return Subject variable.
064 */
065 public SubjectVariable getVariable() {
066 return variable;
067 }
068
069 /**
070 * Is this a fixed interpretation?
071 *
072 * @return Is this a fixed interpretation?
073 */
074 public boolean isFixed() {
075 return fixed;
076 }
077
078 /**
079 * Get reference to current model entity.
080 *
081 * @return Entity number.
082 */
083 public int getValue() {
084 return value.getNumber();
085 }
086
087 /**
088 * Increase model entity number.
089 */
090 public void increaseNumber() {
091 if (fixed) {
092 throw new IllegalStateException("variable could not iterate: " + toString());
093 }
094 value.increaseNumber();
095 }
096
097 /**
098 * Reset model entity number.
099 */
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 }
|