/*
 * 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: Long.h,v 1.20 2002/09/20 17:24:29 florian Exp $
 */

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

namespace jakelib {
  namespace lang {

    /**
     * @brief An instance of this class encapsulates a single \c jlong value.
     * \c Long objects can be used as hash keys for example.
     * Some class methods provide functions to convert strings to long integers
     * and vice versa.
     *
     * @class Long
     * @version $Id: Long.h,v 1.20 2002/09/20 17:24:29 florian Exp $
     * @author Florian 'Overflo' Wolff (florian@donuz.de)
     */
    class Long : public Number, Comparable
      {
      private:
		/** @brief The actual \c jlong value */
		jlong value;

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

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

	/**
	 * @brief Returns a hashcode for the long integer value. 
	 *
	 * @return hash code
	 */
	jint hashCode();
  
	/**
	 * @brief Returns the string representation of the Long value.
	 *
	 * @return String representation
	 */
	String* toString();
  
	/**
	 * @brief Returns the string representation of the given long integer value.
	 *
	 * @param value Long value.
	 * @return String representation
	 */
	static String* toString(jlong value);
  
	/**
	 * Returns the string representation of the given long integer value.
	 *
	 * @param value Long value.
	 * @param radix The radix (Character::MIN_RADIX .. Character::MAX_RADIX)
	 * @return String representation
	 */
	static String* toString(jlong 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>Long</code> object that contains
	 * the same <code>jlong</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(jlong i);
	static String* toHexString(jlong i);
	static String* toBinaryString(jlong i);
	static String* toUnsignedString(jlong i, int shift);

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

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

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

	/**
	 *
	 * @throws NumberFormatException If the \c String cannot be parsed
	 */
	static jlong parseLong(String* str, int radix);
  
	int compareTo(Long* obj);
	int compareTo(Object* obj);

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

	static const jlong MAX_VALUE;
	static const jlong MIN_VALUE;

	JAKELIB_DECLARE_CLASS(Long);
      };
  }
}

#endif

