visad
Class ScalarType

java.lang.Object
  extended by visad.MathType
      extended by visad.ScalarType
All Implemented Interfaces:
Serializable, Comparable
Direct Known Subclasses:
RealType, TextType

public abstract class ScalarType
extends MathType
implements Comparable

ScalarType is the superclass of the VisAD hierarchy of scalar data types.

See Also:
Serialized Form

Constructor Summary
ScalarType(String name)
          Create a ScalarType with the specified name.
 
Method Summary
 void alias(String alias)
          Change the primary name for this ScalarType.
 int compareTo(Object obj)
          Compares this object with another of the same type.
 boolean equals(Object obj)
          Indicates if this ScalarType is the same as another object.
 String getAlias()
          Returns the alias of this instance or null if this instance has no alias.
 String getName()
          Returns this ScalarType's name.
 String getNameWithBlanks()
           
 String getOriginalName()
          Returns the original name of this instance.
static ScalarType getScalarTypeByName(String name)
          Get the ScalarType which has the specified name.
 int hashCode()
          Obtains the hash code for this object.
protected  Object readResolve()
          Returns the instance corresponding to this newly deserialized instance.
static void validateName(String name, String type)
          Throw a TypeException if the name is invalid.
 
Methods inherited from class visad.MathType
addTimeAlias, binary, buildShadowType, cloneDerivative, equalsExceptName, equalsExceptNameButUnits, findScalarType, guessMaps, main, missingData, prettyString, prettyString, stringToType, toString, unary
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ScalarType

public ScalarType(String name)
           throws VisADException
Create a ScalarType with the specified name.

Parameters:
name - The name of this ScalarType
Throws:
VisADException - If the name is not valid.
Method Detail

compareTo

public int compareTo(Object obj)
Compares this object with another of the same type. The comparison is on the names.

Specified by:
compareTo in interface Comparable
Parameters:
obj - The other object of the same type.
Returns:
A value less than zero, zero, or greater than zero depending on whether this object is considered less than, equal to, or greater than the other object, respectively.
Throws:
ClassCastException - if the object is not a ScalarType.

equals

public boolean equals(Object obj)
Indicates if this ScalarType is the same as another object.

Specified by:
equals in class MathType
Parameters:
obj - The other object.
Returns:
true if and only if the other object is a ScalarType and compares equal to this ScalarType.

hashCode

public int hashCode()
Obtains the hash code for this object. If scalarType1.equals(scalarType2), then scalarType1.hashCode() == scalarType2.hashCode().

Overrides:
hashCode in class Object
Returns:
The hash code for this object.

alias

public void alias(String alias)
           throws TypeException
Change the primary name for this ScalarType. The original name can still be used.

If multiple aliases are created, the last one is dominant.

This is handy for translating standard VisAD RealType names to a language other than English.

Parameters:
alias - The new name.
Throws:
TypeException - If the new name is not valid.

getName

public final String getName()
Returns this ScalarType's name. If an alias exists, then it it is returned; otherwise, the name given to the constructor is used.

Returns:
The name of this ScalarType.

getOriginalName

public final String getOriginalName()
Returns the original name of this instance. This method ignores any alias and returns the name given to the constructor.

Returns:
The original name.

getAlias

public final String getAlias()
Returns the alias of this instance or null if this instance has no alias. This method returns the alias set by the most recent alias(String) invocation.

Returns:
The alias or null.

getNameWithBlanks

public String getNameWithBlanks()

getScalarTypeByName

public static ScalarType getScalarTypeByName(String name)
Get the ScalarType which has the specified name.

Parameters:
name - Name of ScalarType.
Returns:
Either the ScalarType if found, or null.

validateName

public static void validateName(String name,
                                String type)
                         throws TypeException
Throw a TypeException if the name is invalid.

Parameters:
name - Name to check.
type - Type used in exception message.
Throws:
TypeException - If there is a problem with the name.

readResolve

protected final Object readResolve()
                            throws InvalidObjectException

Returns the instance corresponding to this newly deserialized instance. If a ScalarType with the same name as this instance already exists and is compatible with this instance, then it is returned. Otherwise, this instance is returned.

This method is protected so that it is always invoked during deserialization and final to prevent subclasses from evading it.

Returns:
the unique ScalarType object corresponding to this object's name.
Throws:
InvalidObjectException - if an incompatible ScalarType with the same name as this instance already exists.