JFCML - JFC/Swing
XML Markup Language

com.metasolutions.jfcml.helpers
Class Primative

java.lang.Object
  extended by com.metasolutions.jfcml.helpers.Primative

public class Primative
extends Object

Used by the JFCML interpreter to internally classify primitive entities. This class is a generic, immutable wrapper for the Java primitive wrapper classes (Byte,Boolean,Character,etc). As such, it provides a generic way to access the TYPE field belonging to the aforementioned classes.

Additionally, this class provides a mechanism to perform any valid cast on the wrapped primitive. For convenience, a constructor is declared for all primitive types.

New parsing abilities have been added to this class to support parsing Strings into Primative Objects, or arrays of Primative Objects. Supported syntax includes:

Version:
0.9, May 29, 2005
Author:
Shawn Curry
See Also:
ReflectionHandler

Field Summary
 Class TYPE
          The type of the primitive entity that this instance represents.
 
Constructor Summary
Primative(boolean b)
          Construct a Primitive from a boolean.
Primative(byte b)
          Construct a Primitive from a byte.
Primative(char c)
          Construct a Primitive from a char.
Primative(Class type, Object val)
          Construct a Primitive from a Java wrapper class.
Primative(double d)
          Construct a Primitive from a double.
Primative(float f)
          Construct a Primitive from a float.
Primative(int i)
          Construct a Primitive from an int.
Primative(long l)
          Construct a Primitive from a long.
Primative(short s)
          Construct a Primitive from a short.
 
Method Summary
static Primative castToType(Class toCastTo, Primative toCast)
          Casts a Primative to another type.
 Object getValue()
          Returns the wrapped value.
static void main(String[] args)
           
static Primative parsePrimative(String s)
           
static Primative[] parsePrimatives(String spec)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TYPE

public final Class TYPE
The type of the primitive entity that this instance represents.

Constructor Detail

Primative

public Primative(boolean b)
Construct a Primitive from a boolean.

Parameters:
b - the boolean to wrap.

Primative

public Primative(byte b)
Construct a Primitive from a byte.

Parameters:
b - the byte to wrap.

Primative

public Primative(char c)
Construct a Primitive from a char.

Parameters:
c - the char to wrap.

Primative

public Primative(double d)
Construct a Primitive from a double.

Parameters:
d - the double to wrap.

Primative

public Primative(float f)
Construct a Primitive from a float.

Parameters:
f - the float to wrap.

Primative

public Primative(int i)
Construct a Primitive from an int.

Parameters:
i - the int to wrap.

Primative

public Primative(long l)
Construct a Primitive from a long.

Parameters:
l - the long to wrap.

Primative

public Primative(short s)
Construct a Primitive from a short.

Parameters:
s - the short to wrap.

Primative

public Primative(Class type,
                 Object val)
Construct a Primitive from a Java wrapper class.

Parameters:
type - the primative Class.
val - the primative value.
Throws:
RuntimeException - if the specified Class is not primative, or if the specified value is not primative.
Method Detail

getValue

public Object getValue()
Returns the wrapped value.

Returns:
the primative value, in it's standard Java wrapper class.

castToType

public static Primative castToType(Class toCastTo,
                                   Primative toCast)
Casts a Primative to another type.

Parameters:
toCastTo - the Class to cast to
toCast - the Primative Object to cast.
Returns:
the new Primative Object.
Throws:
IllegalArgumentException - if the specified Class is not primative, or if the specified Primative is a boolean, and the specified class not boolean.

toString

public String toString()
Overrides:
toString in class Object

parsePrimative

public static Primative parsePrimative(String s)

parsePrimatives

public static Primative[] parsePrimatives(String spec)

main

public static void main(String[] args)

SourceForge.net
java.net

Copyright 2004-2005 Shawn Curry, http://jfcml.sourceforge.net
Licensed under the Academic Free License version 2.1