DependencyState.java
001 /* This file is part of the project "Hilbert II" - http://www.qedeq.org
002  *
003  * Copyright 2000-2013,  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.se.common;
017 
018 
019 /**
020  * Represents a mathematical module state. All existing instances of this class are the public
021  * constants of this class.
022  *
023  @author  Michael Meyling
024  */
025 public final class DependencyState implements State {
026 
027     /** Undefined loading state. */
028     public static final DependencyState STATE_UNDEFINED = new DependencyState(
029         DependencyStateDescriptions.STATE_STRING_UNDEFINED, false,
030         DependencyStateDescriptions.STATE_CODE_UNDEFINED);
031 
032     /** Loading required modules. */
033     public static final DependencyState STATE_LOADING_REQUIRED_MODULES = new DependencyState(
034         DependencyStateDescriptions.STATE_STRING_LOADING_REQUIRED_MODULES, false,
035         DependencyStateDescriptions.STATE_CODE_LOADING_REQUIRED_MODULES);
036 
037     /** Loading required modules failed. */
038     public static final DependencyState STATE_LOADING_REQUIRED_MODULES_FAILED = new DependencyState(
039         DependencyStateDescriptions.STATE_STRING_LOADING_REQUIRED_MODULES_FAILED, true,
040         DependencyStateDescriptions.STATE_CODE_LOADING_REQUIRED_MODULES_FAILED);
041 
042     /** Completely loaded. */
043     public static final DependencyState STATE_LOADED_REQUIRED_MODULES = new DependencyState(
044         DependencyStateDescriptions.STATE_STRING_LOADED_REQUIRED_MODULES, false,
045         DependencyStateDescriptions.STATE_CODE_LOADED_REQUIRED_MODULES);
046 
047 
048     /** meaning of this state. */
049     private final String text;
050 
051     /** is this state a failure? */
052     private final boolean failure;
053 
054     /** Code for state. */
055     private final int code;
056 
057     /**
058      * Creates new module state.
059      *
060      @param   text    meaning of this state, <code>null</code> is not permitted.
061      @param   failure is this a failure state?
062      @param   code    code of this state.
063      @throws  IllegalArgumentException    text == <code>null</code>
064      */
065     private DependencyState(final String text, final boolean failure, final int code) {
066         this.text = text;
067         if (this.text == null) {
068             throw new IllegalArgumentException("text==null");
069         }
070         this.failure = failure;
071         this.code = code;
072     }
073 
074     public String getText() {
075         return this.text;
076     }
077 
078     public boolean isFailure() {
079         return this.failure;
080     }
081 
082     /**
083      * Are all required modules loaded?
084      *
085      @return  Are all required modules loaded?
086      */
087     public boolean areAllRequiredLoaded() {
088         return this.code == STATE_LOADED_REQUIRED_MODULES.getCode();
089     }
090 
091     public int getCode() {
092         return this.code;
093     }
094 
095     public String toString() {
096         return this.text;
097     }
098 
099     public int hashCode() {
100         return this.text.hashCode();
101     }
102 
103     public final boolean equals(final Object obj) {
104         // every instance is unique
105         return (this == obj);
106     }
107 
108 }