diff options
Diffstat (limited to 'wizards/com/sun/star/wizards/common/NumericalHelper.java')
-rw-r--r-- | wizards/com/sun/star/wizards/common/NumericalHelper.java | 369 |
1 files changed, 18 insertions, 351 deletions
diff --git a/wizards/com/sun/star/wizards/common/NumericalHelper.java b/wizards/com/sun/star/wizards/common/NumericalHelper.java index f8dfbc163d3a..3e9778d48925 100644 --- a/wizards/com/sun/star/wizards/common/NumericalHelper.java +++ b/wizards/com/sun/star/wizards/common/NumericalHelper.java @@ -59,25 +59,7 @@ public class NumericalHelper // private c'tor, so no one can instantiate } - /** - * get the type of an object: returns all types that can possibly converted - * with this class. - * @param obj an object that is checked for conversion - * @return the type of the object - */ - public static int getType(Object obj) - { - try - { - TypeObject aTypeObject = getTypeObject(obj); - return aTypeObject.iType; - } - catch (com.sun.star.lang.IllegalArgumentException e) - { - // ignore this one; just return unknown type - } - return UNKNOWN_TYPE; - } + /** * get a byte value from the object @@ -135,68 +117,7 @@ public class NumericalHelper return retValue; } - /** - * get a char value from the object - * @return a char - * @throws com.sun.star.lang.IllegalArgumentException if the object cannot be converted - */ - public static char toChar(Object aValue) - throws com.sun.star.lang.IllegalArgumentException - { - char retValue = 0; - TypeObject aTypeObject = getTypeObject(aValue); - switch (aTypeObject.iType) - { - case CHAR_TYPE: - retValue = getChar(aTypeObject); - break; - case BYTE_TYPE: - retValue = (char) getByte(aTypeObject); - break; - case SHORT_TYPE: - retValue = (char) getShort(aTypeObject); - break; - case INT_TYPE: - retValue = (char) getInt(aTypeObject); - break; - case LONG_TYPE: - retValue = (char) getLong(aTypeObject); - break; - case FLOAT_TYPE: - retValue = (char) getFloat(aTypeObject); - break; - case DOUBLE_TYPE: - retValue = (char) getDouble(aTypeObject); - break; - case STRING_TYPE: - try - { - String s = (String) aTypeObject.aValue; - if (s.length() > 0) - { - retValue = s.charAt(0); - } - else - { - retValue = (char) 0; - } - } - catch (java.lang.NumberFormatException e) - { - throw new com.sun.star.lang.IllegalArgumentException( - "Cannot convert to char: " + aTypeObject.aValue); - } - break; - case BOOLEAN_TYPE: - retValue = getBool(aTypeObject) ? (char) -1 : (char) 0; - break; - default: - throw new com.sun.star.lang.IllegalArgumentException( - "Cannot convert this type: " + aValue.getClass().getName()); - } - return retValue; - } /** * get a short value from the object @@ -253,42 +174,11 @@ public class NumericalHelper return retValue; } - public static boolean isValidAndNumerical(Object aValue) throws com.sun.star.lang.IllegalArgumentException - { - if (aValue != null) - { - if (!AnyConverter.isVoid(aValue)) - { - return (NumericalHelper.isNumerical(aValue)); - } - } - return false; - } - public static boolean isValidAndBoolean(Object aValue) throws com.sun.star.lang.IllegalArgumentException - { - if (aValue != null) - { - if (!AnyConverter.isVoid(aValue)) - { - int nType = AnyConverter.getType(aValue).getTypeClass().getValue(); - return (nType == TypeClass.BOOLEAN_value); - } - } - return false; - } - public static boolean isValid(Object aValue) - { - if (aValue != null) - { - if (!AnyConverter.isVoid(aValue)) - { - return true; - } - } - return false; - } + + + /** @param aValue a object this can contain anything @@ -320,16 +210,7 @@ public class NumericalHelper } } - /** - @param _aValue a object this can contain anything - @return true, if the parameter aValue is type of real numbers - see also http://en.wikipedia.org/wiki/Mathematics - */ - public static boolean isRealNumber(Object _aValue) - { - return isNumerical(_aValue); - } /** @param aValue a object this can contain anything @@ -351,43 +232,9 @@ public class NumericalHelper } } - /** - * Can a given object be converted to a String array? - * @param aValue the object to test - * @return true, if the object can be converted to a String array. - */ - public static boolean isStringArray(Object aValue) - { - try - { - toStringArray(aValue); - return true; - } - catch (com.sun.star.lang.IllegalArgumentException e) - { - // ignore - } - return false; - } - /** - * Can a given object be converted to an int array? - * @param aValue the object to test - * @return true, if the object can be converted to an Integer array. - */ - public static boolean isIntegerArray(Object aValue) - { - try - { - toIntArray(aValue); - return true; - } - catch (com.sun.star.lang.IllegalArgumentException e) - { - // ignore - } - return false; - } + + /** * get an int value from the object @@ -829,198 +676,25 @@ public class NumericalHelper return retValue; } - /** - * get an int from an object - * @param _aValue a value that is constructed into an int - * @param _ndefaultValue the value that is returned, if conversion fails, or if 'aValue' is null - * @return an int value - */ - public static int toInt(Object _aValue, int _ndefaultValue) throws Exception - { - int nreturn = _ndefaultValue; - try - { - if ((_aValue != null) && (!(AnyConverter.isVoid(_aValue)))) - { - if (isInteger(_aValue)) - { - nreturn = toInt(_aValue); - } - else - { - DebugHelper.exception(1/* BasicErrorCode.SbERR_CONVERSION*/, PropertyNames.EMPTY_STRING); - } - } - } - catch (com.sun.star.uno.Exception e) - { - DebugHelper.exception(1 /*BasicErrorCode.SbERR_METHOD_FAILED*/, PropertyNames.EMPTY_STRING); - } - return nreturn; - } - /** - * get a long from an object - * @param aValue a value that is constructed into a long - * @param defaultValue the value that is returned, if conversion fails - * @return a long value - */ - public static long toLong(Object aValue, long defaultValue) - { - try - { - return toLong(aValue); - } - catch (com.sun.star.lang.IllegalArgumentException e) - { - // ignore exception - } - return defaultValue; - } - /** - * get a float from an object - * @param aValue a value that is constructed into a float - * @param defaultValue the value that is returned, if conversion fails - * @return a long value - */ - public static float toFloat(Object aValue, float defaultValue) - { - try - { - return toFloat(aValue); - } - catch (com.sun.star.lang.IllegalArgumentException e) - { - // ignore exception - } - return defaultValue; - } - /** - * get a double from an object - * @param aValue a value that is constructed into a double - * @param defaultValue the value that is returned, if conversion fails - * @return a double value - */ - public static double toDouble(Object aValue, double defaultValue) - { - try - { - return toDouble(aValue); - } - catch (com.sun.star.lang.IllegalArgumentException e) - { - // ignore exception - } - return defaultValue; - } - /** - * get a string from an object - * @param aValue a value that is constructed into a string - * @param defaultValue the value that is returned, if conversion fails - * @return a string value - */ - public static String toString(Object aValue, String defaultValue) - { - try - { - return toString(aValue); - } - catch (com.sun.star.lang.IllegalArgumentException e) - { - // ignore exception - } - return defaultValue; - } - /** - * get a boolean from an object - * @param aValue a value that is constructed into a boolean - * @param defaultValue the value that is returned, if conversion fails - * @return a boolean value - */ - public static boolean toBoolean(Object aValue, boolean defaultValue) - { - try - { - return toBoolean(aValue); - } - catch (com.sun.star.lang.IllegalArgumentException e) - { - // ignore exception - } - return defaultValue; - } - /** - * get a int array from an object - * @param anArrayValue a value that is constructed into an int array - * @param defaultValue the value that is returned, if conversion fails - * @return an int array - */ - public static int[] toIntArray(Object anArrayValue, int[] defaultValue) - { - try - { - return toIntArray(anArrayValue); - } - catch (com.sun.star.lang.IllegalArgumentException e) - { - // ignore exception - } - return defaultValue; - } - /** - * get a short array from an object - * @param anArrayValue a value that is constructed into a short array - * @param defaultValue the value that is returned, if conversion fails - * @return a short array - */ - public static short[] toShortArray(Object anArrayValue, short[] defaultValue) - { - try - { - return toShortArray(anArrayValue); - } - catch (com.sun.star.lang.IllegalArgumentException e) - { - // ignore exception - } - return defaultValue; - } - /** - * get a string array from an object - * @param anArrayValue a value that is constructed into a string array - * @param defaultValue the value that is returned, if conversion fails - * @return a string array - */ - public static String[] toStringArray(Object anArrayValue, String[] defaultValue) - { - try - { - return toStringArray(anArrayValue); - } - catch (com.sun.star.lang.IllegalArgumentException e) - { - // ignore exception - } - return defaultValue; - } - /** - * get a hexadecimal representation from a number - * @param number the number to transform - * @return a String with the hex code of the number - */ - public static String getHexStringFromNumber(long number) - { - TransformNumToHex num = new TransformNumToHex(number); - return num.getResult(); - } + + + + + + + + + + /** * get the type object from the given object @@ -1337,16 +1011,9 @@ public class NumericalHelper return aShortVal; } - public static boolean representsIntegerNumber(double _dblvalue) - { - double dblsecvalue = ((int) _dblvalue); - return Double.compare(_dblvalue, dblsecvalue) == 0; - } - public static double roundDouble(Double _Dblvalue, int _ndecimals) - { - return roundDouble(_Dblvalue.doubleValue(), _ndecimals); - } + + private static double roundDouble(double _dblvalue, int _ndecimals) { |