| ConvertHelp.java |
package de.spieleck.config;
/**
* Helperclass for type conversions.
* Could be a wrapper do * org.apache.commons.beanutils.converters.
*/
public class ConvertHelp
{
private ConvertHelp() {}
public static boolean getBoolean(String value)
{
if (value == null)
return false;
else
return !value.equals("false") && !value.equals("no")
&& !value.equals("nein") && !value.equals("0");
}
public static boolean getBoolean(ConfigNode node, boolean deflt)
{
return node == null
? deflt
: node.getBoolean();
}
public static int getInt(String value)
{
if (value == null || value.equals(""))
return 0;
else
{
try
{
return Integer.parseInt(value);
}
catch (Exception e)
{
return 0;
}
}
}
public static int getInt(ConfigNode node, int deflt)
{
return node == null
? deflt
: node.getInt();
}
public static double getDouble(String value)
{
if (value == null)
return 0;
else
{
try
{
return Double.valueOf(value).doubleValue();
}
catch (Exception e)
{
return Double.NaN;
}
}
}
public static double getDouble(ConfigNode node, double deflt)
{
return node == null
? deflt
: node.getDouble();
}
public static String getString(ConfigNode node, String deflt)
{
return node == null
? deflt
: node.getString();
}
}
//
// Jacson - Text Filtering with Java.
// Copyright (C) 2002 Frank S. Nestel (nestefan -at- users.sourceforge.net)
//
// 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
//
| ConvertHelp.java |