/*
 * Jakelib2 - General purpose C++ library
 * Copyright (C) 2001 Florian Wolff  (florian@donuz.de)
 *
 * 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
 *
 * $Id: Integer.h,v 1.29 2002/12/28 11:30:34 florian Exp $
 */

#ifndef INCLUDE_JAKELIB2_LANG_INTEGER_H
# define INCLUDE_JAKELIB2_LANG_INTEGER_H
# include "Number.h"

namespace jakelib {
  namespace lang {

    /**
     * @brief An instance of this class encapsulates a single \c jint value.
     * \c Integer objects can be used as hash keys for example.
     * Some class methods provide functions to convert strings to integers 
     * and vice versa.
     *
     * @class Integer
     * @version $Id: Integer.h,v 1.29 2002/12/28 11:30:34 florian Exp $
     * @author Florian 'Overflo' Wolff (florian@donuz.de)
     * @todo \c decode is not yet implemented
     */
    class Integer : public Number, Comparable
      {
      private:
	/** @brief The actual \c jint value */
	jint value;

      public:
	/**
	 * @brief Creates a new \c Integer object with the given \c jint value.
	 */
	Integer(jint value);

	/**
	 * @brief Creates a new \c Integer object. The given \c String is
	 * parsed and converted to \c jint.
	 *
	 * @throws NumberFormatException If the \c String cannot be parsed
	 */
	Integer(String* s);

	JAKELIB_DECLARE_CLASS(Integer);
  
	/**
	 * @brief Returns a hashcode for the integer value. 
	 *
	 * @return hash code
	 */
	jint hashCode();
  
	/**
	 * @brief Returns the string representation of the Integer value.
	 *
	 * @return String representation
	 */
	String* toString();
  
	/**
	 * @brief Returns the string representation of the given integer value.
	 *
	 * @param value Integer value.
	 * @return String representation
	 */
	static String* toString(jint value);
  
	/**
	 * Returns the string representation of the given integer value.
	 *
	 * @param value Integer value.
	 * @param radix The radix (Character::MIN_RADIX .. Character::MAX_RADIX)
	 * @return String representation
	 */
	static String* toString(jint value, int radix);
  
	/**
	 * @brief Compares this object to the specified object.
	 *
	 * The result is <code>true</code> if and only if the argument is not
	 * <code>null</code> and is an <code>Integer</code> object that contains
	 * the same <code>jint</code> value as this object.
	 *
	 * @param   obj   the object to compare with.
	 * @return  <code>true</code> if the objects are the same;
	 *          <code>false</code> otherwise.
	 */
	jboolean equals(Object* obj);
    
	/**
	 * @brief Returns the number represented by this object converted to <tt>jbyte</tt>.
	 */
	jbyte byteValue();

	/**
	 * @brief Returns the number represented by this object converted to <tt>jdouble</tt>.
	 */
	jdouble doubleValue();

	/**
	 * @brief Returns the number represented by this object converted to <tt>jfloat</tt>.
	 */
	jfloat floatValue();

	/**
	 * @brief Returns the number represented by this object converted to <tt>jint</tt>.
	 */
	jint intValue();

	/**
	 * @brief Returns the number represented by this object converted to <tt>jlong</tt>.
	 */
	jlong longValue();

	/**
	 * @brief Returns the number represented by this object converted to <tt>jshort</tt>.
	 */
	jshort shortValue();

	static String* toOctalString(jint i);
	static String* toHexString(jint i);
	static String* toBinaryString(jint i);
	static String* toUnsignedString(jint i, int shift);

	/**
	 *
	 * @throws NumberFormatException If the \c String cannot be parsed
	 */
	static Integer* valueOf(String* str, int radix);

	/**
	 *
	 * @throws NumberFormatException If the \c String cannot be parsed
	 */
	static Integer* valueOf(String* str);

	/**
	 *
	 * @throws NumberFormatException If the \c String cannot be parsed
	 */
	static jint parseInt(String *str, int radix = 10);

	/**
	 *
	 * @throws NumberFormatException If the string cannot be parsed
	 */
	static jint parseInt(const char *str, int radix = 10);
  
	int compareTo(Integer* obj);
	int compareTo(Object* obj);

/* 	static Integer* decode(String* str); */

	static const jint MAX_VALUE;
	static const jint MIN_VALUE;
	static const char* digits;
      };

  }
}

#endif

