Class Primitive

java.lang.Object
org.djunits.util.Primitive

public final class Primitive extends Object
The Primitive class is a utility class to deal with primitives. Besides widening and unwidening this class casts and parses UTF8 strings into appropriate primitive classes.

Copyright (c) 2002-2009 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved.

See for project information www.getSI()mulation.tudelft.nl.

The DSOL project is distributed under the following BSD-style license:
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • Neither the name of Delft University of Technology, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
This software is provided by the copyright holders and contributors "as is" and any express or implied warranties, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. In no event shall the copyright holder or contributors be liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage.
Version:
$Revision: 1.2 $ $Date: 2009/10/21 07:32:43 $
Author:
Peter Jacobs
  • Method Details

    • cast

      public static Object[] cast(Class<?>[] classes, Object[] values)
      casts a set of values to classes.
      Parameters:
      classes - the classes to cast to
      values - the values
      Returns:
      the newly creates values
    • cast

      public static Object cast(Class<?> clazz, Object object)
      casts an object to a instance of clazz.
      Parameters:
      clazz - the class to cast to
      object - the object to cast
      Returns:
      the casted object
    • forName

      public static Class<?> forName(String className)
      returns the primitiveClass of the name given as defined by the Java VM class constants. (i.e. both "int" and "I" return int.class). Both void and "V" return void.class. null is returned whenever an unknown className is given.
      Parameters:
      className - the className
      Returns:
      Class the primitiveClass
    • getPrimitive

      public static Class<?> getPrimitive(Class<?> wrapperClass)
      gets the primitive of the given wrapperClass.
      Parameters:
      wrapperClass - the wrapper class
      Returns:
      the primitive Class. null is returned whenever wrapperClass is not a wrapperclass.
    • getWrapper

      public static Class<?> getWrapper(Class<?> primitiveClass)
      gets the wrapper of this primitive class.
      Parameters:
      primitiveClass - the primitive class
      Returns:
      the Class. null is returned whenever wrapperClass is not a wrapperclass.
    • toBoolean

      public static Boolean toBoolean(Object object)
      casts an object to Boolean.
      Parameters:
      object - the object
      Returns:
      Boolean
    • toByte

      public static Byte toByte(Object object)
      casts an object to Byte.
      Parameters:
      object - the object
      Returns:
      Byte
    • toCharacter

      public static Character toCharacter(Object object)
      casts an object to Character.
      Parameters:
      object - the object to parse
      Returns:
      Integer the result
    • toDouble

      public static Double toDouble(Object object)
      casts an object to Double.
      Parameters:
      object - the object to parse
      Returns:
      Integer the result
    • toFloat

      public static Float toFloat(Object object)
      casts an object to Float.
      Parameters:
      object - the object to parse
      Returns:
      Float the result
    • toLong

      public static Long toLong(Object object)
      casts an object to Long.
      Parameters:
      object - the object to parse
      Returns:
      Long the result
    • toShort

      public static Short toShort(Object object)
      casts an object to Short.
      Parameters:
      object - the object to parse
      Returns:
      Long the result
    • toInteger

      public static Integer toInteger(Object object)
      casts an object to Integer.
      Parameters:
      object - the object to parse
      Returns:
      Integer the result