| 1 | package org.qedeq.kernel.se.state; |
| 2 | |
| 3 | import org.qedeq.kernel.se.common.State; |
| 4 | |
| 5 | /** |
| 6 | * Represents a module state. All existing instances of this class should be unique. |
| 7 | * |
| 8 | * @author Michael Meyling |
| 9 | */ |
| 10 | public abstract class AbstractState implements State { |
| 11 | |
| 12 | /** Meaning of this state. */ |
| 13 | private final String text; |
| 14 | |
| 15 | /** Is this state a failure? */ |
| 16 | private final boolean failure; |
| 17 | |
| 18 | /** Code for state. */ |
| 19 | private final int code; |
| 20 | |
| 21 | /** |
| 22 | * Creates new module state. |
| 23 | * |
| 24 | * @param text meaning of this state, <code>null</code> is not permitted. |
| 25 | * @param failure is this a failure state? |
| 26 | * @param code code of this state. |
| 27 | * @throws IllegalArgumentException text == <code>null</code> |
| 28 | */ |
| 29 | protected AbstractState(final String text, final boolean failure, final int code) { |
| 30 | this.text = text; |
| 31 | if (this.text == null) { |
| 32 | throw new IllegalArgumentException("text==null"); |
| 33 | } |
| 34 | this.failure = failure; |
| 35 | this.code = code; |
| 36 | } |
| 37 | |
| 38 | public String getText() { |
| 39 | return this.text; |
| 40 | } |
| 41 | |
| 42 | public boolean isFailure() { |
| 43 | return this.failure; |
| 44 | } |
| 45 | |
| 46 | public int getCode() { |
| 47 | return this.code; |
| 48 | } |
| 49 | |
| 50 | public String toString() { |
| 51 | return this.text; |
| 52 | } |
| 53 | |
| 54 | public int hashCode() { |
| 55 | return this.text.hashCode(); |
| 56 | } |
| 57 | |
| 58 | public boolean equals(final Object obj) { |
| 59 | // every instance is unique |
| 60 | return (this == obj); |
| 61 | } |
| 62 | |
| 63 | } |