com.hfg.util.ValueImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com_hfg Show documentation
Show all versions of com_hfg Show documentation
com.hfg xml, html, svg, and bioinformatics utility library
package com.hfg.util;
//------------------------------------------------------------------------------
/**
Simple implementation of the Value interface.
@author J. Alex Taylor, hairyfatguy.com
*/
//------------------------------------------------------------------------------
// com.hfg Library
//
// 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
//
// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
// [email protected]
//------------------------------------------------------------------------------
public class ValueImpl implements Value
{
private String mStringValue;
private Number mNumberValue;
private Boolean mBooleanValue;
//###########################################################################
// CONSTRUCTORS
//###########################################################################
//---------------------------------------------------------------------------
public ValueImpl(String inValue)
{
mStringValue = inValue;
}
//---------------------------------------------------------------------------
public ValueImpl(Number inValue)
{
mNumberValue = inValue;
}
//---------------------------------------------------------------------------
public ValueImpl(boolean inValue)
{
mBooleanValue = inValue;
}
//---------------------------------------------------------------------------
public ValueImpl(int inValue)
{
mNumberValue = inValue;
}
//---------------------------------------------------------------------------
public ValueImpl(long inValue)
{
mNumberValue = inValue;
}
//---------------------------------------------------------------------------
public ValueImpl(float inValue)
{
mNumberValue = inValue;
}
//---------------------------------------------------------------------------
public ValueImpl(double inValue)
{
mNumberValue = inValue;
}
//###########################################################################
// PUBLIC METHODS
//###########################################################################
//---------------------------------------------------------------------------
@Override
public boolean isNull()
{
return (null == mStringValue
&& null == mNumberValue
&& null == mBooleanValue);
}
//---------------------------------------------------------------------------
@Override
public String stringValue()
{
return (mStringValue != null ? mStringValue : mNumberValue != null ? mNumberValue.toString() : mBooleanValue != null ? mBooleanValue.toString() : null);
}
//---------------------------------------------------------------------------
@Override
public Boolean booleanValue()
{
return (mBooleanValue != null ? mBooleanValue : mNumberValue != null ? BooleanUtil.valueOf(mNumberValue) : mStringValue != null ? BooleanUtil.valueOf(mStringValue) : null);
}
//---------------------------------------------------------------------------
@Override
public Integer intValue()
{
return (mNumberValue != null ? mNumberValue.intValue() : mBooleanValue != null ? (mBooleanValue ? 1 : 0) : null);
}
//---------------------------------------------------------------------------
@Override
public Long longValue()
{
return (mNumberValue != null ? mNumberValue.longValue() : mBooleanValue != null ? (mBooleanValue ? 1 : 0) : null);
}
//---------------------------------------------------------------------------
@Override
public Float floatValue()
{
return (mNumberValue != null ? mNumberValue.floatValue() : mBooleanValue != null ? (mBooleanValue ? 1 : 0) : null);
}
//---------------------------------------------------------------------------
@Override
public Double doubleValue()
{
return (mNumberValue != null ? mNumberValue.doubleValue() : mBooleanValue != null ? (mBooleanValue ? 1 : 0) : null);
}
}