/*
 * @(#)HexXFloat.java    2.3  23 June 2003
 *
 * Copyright 2004
 * College of Computer and Information Science
 * Northeastern University
 * Boston, MA  02115
 *
 * The Java Power Tools software may be used for educational
 * purposes as long as this copyright notice is retained intact
 * at the top of all source files.
 *
 * To discuss possible commercial use of this software, 
 * contact Richard Rasala at Northeastern University, 
 * College of Computer and Information Science,
 * 617-373-2462 or rasala@ccs.neu.edu.
 *
 * The Java Power Tools software has been designed and built
 * in collaboration with Viera Proulx and Jeff Raab.
 *
 * Should this software be modified, the words "Modified from 
 * Original" must be included as a comment below this notice.
 *
 * All publication rights are retained.  This software or its 
 * documentation may not be published in any media either
 * in whole or in part without explicit permission.
 *
 * This software was created with support from Northeastern 
 * University and from NSF grant DUE-9950829.
 */

package edu.neu.ccs;

import edu.neu.ccs.util.*;
import java.text.*;

/**
 * <P>Class <CODE>HexXFloat</CODE> extends <CODE>XFloat</CODE>
 * by replacing the three methods:
 * <CODE>fromStringData</CODE>,
 * <CODE>toStringData</CODE>,
 * and <CODE>toString</CODE>,
 * to use hexadecimal digits rather than decimal digits.<P>
 *
 * @author  Richard Rasala
 * @version 2.3
 * @since   2.3
 */
public class HexXFloat extends XFloat {
    
    /**
     * Constructs a wrapper for the default <CODE>float</CODE> value.
     *
     * @see #HexXFloat(float)
     * @see #HexXFloat(String)
     */
    public HexXFloat() { }
    
    
    /**
     * Constructs a wrapper for the given <CODE>float</CODE> value.
     *
     * @param x the value to be wrapped
     * @see #HexXFloat()
     * @see #HexXFloat(String)
     */
    public HexXFloat(float x) { super(x); }
    
    
    /**
     * Constructs a wrapper for the byte value whose state information
     * is encapsulated in the given hexadecimal <CODE>String</CODE> data
     * of length exactly 8.
     *
     * @param s a hexadecimal <CODE>String</CODE> representation of the
     *          desired value
     * @see #HexXFloat()
     * @see #HexXFloat(float)
     * @see #fromStringData(String)
     * @throws ParseException if s is not hexadecimal with exactly 8 digits
     */
    public HexXFloat(String s) throws ParseException { super(s); }
    
    
    /**
     * <P>Sets the state of this object using information contained in the
     * given hexadecimal <CODE>String</CODE> of length exactly 8.</P>
     *
     * <P>Uses <CODE>Hex.hexToFloat</CODE> internally.</P>
     *
     * @param s a hexadecimal <CODE>String</CODE> representation of the
     *          desired value
     * @see Hex#hexToFloat(String)
     * @throws ParseException if s is not hexadecimal with exactly 8 digits
     */
    public void fromStringData(String s)
        throws ParseException
    {
        setValue(Hex.hexToFloat(s));
    }
    
    
    /**
     * <P>Returns a hexadecimal <CODE>String</CODE> encapsulation of this object
     * that contains the information needed to set the state of this object at a
     * later time.</P>
     *
     * <P>Uses <CODE>Hex.floatToHex</CODE> internally.</P>
     *
     * @return a hexadecimal <CODE>String</CODE> encapsulation of this object
     * @see Hex#floatToHex(float)
     */
    public String toStringData() {
        return Hex.floatToHex(getValue());
    }
    
    
    /**
     * <P>Returns the same <CODE>String</CODE> as <CODE>toStringData</CODE>.</P>
     *
     * @return a hexadecimal <CODE>String</CODE> encapsulation of this object
     * @see #toStringData()
     */
    public String toString() {
        return toStringData();
    }
    
}
