LoadingState.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  * Represents a module state. Every instance of this class is unique.
020  *
021  @author Michael Meyling
022  */
023 public final class LoadingState implements State {
024 
025     /** Undefined loading state. */
026     public static final LoadingState STATE_UNDEFINED = new LoadingState(
027         LoadingStateDescriptions.STATE_STRING_UNDEFINED, false,
028         LoadingStateDescriptions.STATE_CODE_UNDEFINED);
029 
030     /** Trying to access web address. */
031     public static final LoadingState STATE_LOCATING_WITHIN_WEB = new LoadingState(
032         LoadingStateDescriptions.STATE_STRING_LOCATING_WITHIN_WEB, false,
033         LoadingStateDescriptions.STATE_CODE_LOCATING_WITHIN_WEB);
034 
035     /** Try to access web address failed. */
036     public static final LoadingState STATE_LOCATING_WITHIN_WEB_FAILED = new LoadingState(
037         LoadingStateDescriptions.STATE_STRING_LOCATING_WITHIN_WEB_FAILED, true,
038         LoadingStateDescriptions.STATE_CODE_LOCATING_WITHIN_WEB_FAILED);
039 
040     /** Loading from web address. */
041     public static final LoadingState STATE_LOADING_FROM_WEB = new LoadingState(
042         LoadingStateDescriptions.STATE_STRING_LOADING_FROM_WEB, false,
043         LoadingStateDescriptions.STATE_CODE_LOADING_FROM_WEB);
044 
045     /** Loading from web address failed. */
046     public static final LoadingState STATE_LOADING_FROM_WEB_FAILED = new LoadingState(
047         LoadingStateDescriptions.STATE_STRING_LOADING_FROM_WEB_FAILED, true,
048         LoadingStateDescriptions.STATE_CODE_LOADING_FROM_WEB_FAILED);
049 
050     /** Loading from local file. */
051     public static final LoadingState STATE_LOADING_FROM_LOCAL_FILE = new LoadingState(
052         LoadingStateDescriptions.STATE_STRING_LOADING_FROM_LOCAL_FILE, false,
053         LoadingStateDescriptions.STATE_CODE_LOADING_FROM_LOCAL_FILE);
054 
055     /** Loading from local file failed. */
056     public static final LoadingState STATE_LOADING_FROM_LOCAL_FILE_FAILED = new LoadingState(
057         LoadingStateDescriptions.STATE_STRING_LOADING_FROM_LOCAL_FILE_FAILED, true,
058         LoadingStateDescriptions.STATE_CODE_LOADING_FROM_LOCAL_FILE_FAILED);
059 
060     /** Loading from local file buffer. */
061     public static final LoadingState STATE_LOADING_FROM_BUFFER = new LoadingState(
062         LoadingStateDescriptions.STATE_STRING_LOADING_FROM_BUFFER, false,
063         LoadingStateDescriptions.STATE_CODE_LOADING_FROM_BUFFER);
064 
065     /** Loading from local file buffer failed. */
066     public static final LoadingState STATE_LOADING_FROM_BUFFER_FAILED = new LoadingState(
067         LoadingStateDescriptions.STATE_STRING_LOADING_FROM_BUFFER_FAILED, true,
068         LoadingStateDescriptions.STATE_CODE_LOADING_FROM_BUFFER_FAILED);
069 
070     /** Loading into memory. */
071     public static final LoadingState STATE_LOADING_INTO_MEMORY = new LoadingState(
072         LoadingStateDescriptions.STATE_STRING_LOADING_INTO_MEMORY, false,
073         LoadingStateDescriptions.STATE_CODE_LOADING_INTO_MEMORY);
074 
075     /** Loading into memory failed. */
076     public static final LoadingState STATE_LOADING_INTO_MEMORY_FAILED = new LoadingState(
077         LoadingStateDescriptions.STATE_STRING_LOADING_INTO_MEMORY_FAILED, true,
078         LoadingStateDescriptions.STATE_CODE_LOADING_INTO_MEMORY_FAILED);
079 
080     /** Completely loaded. */
081     public static final LoadingState STATE_LOADED = new LoadingState(
082         LoadingStateDescriptions.STATE_STRING_LOADED, false,
083         LoadingStateDescriptions.STATE_CODE_LOADED);
084 
085     /** Deleted. */
086     public static final LoadingState STATE_DELETED = new LoadingState(
087         LoadingStateDescriptions.STATE_STRING_DELETED, false,
088         LoadingStateDescriptions.STATE_CODE_DELETED);
089 
090     /** meaning of this state. */
091     private final String text;
092 
093     /** is this state a failure? */
094     private final boolean failure;
095 
096     /** Code for state. */
097     private final int code;
098 
099     /**
100      * Creates new module state.
101      *
102      @param text meaning of this state, <code>null</code> is not permitted.
103      @param failure is this a failure state?
104      @param code code of this state.
105      @throws IllegalArgumentException text == <code>null</code>
106      */
107     private LoadingState(final String text, final boolean failure, final int code) {
108         this.text = text;
109         if (this.text == null) {
110             throw new IllegalArgumentException("text==null");
111         }
112         this.failure = failure;
113         this.code = code;
114     }
115 
116     public String getText() {
117         return this.text;
118     }
119 
120     public boolean isFailure() {
121         return this.failure;
122     }
123 
124     public int getCode() {
125         return this.code;
126     }
127 
128     public String toString() {
129         return this.text;
130     }
131 
132     public int hashCode() {
133         return this.text.hashCode();
134     }
135 
136     public final boolean equals(final Object obj) {
137         // every instance is unique
138         return (this == obj);
139     }
140 
141 }