/*
This file is part of the software framework JStatCom,
a library for building applications for data based analysis.
Copyright (C) 2000-2005 Markus Kraetzig
This library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
*/
package com.jstatcom.ts;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import javax.swing.Icon;
import javax.swing.ImageIcon;
/**
* This class contains an enumeration of constants that define different types
* of time series.
*
* It implements the typesave enum pattern (Joshua Bloch, "Effective
* Java", Item 21) . If you compare TSTypes, always use
* the == operator. This is save, because they are Singletons
* (Gamma et al., 1995) .
*
* @author Markus Kraetzig
*/
public class TSTypes {
/**
* The name of the ConfigKey.
*/
private final String NAME;
private Icon icon = null;
private static Map typeMap = new HashMap();
/**
* Type for endogenous series.
*/
public static final TSTypes ENDOGENOUS = new TSTypes("ENDOGENOUS");
/**
* Type for exogenous series.
*/
public static final TSTypes EXOGENOUS = new TSTypes("EXOGENOUS");
/**
* Type for deterministic series.
*/
public static final TSTypes DETERMINISTIC = new TSTypes("DETERMINISTIC");
/**
* Creates a TSTypes with a descriptive name.
*
* @param name
* identifier
* @throws IllegalStateException
* if a type with the same name has already been created before
* @throws IllegalArgumentException
* if (name == null)
*/
public TSTypes(String name) {
if (name == null)
throw new IllegalArgumentException("Argument was null.");
this.NAME = name.toUpperCase();
if (typeMap.containsKey(NAME))
throw new IllegalStateException(
"An instance of TSTypes with the name \""
+ NAME
+ "\" has already been created.\nChoose a different name.");
typeMap.put(NAME, this);
}
/**
* Factory method that gets a reference to the static type from an
* identifying string. The lookup is case insensitive.
*
* @param str
* type name
* @return singleton instance for the type name, or null if
* no such type exists
* @throws IllegalArgumentException
* if (str == null)
*/
public static final TSTypes valueOf(String str) {
if (str == null)
throw new IllegalArgumentException("Argument was null.");
return typeMap.get(str.toUpperCase());
}
/**
* Override prevention method to enforce a.equals(b) if and
* only if a==b.
*
* @param o
* object to compare with
* @return true if equal, false otherwise
*/
public final boolean equals(Object o) {
return super.equals(o);
}
/**
* Gets the respective icon that visualizes the property.
*
* @return icon for visualization of this type
*/
public Icon getIcon() {
if (icon == null) {
URL loc = getClass().getResource(
"/images/" + NAME.toLowerCase() + ".gif");
icon = (loc != null) ? new ImageIcon(loc) : null;
}
return icon;
}
/**
* Gets the name of the type. Do not use for comparisons, but compare by
* reference.
*
* @return name of this type
*/
public final String getName() {
return NAME;
}
/**
* Override prevention method invokes super method.
*
* @return hash code
*/
public final int hashCode() {
return super.hashCode();
}
/**
* Returns a string representation of the type, do not use for comparisons.
*
* @return string representing this type
*/
public final String toString() {
return NAME;
}
}
Ads help maintain this website.