diff options
Diffstat (limited to 'wizards/com/sun/star/wizards/common/NumericalHelper.java')
-rw-r--r-- | wizards/com/sun/star/wizards/common/NumericalHelper.java | 572 |
1 files changed, 0 insertions, 572 deletions
diff --git a/wizards/com/sun/star/wizards/common/NumericalHelper.java b/wizards/com/sun/star/wizards/common/NumericalHelper.java index 12efa62e949a..bf02290d9ae6 100644 --- a/wizards/com/sun/star/wizards/common/NumericalHelper.java +++ b/wizards/com/sun/star/wizards/common/NumericalHelper.java @@ -62,181 +62,6 @@ public class NumericalHelper /** - * get a byte value from the object - * @return a byte - * @throws com.sun.star.lang.IllegalArgumentException if the object cannot be converted - */ - private static byte toByte(Object aValue) - throws com.sun.star.lang.IllegalArgumentException - { - - byte retValue = 0; - TypeObject aTypeObject = getTypeObject(aValue); - switch (aTypeObject.iType) - { - case BYTE_TYPE: - retValue = getByte(aTypeObject); - break; - case CHAR_TYPE: - retValue = (byte) getChar(aTypeObject); - break; - case SHORT_TYPE: - retValue = (byte) getShort(aTypeObject); - break; - case INT_TYPE: - retValue = (byte) getInt(aTypeObject); - break; - case LONG_TYPE: - retValue = (byte) getLong(aTypeObject); - break; - case FLOAT_TYPE: - retValue = (byte) getFloat(aTypeObject); - break; - case DOUBLE_TYPE: - retValue = (byte) getDouble(aTypeObject); - break; - case STRING_TYPE: - try - { - Byte b = new Byte((String) aTypeObject.aValue); - retValue = b.byteValue(); - } - catch (java.lang.NumberFormatException e) - { - throw new com.sun.star.lang.IllegalArgumentException( - "Cannot convert to byte: " + aTypeObject.aValue); - } - break; - case BOOLEAN_TYPE: - retValue = getBool(aTypeObject) ? (byte) -1 : (byte) 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 - * @return a short - * @throws com.sun.star.lang.IllegalArgumentException if the object cannot be converted - */ - private static short toShort(Object aValue) - throws com.sun.star.lang.IllegalArgumentException - { - short retValue = 0; - TypeObject aTypeObject = getTypeObject(aValue); - switch (aTypeObject.iType) - { - case BYTE_TYPE: - retValue = getByte(aTypeObject); - break; - case CHAR_TYPE: - retValue = (byte) getChar(aTypeObject); - break; - case SHORT_TYPE: - retValue = getShort(aTypeObject); - break; - case INT_TYPE: - retValue = (short) getInt(aTypeObject); - break; - case LONG_TYPE: - retValue = (short) getLong(aTypeObject); - break; - case FLOAT_TYPE: - retValue = (short) getFloat(aTypeObject); - break; - case DOUBLE_TYPE: - retValue = (short) getDouble(aTypeObject); - break; - case STRING_TYPE: - try - { - Short s = new Short((String) aTypeObject.aValue); - retValue = s.shortValue(); - } - catch (java.lang.NumberFormatException e) - { - throw new com.sun.star.lang.IllegalArgumentException( - "Cannot convert to short: " + aTypeObject.aValue); - } - break; - case BOOLEAN_TYPE: - retValue = getBool(aTypeObject) ? (short) -1 : (short) 0; - break; - default: - throw new com.sun.star.lang.IllegalArgumentException( - "Cannot convert this type: " + aValue.getClass().getName()); - } - return retValue; - } - - - - - - - - /** - @param aValue a object this can contain anything - @return true, if the parameter aValue is type of real numbers - @deprecate, use isRealNumber() instead. - */ - private static boolean isNumerical(Object aValue) - { - try - { - TypeObject aTypeObject = getTypeObject(aValue); - switch (aTypeObject.iType) - { - case BYTE_TYPE: - case CHAR_TYPE: - case SHORT_TYPE: - case INT_TYPE: - case LONG_TYPE: - case DOUBLE_TYPE: - case FLOAT_TYPE: - return true; - default: - return false; - } - } - catch (com.sun.star.lang.IllegalArgumentException e) - { - return false; - } - } - - - - /** - @param aValue a object this can contain anything - * @return true, if the value is type of any integer values. double / float are not(!) integer values - */ - private static boolean isInteger(Object aValue) throws com.sun.star.lang.IllegalArgumentException - { - TypeObject aTypeObject = getTypeObject(aValue); - switch (aTypeObject.iType) - { - case BYTE_TYPE: - case CHAR_TYPE: - case SHORT_TYPE: - case INT_TYPE: - case LONG_TYPE: - return true; - default: - return false; - } - } - - - - - - /** * get an int value from the object * @return an int * @throws com.sun.star.lang.IllegalArgumentException if the object cannot be converted @@ -292,116 +117,6 @@ public class NumericalHelper } /** - * get a long value from the object - * @return a long - * @throws com.sun.star.lang.IllegalArgumentException if the object cannot be converted - */ - private static long toLong(Object aValue) - throws com.sun.star.lang.IllegalArgumentException - { - long retValue = 0; - TypeObject aTypeObject = getTypeObject(aValue); - switch (aTypeObject.iType) - { - case BYTE_TYPE: - retValue = getByte(aTypeObject); - break; - case CHAR_TYPE: - retValue = getChar(aTypeObject); - break; - case SHORT_TYPE: - retValue = getShort(aTypeObject); - break; - case INT_TYPE: - retValue = getInt(aTypeObject); - break; - case LONG_TYPE: - retValue = getLong(aTypeObject); - break; - case FLOAT_TYPE: - retValue = (long) getFloat(aTypeObject); - break; - case DOUBLE_TYPE: - retValue = (long) getDouble(aTypeObject); - break; - case STRING_TYPE: - try - { - Long l = new Long((String) aTypeObject.aValue); - retValue = l.longValue(); - } - catch (java.lang.NumberFormatException e) - { - throw new com.sun.star.lang.IllegalArgumentException( - "Cannot convert to short: " + aTypeObject.aValue); - } - break; - case BOOLEAN_TYPE: - retValue = getBool(aTypeObject) ? -1 : 0; - break; - default: - throw new com.sun.star.lang.IllegalArgumentException( - "Cannot convert this type: " + aValue.getClass().getName()); - } - return retValue; - } - - /** - * get a float value from the object - * @return a float - * @throws com.sun.star.lang.IllegalArgumentException if the object cannot be converted - */ - private static float toFloat(Object aValue) - throws com.sun.star.lang.IllegalArgumentException - { - float retValue = (float) 0.0; - TypeObject aTypeObject = getTypeObject(aValue); - switch (aTypeObject.iType) - { - case BYTE_TYPE: - retValue = getByte(aTypeObject); - break; - case CHAR_TYPE: - retValue = getChar(aTypeObject); - break; - case SHORT_TYPE: - retValue = getShort(aTypeObject); - break; - case INT_TYPE: - retValue = getInt(aTypeObject); - break; - case LONG_TYPE: - retValue = getLong(aTypeObject); - break; - case FLOAT_TYPE: - retValue = getFloat(aTypeObject); - break; - case DOUBLE_TYPE: - retValue = (float) getDouble(aTypeObject); - break; - case STRING_TYPE: - try - { - Float f = new Float((String) aTypeObject.aValue); - retValue = f.floatValue(); - } - catch (java.lang.NumberFormatException e) - { - throw new com.sun.star.lang.IllegalArgumentException( - "Cannot convert to short: " + aTypeObject.aValue); - } - break; - case BOOLEAN_TYPE: - retValue = getBool(aTypeObject) ? (float) -1 : (float) 0; - break; - default: - throw new com.sun.star.lang.IllegalArgumentException( - "Cannot convert this type: " + aValue.getClass().getName()); - } - return retValue; - } - - /** * get a double value from the object * @return a double * @throws com.sun.star.lang.IllegalArgumentException if the object cannot be converted @@ -457,55 +172,6 @@ public class NumericalHelper } /** - * get a String value from the object - * @return a String - * @throws com.sun.star.lang.IllegalArgumentException if the object cannot be converted - */ - private static String toString(Object aValue) - throws com.sun.star.lang.IllegalArgumentException - { - String retValue = null; - TypeObject aTypeObject = getTypeObject(aValue); - switch (aTypeObject.iType) - { - case BYTE_TYPE: - retValue = aTypeObject.aValue.toString(); - break; - case CHAR_TYPE: - retValue = aTypeObject.aValue.toString(); - break; - case SHORT_TYPE: - retValue = aTypeObject.aValue.toString(); - break; - case INT_TYPE: - retValue = aTypeObject.aValue.toString(); - break; - case LONG_TYPE: - retValue = aTypeObject.aValue.toString(); - break; - case FLOAT_TYPE: - retValue = aTypeObject.aValue.toString(); - break; - case DOUBLE_TYPE: - retValue = aTypeObject.aValue.toString(); - break; - case STRING_TYPE: - retValue = (String) aTypeObject.aValue; - break; - case BOOLEAN_TYPE: - retValue = aTypeObject.aValue.toString(); - break; - case SEQUENCE_TYPE: - retValue = new String(toByteArray((aValue))); - break; - default: - throw new com.sun.star.lang.IllegalArgumentException( - "Cannot convert this type: " + aValue.getClass().getName()); - } - return retValue; - } - - /** * get a boolean value from the object * @return a boolean * @throws com.sun.star.lang.IllegalArgumentException if the object cannot be converted @@ -561,142 +227,6 @@ public class NumericalHelper } /** - * get an int array from an object - * @param anArrayValue a value that is constructed into an array - * @return an integer array - */ - private static int[] toIntArray(Object anArrayValue) - throws com.sun.star.lang.IllegalArgumentException - { - int[] retValue = null; - TypeObject aTypeObject = getTypeObject(anArrayValue); - if (aTypeObject.iType == SEQUENCE_TYPE) - { - Object[] obj = convertSequenceToObjectArray(aTypeObject); - retValue = new int[obj.length]; - for (int i = 0; i < obj.length; i++) - { - retValue[i] = toInt(obj[i]); - } - } - else - { // object is not really an array - retValue = new int[] - { - toInt(anArrayValue) - }; - } - return retValue; - } - - /** - * get an byte array from an object - * @param anArrayValue a value that is constructed into an array - * @return a byte array - */ - private static byte[] toByteArray(Object anArrayValue) - throws com.sun.star.lang.IllegalArgumentException - { - byte[] retValue = null; - TypeObject aTypeObject = getTypeObject(anArrayValue); - if (aTypeObject.iType == SEQUENCE_TYPE) - { - Object[] obj = convertSequenceToObjectArray(aTypeObject); - retValue = new byte[obj.length]; - for (int i = 0; i < obj.length; i++) - { - retValue[i] = toByte(obj[i]); - } - } - else - { // object is not really an array - retValue = new byte[] - { - toByte(anArrayValue) - }; - } - return retValue; - } - - /** - * get a short array from an object - * @param anArrayValue a value that is constructed into an array - * @return a short array - */ - private static short[] toShortArray(Object anArrayValue) - throws com.sun.star.lang.IllegalArgumentException - { - short[] retValue = null; - TypeObject aTypeObject = getTypeObject(anArrayValue); - if (aTypeObject.iType == SEQUENCE_TYPE) - { - Object[] obj = convertSequenceToObjectArray(aTypeObject); - retValue = new short[obj.length]; - for (int i = 0; i < obj.length; i++) - { - retValue[i] = toShort(obj[i]); - } - } - else - { // object is not really an array - retValue = new short[] - { - toShort(anArrayValue) - }; - } - return retValue; - } - - /** - * get a string array from an object - * @param anArrayValue a value that is constructed into an array - * @return a short array - */ - private static String[] toStringArray(Object anArrayValue) - throws com.sun.star.lang.IllegalArgumentException - { - String[] retValue = null; - TypeObject aTypeObject = getTypeObject(anArrayValue); - if (aTypeObject.iType == SEQUENCE_TYPE) - { - Object[] obj = convertSequenceToObjectArray(aTypeObject); - retValue = new String[obj.length]; - for (int i = 0; i < obj.length; i++) - { - retValue[i] = toString(obj[i]); - } - } - else - { // object is not really an array - retValue = new String[] - { - toString(anArrayValue) - }; - } - return retValue; - } - - - - - - - - - - - - - - - - - - - - - - /** * get the type object from the given object * @param aValue an object representing a (numerical) value; can also be an 'any' * @return a type object: the object together with the its type information @@ -917,107 +447,5 @@ public class NumericalHelper transform(number); } } - - public String getResult() - { - return val.toString(); - } - } - - private static Object[] convertSequenceToObjectArray( - TypeObject sourceObject) - throws com.sun.star.lang.IllegalArgumentException - { - Object array = sourceObject.aValue; - Class<?> c = array.getClass(); - Object[] aShortVal = null; - if (c.equals(byte[].class)) - { - byte[] vals = (byte[]) array; - aShortVal = new Object[vals.length]; - for (int i = 0; i < vals.length; i++) - { - aShortVal[i] = new Byte(vals[i]); - } - } - else if (c.equals(short[].class)) - { - short[] vals = (short[]) array; - aShortVal = new Object[vals.length]; - for (int i = 0; i < vals.length; i++) - { - aShortVal[i] = new Short(vals[i]); - } - } - else if (c.equals(int[].class)) - { - int[] vals = (int[]) array; - aShortVal = new Object[vals.length]; - for (int i = 0; i < vals.length; i++) - { - aShortVal[i] = new Integer(vals[i]); - } - } - else if (c.equals(long[].class)) - { - long[] vals = (long[]) array; - aShortVal = new Object[vals.length]; - for (int i = 0; i < vals.length; i++) - { - aShortVal[i] = new Long(vals[i]); - } - } - else if (c.equals(float[].class)) - { - float[] vals = (float[]) array; - aShortVal = new Object[vals.length]; - for (int i = 0; i < vals.length; i++) - { - aShortVal[i] = new Float(vals[i]); - } - } - else if (c.equals(double[].class)) - { - double[] vals = (double[]) array; - aShortVal = new Object[vals.length]; - for (int i = 0; i < vals.length; i++) - { - aShortVal[i] = new Double(vals[i]); - } - } - else if (c.equals(boolean[].class)) - { - boolean[] vals = (boolean[]) array; - aShortVal = new Object[vals.length]; - for (int i = 0; i < vals.length; i++) - { - aShortVal[i] = Boolean.valueOf(vals[i]); - } - } - // if nothing did match, try this - if (aShortVal == null) - { - try - { - aShortVal = (Object[]) array; - } - catch (java.lang.ClassCastException e) - { - // unknown type cannot be converted - throw new com.sun.star.lang.IllegalArgumentException( - "Cannot convert unknown type: '" + e.getMessage() + "'"); - } - } - return aShortVal; - } - - - - - - private static double roundDouble(double _dblvalue, int _ndecimals) - { - double dblfactor = java.lang.Math.pow(10.0, _ndecimals); - return ((int) (_dblvalue * dblfactor)) / dblfactor; } } |