summaryrefslogtreecommitdiffstats
path: root/wizards/com/sun/star/wizards/common/NumericalHelper.java
diff options
context:
space:
mode:
Diffstat (limited to 'wizards/com/sun/star/wizards/common/NumericalHelper.java')
-rw-r--r--wizards/com/sun/star/wizards/common/NumericalHelper.java845
1 files changed, 501 insertions, 344 deletions
diff --git a/wizards/com/sun/star/wizards/common/NumericalHelper.java b/wizards/com/sun/star/wizards/common/NumericalHelper.java
index 4a29325f0108..f65de8327677 100644
--- a/wizards/com/sun/star/wizards/common/NumericalHelper.java
+++ b/wizards/com/sun/star/wizards/common/NumericalHelper.java
@@ -9,7 +9,7 @@
*
* $RCSfile: NumericalHelper.java,v $
*
- * $Revision: 1.2 $
+ * $Revision: 1.2.36.1 $
*
* This file is part of OpenOffice.org.
*
@@ -29,8 +29,6 @@
* for a copy of the LGPLv3 License.
*
************************************************************************/
-
-
package com.sun.star.wizards.common;
// import com.sun.star.beans.XPropertySet;
@@ -47,7 +45,8 @@ import com.sun.star.uno.TypeClass;
* This class does not log warnings (or throws Exceptions) when the precision
* of a value is lost.
*/
-public class NumericalHelper {
+public class NumericalHelper
+{
public static final int UNKNOWN_TYPE = -32768;
public static final int BYTE_TYPE = 0;
@@ -61,11 +60,9 @@ public class NumericalHelper {
public static final int BOOLEAN_TYPE = -2;
public static final int ARRAY_TYPE = -3;
public static final int SEQUENCE_TYPE = -4;
-
public static final int ASCII_VALUE_0 = 48;
public static final int ASCII_VALUE_A = 65;
public static final int COUNT_CHARS_IN_ALPHABET = 26;
-
private static final int HEX_BASE = 16;
private static final int DEC_BASE = 10;
private static final int ASCII_LETTER_A_OFFSET = 55;
@@ -73,7 +70,8 @@ public class NumericalHelper {
/**
* private c'tor to prevent instantiation
*/
- private NumericalHelper() {
+ private NumericalHelper()
+ {
// private c'tor, so noone can instantiate
}
@@ -85,11 +83,13 @@ public class NumericalHelper {
*/
public static int getType(Object obj)
{
- try {
+ try
+ {
TypeObject aTypeObject = getTypeObject(obj);
return aTypeObject.iType;
}
- catch(com.sun.star.lang.IllegalArgumentException e) {
+ catch (com.sun.star.lang.IllegalArgumentException e)
+ {
// ignore this one; just return unknown type
}
return UNKNOWN_TYPE;
@@ -102,49 +102,53 @@ public class NumericalHelper {
* @throws com.sun.star.lang.IllegalArgumentException if the object cannot be converted
*/
public static byte toByte(Object aValue)
- throws com.sun.star.lang.IllegalArgumentException {
+ throws com.sun.star.lang.IllegalArgumentException
+ {
byte retValue = 0;
boolean hasConversionWarning = false;
TypeObject aTypeObject = getTypeObject(aValue);
- switch(aTypeObject.iType) {
+ switch (aTypeObject.iType)
+ {
case BYTE_TYPE:
retValue = getByte(aTypeObject);
break;
case CHAR_TYPE:
- retValue = (byte)getChar(aTypeObject);
+ retValue = (byte) getChar(aTypeObject);
break;
case SHORT_TYPE:
- retValue = (byte)getShort(aTypeObject);
+ retValue = (byte) getShort(aTypeObject);
break;
case INT_TYPE:
- retValue = (byte)getInt(aTypeObject);
+ retValue = (byte) getInt(aTypeObject);
break;
case LONG_TYPE:
- retValue = (byte)getLong(aTypeObject);
+ retValue = (byte) getLong(aTypeObject);
break;
case FLOAT_TYPE:
- retValue = (byte)getFloat(aTypeObject);
+ retValue = (byte) getFloat(aTypeObject);
break;
case DOUBLE_TYPE:
- retValue = (byte)getDouble(aTypeObject);
+ retValue = (byte) getDouble(aTypeObject);
break;
case STRING_TYPE:
- try {
- Byte b = new Byte((String)aTypeObject.aValue);
+ try
+ {
+ Byte b = new Byte((String) aTypeObject.aValue);
retValue = b.byteValue();
}
- catch(java.lang.NumberFormatException e) {
+ catch (java.lang.NumberFormatException e)
+ {
throw new com.sun.star.lang.IllegalArgumentException(
- "Cannot convert to byte: " + aTypeObject.aValue);
+ "Cannot convert to byte: " + aTypeObject.aValue);
}
break;
case BOOLEAN_TYPE:
- retValue = getBool(aTypeObject)?(byte)-1:(byte)0;
+ retValue = getBool(aTypeObject) ? (byte) -1 : (byte) 0;
break;
default:
throw new com.sun.star.lang.IllegalArgumentException(
- "Cannot convert this type: " + aValue.getClass().getName());
+ "Cannot convert this type: " + aValue.getClass().getName());
}
return retValue;
}
@@ -156,54 +160,60 @@ public class NumericalHelper {
* @throws com.sun.star.lang.IllegalArgumentException if the object cannot be converted
*/
public static char toChar(Object aValue)
- throws com.sun.star.lang.IllegalArgumentException {
+ throws com.sun.star.lang.IllegalArgumentException
+ {
char retValue = 0;
boolean hasConversionWarning = false;
TypeObject aTypeObject = getTypeObject(aValue);
- switch(aTypeObject.iType) {
+ switch (aTypeObject.iType)
+ {
case CHAR_TYPE:
retValue = getChar(aTypeObject);
break;
case BYTE_TYPE:
- retValue = (char)getByte(aTypeObject);
+ retValue = (char) getByte(aTypeObject);
break;
case SHORT_TYPE:
- retValue = (char)getShort(aTypeObject);
+ retValue = (char) getShort(aTypeObject);
break;
case INT_TYPE:
- retValue = (char)getInt(aTypeObject);
+ retValue = (char) getInt(aTypeObject);
break;
case LONG_TYPE:
- retValue = (char)getLong(aTypeObject);
+ retValue = (char) getLong(aTypeObject);
break;
case FLOAT_TYPE:
- retValue = (char)getFloat(aTypeObject);
+ retValue = (char) getFloat(aTypeObject);
break;
case DOUBLE_TYPE:
- retValue = (char)getDouble(aTypeObject);
+ retValue = (char) getDouble(aTypeObject);
break;
case STRING_TYPE:
- try {
- String s = (String)aTypeObject.aValue;
- if (s.length() > 0) {
+ try
+ {
+ String s = (String) aTypeObject.aValue;
+ if (s.length() > 0)
+ {
retValue = s.charAt(0);
}
- else {
- retValue = (char)0;
+ else
+ {
+ retValue = (char) 0;
}
}
- catch(java.lang.NumberFormatException e) {
+ catch (java.lang.NumberFormatException e)
+ {
throw new com.sun.star.lang.IllegalArgumentException(
- "Cannot convert to char: " + aTypeObject.aValue);
+ "Cannot convert to char: " + aTypeObject.aValue);
}
break;
case BOOLEAN_TYPE:
- retValue = getBool(aTypeObject)?(char)-1:(char)0;
+ retValue = getBool(aTypeObject) ? (char) -1 : (char) 0;
break;
default:
throw new com.sun.star.lang.IllegalArgumentException(
- "Cannot convert this type: " + aValue.getClass().getName());
+ "Cannot convert this type: " + aValue.getClass().getName());
}
return retValue;
}
@@ -215,64 +225,73 @@ public class NumericalHelper {
* @throws com.sun.star.lang.IllegalArgumentException if the object cannot be converted
*/
public static short toShort(Object aValue)
- throws com.sun.star.lang.IllegalArgumentException {
+ throws com.sun.star.lang.IllegalArgumentException
+ {
short retValue = 0;
TypeObject aTypeObject = getTypeObject(aValue);
- switch(aTypeObject.iType) {
+ switch (aTypeObject.iType)
+ {
case BYTE_TYPE:
- retValue = (short)getByte(aTypeObject);
+ retValue = (short) getByte(aTypeObject);
break;
case CHAR_TYPE:
- retValue = (byte)getChar(aTypeObject);
+ retValue = (byte) getChar(aTypeObject);
break;
case SHORT_TYPE:
retValue = getShort(aTypeObject);
break;
case INT_TYPE:
- retValue = (short)getInt(aTypeObject);
+ retValue = (short) getInt(aTypeObject);
break;
case LONG_TYPE:
- retValue = (short)getLong(aTypeObject);
+ retValue = (short) getLong(aTypeObject);
break;
case FLOAT_TYPE:
- retValue = (short)getFloat(aTypeObject);
+ retValue = (short) getFloat(aTypeObject);
break;
case DOUBLE_TYPE:
- retValue = (short)getDouble(aTypeObject);
+ retValue = (short) getDouble(aTypeObject);
break;
case STRING_TYPE:
- try {
- Short s = new Short((String)aTypeObject.aValue);
+ try
+ {
+ Short s = new Short((String) aTypeObject.aValue);
retValue = s.shortValue();
}
- catch(java.lang.NumberFormatException e) {
+ catch (java.lang.NumberFormatException e)
+ {
throw new com.sun.star.lang.IllegalArgumentException(
- "Cannot convert to short: " + aTypeObject.aValue);
+ "Cannot convert to short: " + aTypeObject.aValue);
}
break;
case BOOLEAN_TYPE:
- retValue = getBool(aTypeObject)?(short)-1:(short)0;
+ retValue = getBool(aTypeObject) ? (short) -1 : (short) 0;
break;
default:
throw new com.sun.star.lang.IllegalArgumentException(
- "Cannot convert this type: " + aValue.getClass().getName());
+ "Cannot convert this type: " + aValue.getClass().getName());
}
return retValue;
}
-
- public static boolean isValidAndNumerical(Object aValue) throws com.sun.star.lang.IllegalArgumentException{
- if (aValue != null){
- if (!AnyConverter.isVoid(aValue)) {
+ 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)) {
+ 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);
}
@@ -280,10 +299,12 @@ public class NumericalHelper {
return false;
}
-
- public static boolean isValid(Object aValue){
- if (aValue != null){
- if (!AnyConverter.isVoid(aValue)) {
+ public static boolean isValid(Object aValue)
+ {
+ if (aValue != null)
+ {
+ if (!AnyConverter.isVoid(aValue))
+ {
return true;
}
}
@@ -291,51 +312,56 @@ public class NumericalHelper {
}
/**
- @param aValue a object this can contain anything
- @return true, if the parameter aValue is type of real numbers
- @deprecate, use isRealNumber() instead.
- */
-
- public static boolean isNumerical(Object aValue) {
- try {
+ @param aValue a object this can contain anything
+ @return true, if the parameter aValue is type of real numbers
+ @deprecate, use isRealNumber() instead.
+ */
+ public 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;
+ 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) {
+ }
+ catch (com.sun.star.lang.IllegalArgumentException e)
+ {
return false;
- }}
+ }
+ }
/**
- @param _aValue a object this can contain anything
- @return true, if the parameter aValue is type of real numbers
+ @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
- */
+ 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
+ @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
* @throws com.sun.star.lang.IllegalArgumentException
- */
+ */
public static boolean isInteger(Object aValue) throws com.sun.star.lang.IllegalArgumentException
+ {
+ TypeObject aTypeObject = getTypeObject(aValue);
+ switch (aTypeObject.iType)
{
- TypeObject aTypeObject = getTypeObject(aValue);
- switch(aTypeObject.iType)
- {
case BYTE_TYPE:
case CHAR_TYPE:
case SHORT_TYPE:
@@ -344,20 +370,23 @@ public class NumericalHelper {
return true;
default:
return false;
- }
}
+ }
/**
* 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 {
+ public static boolean isStringArray(Object aValue)
+ {
+ try
+ {
toStringArray(aValue);
return true;
}
- catch(com.sun.star.lang.IllegalArgumentException e) {
+ catch (com.sun.star.lang.IllegalArgumentException e)
+ {
// ignore
}
return false;
@@ -368,18 +397,19 @@ public class NumericalHelper {
* @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 {
+ public static boolean isIntegerArray(Object aValue)
+ {
+ try
+ {
toIntArray(aValue);
return true;
}
- catch(com.sun.star.lang.IllegalArgumentException e) {
+ catch (com.sun.star.lang.IllegalArgumentException e)
+ {
// ignore
}
return false;
}
-
-
// public static int toIntWithErrorMessage(Object _aValue) throws com.sun.star.script.BasicErrorException{
// try {
// return toInt(_aValue);
@@ -471,8 +501,6 @@ public class NumericalHelper {
// DebugHelper.exception(BasicErrorCode.SbERR_OUT_OF_RANGE, "");
// return false;
// }}
-
-
/**
* get an int value from the object
* @param aValue
@@ -480,47 +508,51 @@ public class NumericalHelper {
* @throws com.sun.star.lang.IllegalArgumentException if the object cannot be converted
*/
public static int toInt(Object aValue)
- throws com.sun.star.lang.IllegalArgumentException {
+ throws com.sun.star.lang.IllegalArgumentException
+ {
int retValue = 0;
TypeObject aTypeObject = getTypeObject(aValue);
- switch(aTypeObject.iType) {
+ switch (aTypeObject.iType)
+ {
case BYTE_TYPE:
- retValue = (int)getByte(aTypeObject);
+ retValue = (int) getByte(aTypeObject);
break;
case CHAR_TYPE:
- retValue = (int)getChar(aTypeObject);
+ retValue = (int) getChar(aTypeObject);
break;
case SHORT_TYPE:
- retValue = (int)getShort(aTypeObject);
+ retValue = (int) getShort(aTypeObject);
break;
case INT_TYPE:
retValue = getInt(aTypeObject);
break;
case LONG_TYPE:
- retValue = (int)getLong(aTypeObject);
+ retValue = (int) getLong(aTypeObject);
break;
case FLOAT_TYPE:
- retValue = (int)getFloat(aTypeObject);
+ retValue = (int) getFloat(aTypeObject);
break;
case DOUBLE_TYPE:
- retValue = (int)getDouble(aTypeObject);
+ retValue = (int) getDouble(aTypeObject);
break;
case STRING_TYPE:
- try {
- Integer i = new Integer((String)aTypeObject.aValue);
+ try
+ {
+ Integer i = new Integer((String) aTypeObject.aValue);
retValue = i.intValue();
}
- catch(java.lang.NumberFormatException e) {
+ catch (java.lang.NumberFormatException e)
+ {
throw new com.sun.star.lang.IllegalArgumentException(
- "Cannot convert to int: " + aTypeObject.aValue);
+ "Cannot convert to int: " + aTypeObject.aValue);
}
break;
case BOOLEAN_TYPE:
- retValue = getBool(aTypeObject)? -1 : 0;
+ retValue = getBool(aTypeObject) ? -1 : 0;
break;
default:
throw new com.sun.star.lang.IllegalArgumentException(
- "Cannot convert this type: " + aValue.getClass().getName());
+ "Cannot convert this type: " + aValue.getClass().getName());
}
return retValue;
}
@@ -532,47 +564,51 @@ public class NumericalHelper {
* @throws com.sun.star.lang.IllegalArgumentException if the object cannot be converted
*/
public static long toLong(Object aValue)
- throws com.sun.star.lang.IllegalArgumentException {
+ throws com.sun.star.lang.IllegalArgumentException
+ {
long retValue = 0;
TypeObject aTypeObject = getTypeObject(aValue);
- switch(aTypeObject.iType) {
+ switch (aTypeObject.iType)
+ {
case BYTE_TYPE:
- retValue = (long)getByte(aTypeObject);
+ retValue = (long) getByte(aTypeObject);
break;
case CHAR_TYPE:
- retValue = (long)getChar(aTypeObject);
+ retValue = (long) getChar(aTypeObject);
break;
case SHORT_TYPE:
- retValue = (long)getShort(aTypeObject);
+ retValue = (long) getShort(aTypeObject);
break;
case INT_TYPE:
- retValue = (long)getInt(aTypeObject);
+ retValue = (long) getInt(aTypeObject);
break;
case LONG_TYPE:
retValue = getLong(aTypeObject);
break;
case FLOAT_TYPE:
- retValue = (long)getFloat(aTypeObject);
+ retValue = (long) getFloat(aTypeObject);
break;
case DOUBLE_TYPE:
- retValue = (long)getDouble(aTypeObject);
+ retValue = (long) getDouble(aTypeObject);
break;
case STRING_TYPE:
- try {
- Long l = new Long((String)aTypeObject.aValue);
+ try
+ {
+ Long l = new Long((String) aTypeObject.aValue);
retValue = l.longValue();
}
- catch(java.lang.NumberFormatException e) {
+ catch (java.lang.NumberFormatException e)
+ {
throw new com.sun.star.lang.IllegalArgumentException(
- "Cannot convert to short: " + aTypeObject.aValue);
+ "Cannot convert to short: " + aTypeObject.aValue);
}
break;
case BOOLEAN_TYPE:
- retValue = getBool(aTypeObject)? -1 : 0;
+ retValue = getBool(aTypeObject) ? -1 : 0;
break;
default:
throw new com.sun.star.lang.IllegalArgumentException(
- "Cannot convert this type: " + aValue.getClass().getName());
+ "Cannot convert this type: " + aValue.getClass().getName());
}
return retValue;
}
@@ -584,47 +620,51 @@ public class NumericalHelper {
* @throws com.sun.star.lang.IllegalArgumentException if the object cannot be converted
*/
public static float toFloat(Object aValue)
- throws com.sun.star.lang.IllegalArgumentException {
- float retValue = (float)0.0;
+ throws com.sun.star.lang.IllegalArgumentException
+ {
+ float retValue = (float) 0.0;
TypeObject aTypeObject = getTypeObject(aValue);
- switch(aTypeObject.iType) {
+ switch (aTypeObject.iType)
+ {
case BYTE_TYPE:
- retValue = (float)getByte(aTypeObject);
+ retValue = (float) getByte(aTypeObject);
break;
case CHAR_TYPE:
- retValue = (float)getChar(aTypeObject);
+ retValue = (float) getChar(aTypeObject);
break;
case SHORT_TYPE:
- retValue = (float)getShort(aTypeObject);
+ retValue = (float) getShort(aTypeObject);
break;
case INT_TYPE:
- retValue = (float)getInt(aTypeObject);
+ retValue = (float) getInt(aTypeObject);
break;
case LONG_TYPE:
- retValue = (float)getLong(aTypeObject);
+ retValue = (float) getLong(aTypeObject);
break;
case FLOAT_TYPE:
retValue = getFloat(aTypeObject);
break;
case DOUBLE_TYPE:
- retValue = (float)getDouble(aTypeObject);
+ retValue = (float) getDouble(aTypeObject);
break;
case STRING_TYPE:
- try {
- Float f = new Float((String)aTypeObject.aValue);
+ try
+ {
+ Float f = new Float((String) aTypeObject.aValue);
retValue = f.floatValue();
}
- catch(java.lang.NumberFormatException e) {
+ catch (java.lang.NumberFormatException e)
+ {
throw new com.sun.star.lang.IllegalArgumentException(
- "Cannot convert to short: " + aTypeObject.aValue);
+ "Cannot convert to short: " + aTypeObject.aValue);
}
break;
case BOOLEAN_TYPE:
- retValue = getBool(aTypeObject)?(float)-1:(float)0;
+ retValue = getBool(aTypeObject) ? (float) -1 : (float) 0;
break;
default:
throw new com.sun.star.lang.IllegalArgumentException(
- "Cannot convert this type: " + aValue.getClass().getName());
+ "Cannot convert this type: " + aValue.getClass().getName());
}
return retValue;
}
@@ -636,47 +676,51 @@ public class NumericalHelper {
* @throws com.sun.star.lang.IllegalArgumentException if the object cannot be converted
*/
public static double toDouble(Object aValue)
- throws com.sun.star.lang.IllegalArgumentException {
+ throws com.sun.star.lang.IllegalArgumentException
+ {
double retValue = 0.0;
TypeObject aTypeObject = getTypeObject(aValue);
- switch(aTypeObject.iType) {
+ switch (aTypeObject.iType)
+ {
case BYTE_TYPE:
- retValue = (double)getByte(aTypeObject);
+ retValue = (double) getByte(aTypeObject);
break;
case CHAR_TYPE:
- retValue = (double)getChar(aTypeObject);
+ retValue = (double) getChar(aTypeObject);
break;
case SHORT_TYPE:
- retValue = (double)getShort(aTypeObject);
+ retValue = (double) getShort(aTypeObject);
break;
case INT_TYPE:
- retValue = (double)getInt(aTypeObject);
+ retValue = (double) getInt(aTypeObject);
break;
case LONG_TYPE:
- retValue = (double)getLong(aTypeObject);
+ retValue = (double) getLong(aTypeObject);
break;
case FLOAT_TYPE:
- retValue = (double)getFloat(aTypeObject);
+ retValue = (double) getFloat(aTypeObject);
break;
case DOUBLE_TYPE:
retValue = getDouble(aTypeObject);
break;
case STRING_TYPE:
- try {
- Float f = new Float((String)aTypeObject.aValue);
+ try
+ {
+ Float f = new Float((String) aTypeObject.aValue);
retValue = f.floatValue();
}
- catch(java.lang.NumberFormatException e) {
+ catch (java.lang.NumberFormatException e)
+ {
throw new com.sun.star.lang.IllegalArgumentException(
- "Cannot convert to short: " + aTypeObject.aValue);
+ "Cannot convert to short: " + aTypeObject.aValue);
}
break;
case BOOLEAN_TYPE:
- retValue = getBool(aTypeObject)?(double)-1:(double)0;
+ retValue = getBool(aTypeObject) ? (double) -1 : (double) 0;
break;
default:
throw new com.sun.star.lang.IllegalArgumentException(
- "Cannot convert this type: " + aValue.getClass().getName());
+ "Cannot convert this type: " + aValue.getClass().getName());
}
return retValue;
}
@@ -688,48 +732,49 @@ public class NumericalHelper {
* @throws com.sun.star.lang.IllegalArgumentException if the object cannot be converted
*/
public static String toString(Object aValue)
- throws com.sun.star.lang.IllegalArgumentException {
+ throws com.sun.star.lang.IllegalArgumentException
+ {
String retValue = null;
TypeObject aTypeObject = getTypeObject(aValue);
- switch(aTypeObject.iType) {
+ switch (aTypeObject.iType)
+ {
case BYTE_TYPE:
- retValue = ((Byte)aTypeObject.aValue).toString();
+ retValue = ((Byte) aTypeObject.aValue).toString();
break;
case CHAR_TYPE:
- retValue = ((Character)aTypeObject.aValue).toString();
+ retValue = ((Character) aTypeObject.aValue).toString();
break;
case SHORT_TYPE:
- retValue = ((Short)aTypeObject.aValue).toString();
+ retValue = ((Short) aTypeObject.aValue).toString();
break;
case INT_TYPE:
- retValue = ((Integer)aTypeObject.aValue).toString();
+ retValue = ((Integer) aTypeObject.aValue).toString();
break;
case LONG_TYPE:
- retValue = ((Long)aTypeObject.aValue).toString();
+ retValue = ((Long) aTypeObject.aValue).toString();
break;
case FLOAT_TYPE:
- retValue = ((Float)aTypeObject.aValue).toString();
+ retValue = ((Float) aTypeObject.aValue).toString();
break;
case DOUBLE_TYPE:
- retValue = ((Double)aTypeObject.aValue).toString();
+ retValue = ((Double) aTypeObject.aValue).toString();
break;
case STRING_TYPE:
- retValue = (String)aTypeObject.aValue;
+ retValue = (String) aTypeObject.aValue;
break;
case BOOLEAN_TYPE:
- retValue = ((Boolean)aTypeObject.aValue).toString();
+ retValue = ((Boolean) aTypeObject.aValue).toString();
break;
case ARRAY_TYPE:
retValue = new String(toByteArray((aValue)));
break;
default:
throw new com.sun.star.lang.IllegalArgumentException(
- "Cannot convert this type: " + aValue.getClass().getName());
+ "Cannot convert this type: " + aValue.getClass().getName());
}
return retValue;
}
-
/**
* get a boolean value from the object
* @param aValue
@@ -737,47 +782,51 @@ public class NumericalHelper {
* @throws com.sun.star.lang.IllegalArgumentException if the object cannot be converted
*/
public static boolean toBoolean(Object aValue)
- throws com.sun.star.lang.IllegalArgumentException {
+ throws com.sun.star.lang.IllegalArgumentException
+ {
boolean retValue = true;
TypeObject aTypeObject = getTypeObject(aValue);
- switch(aTypeObject.iType) {
+ switch (aTypeObject.iType)
+ {
case BYTE_TYPE:
- retValue = (((Byte)aTypeObject.aValue).byteValue() != 0);
+ retValue = (((Byte) aTypeObject.aValue).byteValue() != 0);
break;
case CHAR_TYPE:
- retValue = (((Character)aTypeObject.aValue).charValue() != 0);
+ retValue = (((Character) aTypeObject.aValue).charValue() != 0);
break;
case SHORT_TYPE:
- retValue = (((Short)aTypeObject.aValue).shortValue() != 0);
+ retValue = (((Short) aTypeObject.aValue).shortValue() != 0);
break;
case INT_TYPE:
- retValue = (((Integer)aTypeObject.aValue).intValue() != 0);
+ retValue = (((Integer) aTypeObject.aValue).intValue() != 0);
break;
case LONG_TYPE:
- retValue = (((Long)aTypeObject.aValue).longValue() != 0);
+ retValue = (((Long) aTypeObject.aValue).longValue() != 0);
break;
case FLOAT_TYPE:
- retValue = (((Float)aTypeObject.aValue).floatValue() != 0);
+ retValue = (((Float) aTypeObject.aValue).floatValue() != 0);
break;
case DOUBLE_TYPE:
- retValue = (((Double)aTypeObject.aValue).doubleValue() != 0);
+ retValue = (((Double) aTypeObject.aValue).doubleValue() != 0);
break;
case STRING_TYPE:
- try {
- Boolean b = Boolean.valueOf((String)aTypeObject.aValue);
+ try
+ {
+ Boolean b = Boolean.valueOf((String) aTypeObject.aValue);
retValue = b.booleanValue();
}
- catch(java.lang.NumberFormatException e) {
+ catch (java.lang.NumberFormatException e)
+ {
throw new com.sun.star.lang.IllegalArgumentException(
- "Cannot convert to short: " + aTypeObject.aValue);
+ "Cannot convert to short: " + aTypeObject.aValue);
}
break;
case BOOLEAN_TYPE:
- retValue = ((Boolean)aTypeObject.aValue).booleanValue();
+ retValue = ((Boolean) aTypeObject.aValue).booleanValue();
break;
default:
throw new com.sun.star.lang.IllegalArgumentException(
- "Cannot convert this type: " + aValue.getClass().getName());
+ "Cannot convert this type: " + aValue.getClass().getName());
}
return retValue;
}
@@ -789,21 +838,29 @@ public class NumericalHelper {
* @throws com.sun.star.lang.IllegalArgumentException
*/
public static int[] toIntArray(Object anArrayValue)
- throws com.sun.star.lang.IllegalArgumentException {
+ throws com.sun.star.lang.IllegalArgumentException
+ {
int[] retValue = null;
TypeObject aTypeObject = getTypeObject(anArrayValue);
- if (aTypeObject.iType == SEQUENCE_TYPE) {
+ if (aTypeObject.iType == SEQUENCE_TYPE)
+ {
aTypeObject = convertSequenceToObjectArray(aTypeObject);
}
- if (aTypeObject.iType == ARRAY_TYPE) {
- Object[]obj = (Object[])aTypeObject.aValue;
+ if (aTypeObject.iType == ARRAY_TYPE)
+ {
+ Object[] obj = (Object[]) aTypeObject.aValue;
retValue = new int[obj.length];
- for (int i=0; i<obj.length; i++) {
+ 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)};
+ else
+ { // object is not really an array
+ retValue = new int[]
+ {
+ toInt(anArrayValue)
+ };
}
return retValue;
}
@@ -815,21 +872,29 @@ public class NumericalHelper {
* @throws com.sun.star.lang.IllegalArgumentException
*/
public static byte[] toByteArray(Object anArrayValue)
- throws com.sun.star.lang.IllegalArgumentException {
+ throws com.sun.star.lang.IllegalArgumentException
+ {
byte[] retValue = null;
TypeObject aTypeObject = getTypeObject(anArrayValue);
- if (aTypeObject.iType == SEQUENCE_TYPE) {
+ if (aTypeObject.iType == SEQUENCE_TYPE)
+ {
aTypeObject = convertSequenceToObjectArray(aTypeObject);
}
- if (aTypeObject.iType == ARRAY_TYPE) {
- Object[]obj = (Object[])aTypeObject.aValue;
+ if (aTypeObject.iType == ARRAY_TYPE)
+ {
+ Object[] obj = (Object[]) aTypeObject.aValue;
retValue = new byte[obj.length];
- for (int i=0; i<obj.length; i++) {
+ 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)};
+ else
+ { // object is not really an array
+ retValue = new byte[]
+ {
+ toByte(anArrayValue)
+ };
}
return retValue;
}
@@ -841,21 +906,29 @@ public class NumericalHelper {
* @throws com.sun.star.lang.IllegalArgumentException
*/
public static short[] toShortArray(Object anArrayValue)
- throws com.sun.star.lang.IllegalArgumentException {
+ throws com.sun.star.lang.IllegalArgumentException
+ {
short[] retValue = null;
TypeObject aTypeObject = getTypeObject(anArrayValue);
- if (aTypeObject.iType == SEQUENCE_TYPE) {
+ if (aTypeObject.iType == SEQUENCE_TYPE)
+ {
aTypeObject = convertSequenceToObjectArray(aTypeObject);
}
- if (aTypeObject.iType == ARRAY_TYPE) {
- Object[]obj = (Object[])aTypeObject.aValue;
+ if (aTypeObject.iType == ARRAY_TYPE)
+ {
+ Object[] obj = (Object[]) aTypeObject.aValue;
retValue = new short[obj.length];
- for (int i=0; i<obj.length; i++) {
+ 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)};
+ else
+ { // object is not really an array
+ retValue = new short[]
+ {
+ toShort(anArrayValue)
+ };
}
return retValue;
}
@@ -867,26 +940,33 @@ public class NumericalHelper {
* @throws com.sun.star.lang.IllegalArgumentException
*/
public static String[] toStringArray(Object anArrayValue)
- throws com.sun.star.lang.IllegalArgumentException {
+ throws com.sun.star.lang.IllegalArgumentException
+ {
String[] retValue = null;
TypeObject aTypeObject = getTypeObject(anArrayValue);
- if (aTypeObject.iType == SEQUENCE_TYPE) {
+ if (aTypeObject.iType == SEQUENCE_TYPE)
+ {
aTypeObject = convertSequenceToObjectArray(aTypeObject);
}
- if (aTypeObject.iType == ARRAY_TYPE) {
- Object[]obj = (Object[])aTypeObject.aValue;
+ if (aTypeObject.iType == ARRAY_TYPE)
+ {
+ Object[] obj = (Object[]) aTypeObject.aValue;
retValue = new String[obj.length];
- for (int i=0; i<obj.length; i++) {
+ 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)};
+ else
+ { // object is not really an array
+ retValue = new String[]
+ {
+ toString(anArrayValue)
+ };
}
return retValue;
}
-
/**
* get an int from an object
* @param _aValue a value that is constructed into an int
@@ -896,7 +976,7 @@ public class NumericalHelper {
*/
public static int toInt(Object _aValue, int _ndefaultValue) throws Exception
{
- int nreturn = _ndefaultValue;
+ int nreturn = _ndefaultValue;
try
{
if ((_aValue != null) && (!(AnyConverter.isVoid(_aValue))))
@@ -913,24 +993,25 @@ public class NumericalHelper {
}
catch (com.sun.star.uno.Exception e)
{
- DebugHelper.exception(1 /*BasicErrorCode.SbERR_METHOD_FAILED*/ , "");
+ DebugHelper.exception(1 /*BasicErrorCode.SbERR_METHOD_FAILED*/, "");
}
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 {
+ public static long toLong(Object aValue, long defaultValue)
+ {
+ try
+ {
return toLong(aValue);
}
- catch(com.sun.star.lang.IllegalArgumentException e) {
+ catch (com.sun.star.lang.IllegalArgumentException e)
+ {
// ignore exception
}
return defaultValue;
@@ -942,11 +1023,14 @@ public class NumericalHelper {
* @param defaultValue the value that is returned, if conversion fails
* @return a long value
*/
- public static float toFloat(Object aValue, float defaultValue) {
- try {
+ public static float toFloat(Object aValue, float defaultValue)
+ {
+ try
+ {
return toFloat(aValue);
}
- catch(com.sun.star.lang.IllegalArgumentException e) {
+ catch (com.sun.star.lang.IllegalArgumentException e)
+ {
// ignore exception
}
return defaultValue;
@@ -958,11 +1042,14 @@ public class NumericalHelper {
* @param defaultValue the value that is returned, if conversion fails
* @return a double value
*/
- public static double toDouble(Object aValue, double defaultValue) {
- try {
+ public static double toDouble(Object aValue, double defaultValue)
+ {
+ try
+ {
return toDouble(aValue);
}
- catch(com.sun.star.lang.IllegalArgumentException e) {
+ catch (com.sun.star.lang.IllegalArgumentException e)
+ {
// ignore exception
}
return defaultValue;
@@ -974,11 +1061,14 @@ public class NumericalHelper {
* @param defaultValue the value that is returned, if conversion fails
* @return a string value
*/
- public static String toString(Object aValue, String defaultValue) {
- try {
+ public static String toString(Object aValue, String defaultValue)
+ {
+ try
+ {
return toString(aValue);
}
- catch(com.sun.star.lang.IllegalArgumentException e) {
+ catch (com.sun.star.lang.IllegalArgumentException e)
+ {
// ignore exception
}
return defaultValue;
@@ -990,11 +1080,14 @@ public class NumericalHelper {
* @param defaultValue the value that is returned, if conversion fails
* @return a boolean value
*/
- public static boolean toBoolean(Object aValue, boolean defaultValue) {
- try {
+ public static boolean toBoolean(Object aValue, boolean defaultValue)
+ {
+ try
+ {
return toBoolean(aValue);
}
- catch(com.sun.star.lang.IllegalArgumentException e) {
+ catch (com.sun.star.lang.IllegalArgumentException e)
+ {
// ignore exception
}
return defaultValue;
@@ -1006,11 +1099,14 @@ public class NumericalHelper {
* @param defaultValue the value that is returned, if conversion fails
* @return an int array
*/
- public static int[] toIntArray(Object anArrayValue, int[] defaultValue) {
- try {
+ public static int[] toIntArray(Object anArrayValue, int[] defaultValue)
+ {
+ try
+ {
return toIntArray(anArrayValue);
}
- catch(com.sun.star.lang.IllegalArgumentException e) {
+ catch (com.sun.star.lang.IllegalArgumentException e)
+ {
// ignore exception
}
return defaultValue;
@@ -1022,11 +1118,14 @@ public class NumericalHelper {
* @param defaultValue the value that is returned, if conversion fails
* @return a short array
*/
- public static short[] toShortArray(Object anArrayValue, short[] defaultValue) {
- try {
+ public static short[] toShortArray(Object anArrayValue, short[] defaultValue)
+ {
+ try
+ {
return toShortArray(anArrayValue);
}
- catch(com.sun.star.lang.IllegalArgumentException e) {
+ catch (com.sun.star.lang.IllegalArgumentException e)
+ {
// ignore exception
}
return defaultValue;
@@ -1038,11 +1137,14 @@ public class NumericalHelper {
* @param defaultValue the value that is returned, if conversion fails
* @return a string array
*/
- public static String[] toStringArray(Object anArrayValue, String[] defaultValue) {
- try {
+ public static String[] toStringArray(Object anArrayValue, String[] defaultValue)
+ {
+ try
+ {
return toStringArray(anArrayValue);
}
- catch(com.sun.star.lang.IllegalArgumentException e) {
+ catch (com.sun.star.lang.IllegalArgumentException e)
+ {
// ignore exception
}
return defaultValue;
@@ -1053,7 +1155,8 @@ public class NumericalHelper {
* @param number the number to transform
* @return a String with the hex code of the number
*/
- public static String getHexStringFromNumber(long number) {
+ public static String getHexStringFromNumber(long number)
+ {
TransformNumToHex num = new TransformNumToHex(number);
return num.getResult();
}
@@ -1070,8 +1173,6 @@ public class NumericalHelper {
// throws com.sun.star.script.BasicErrorException {
// return RomanNumbering.getRomanEquivalent(n);
// }
-
-
/**
* get the type object from the given object
* @param aValue an object representing a (numerical) value; can also be an 'any'
@@ -1079,13 +1180,16 @@ public class NumericalHelper {
* @throws com.sun.star.lang.IllegalArgumentException if the object is unknown
*/
private static TypeObject getTypeObject(Object aValue)
- throws com.sun.star.lang.IllegalArgumentException {
+ throws com.sun.star.lang.IllegalArgumentException
+ {
TypeObject aTypeObject = new TypeObject();
- if (aValue == null || AnyConverter.isVoid(aValue)) {
+ if (aValue == null || AnyConverter.isVoid(aValue))
+ {
throw new com.sun.star.lang.IllegalArgumentException("Cannot convert a null object.");
}
int type = AnyConverter.getType(aValue).getTypeClass().getValue();
- switch(type) {
+ switch (type)
+ {
case TypeClass.CHAR_value:
aTypeObject.iType = CHAR_TYPE;
aTypeObject.aValue = new Character(AnyConverter.toChar(aValue));
@@ -1124,7 +1228,10 @@ public class NumericalHelper {
break;
case TypeClass.ARRAY_value:
aTypeObject.iType = ARRAY_TYPE;
- aTypeObject.aValue = new Object[]{AnyConverter.toArray(aValue)};
+ aTypeObject.aValue = new Object[]
+ {
+ AnyConverter.toArray(aValue)
+ };
break;
case TypeClass.SEQUENCE_value:
aTypeObject.iType = SEQUENCE_TYPE;
@@ -1132,7 +1239,7 @@ public class NumericalHelper {
break;
default:
throw new com.sun.star.lang.IllegalArgumentException(
- "Cannot convert this type: " + aValue.getClass().getName());
+ "Cannot convert this type: " + aValue.getClass().getName());
}
return aTypeObject;
}
@@ -1141,39 +1248,44 @@ public class NumericalHelper {
* get the simple byte type
*/
private static byte getByte(TypeObject typeObject)
- throws com.sun.star.lang.IllegalArgumentException {
- if (typeObject.iType != BYTE_TYPE) {
+ throws com.sun.star.lang.IllegalArgumentException
+ {
+ if (typeObject.iType != BYTE_TYPE)
+ {
throw new com.sun.star.lang.IllegalArgumentException(
"Given argument is not a byte type.");
}
- return ((Byte)typeObject.aValue).byteValue();
+ return ((Byte) typeObject.aValue).byteValue();
}
/**
* get the simple char type
*/
private static char getChar(TypeObject typeObject)
- throws com.sun.star.lang.IllegalArgumentException {
- if (typeObject.iType != CHAR_TYPE) {
+ throws com.sun.star.lang.IllegalArgumentException
+ {
+ if (typeObject.iType != CHAR_TYPE)
+ {
throw new com.sun.star.lang.IllegalArgumentException(
"Given argument is not a char type.");
}
- return ((Character)typeObject.aValue).charValue();
+ return ((Character) typeObject.aValue).charValue();
}
/**
* get the simple short type
*/
private static short getShort(TypeObject typeObject)
- throws com.sun.star.lang.IllegalArgumentException {
- if (typeObject.iType != SHORT_TYPE) {
+ throws com.sun.star.lang.IllegalArgumentException
+ {
+ if (typeObject.iType != SHORT_TYPE)
+ {
throw new com.sun.star.lang.IllegalArgumentException(
"Given argument is not a short type.");
}
- return ((Short)typeObject.aValue).shortValue();
+ return ((Short) typeObject.aValue).shortValue();
}
-
/**
* get the simple int type
* @param typeObject
@@ -1181,12 +1293,14 @@ public class NumericalHelper {
* @throws com.sun.star.lang.IllegalArgumentException
*/
static int getInt(TypeObject typeObject)
- throws com.sun.star.lang.IllegalArgumentException {
- if (typeObject.iType != INT_TYPE) {
+ throws com.sun.star.lang.IllegalArgumentException
+ {
+ if (typeObject.iType != INT_TYPE)
+ {
throw new com.sun.star.lang.IllegalArgumentException(
"Given argument is not an int type.");
}
- return ((Integer)typeObject.aValue).intValue();
+ return ((Integer) typeObject.aValue).intValue();
}
/**
@@ -1194,54 +1308,64 @@ public class NumericalHelper {
* @throws com.sun.star.lang.IllegalArgumentException
*/
static float getFloat(TypeObject typeObject)
- throws com.sun.star.lang.IllegalArgumentException {
- if (typeObject.iType != FLOAT_TYPE) {
+ throws com.sun.star.lang.IllegalArgumentException
+ {
+ if (typeObject.iType != FLOAT_TYPE)
+ {
throw new com.sun.star.lang.IllegalArgumentException(
"Given argument is not a float type.");
}
- return ((Float)typeObject.aValue).floatValue();
+ return ((Float) typeObject.aValue).floatValue();
}
/**
* get the simple double type
*/
private static double getDouble(TypeObject typeObject)
- throws com.sun.star.lang.IllegalArgumentException {
- if (typeObject.iType != DOUBLE_TYPE) {
+ throws com.sun.star.lang.IllegalArgumentException
+ {
+ if (typeObject.iType != DOUBLE_TYPE)
+ {
throw new com.sun.star.lang.IllegalArgumentException(
"Given argument is not a double type.");
}
- return ((Double)typeObject.aValue).doubleValue();
+ return ((Double) typeObject.aValue).doubleValue();
}
/**
* get the simple long type
*/
private static long getLong(TypeObject typeObject)
- throws com.sun.star.lang.IllegalArgumentException {
- if (typeObject.iType != LONG_TYPE) {
+ throws com.sun.star.lang.IllegalArgumentException
+ {
+ if (typeObject.iType != LONG_TYPE)
+ {
throw new com.sun.star.lang.IllegalArgumentException(
"Given argument is not a long type.");
}
- return ((Long)typeObject.aValue).longValue();
+ return ((Long) typeObject.aValue).longValue();
}
/**
* get the simple boolean type
*/
private static boolean getBool(TypeObject typeObject)
- throws com.sun.star.lang.IllegalArgumentException {
- if (typeObject.iType != BOOLEAN_TYPE) {
+ throws com.sun.star.lang.IllegalArgumentException
+ {
+ if (typeObject.iType != BOOLEAN_TYPE)
+ {
throw new com.sun.star.lang.IllegalArgumentException(
"Given argument is not a boolean type.");
}
- return ((Boolean)typeObject.aValue).booleanValue();
+ return ((Boolean) typeObject.aValue).booleanValue();
}
/**
* a class to contain a type and a value for easier conversions
*/
- private static class TypeObject {
+ private static class TypeObject
+ {
+
public int iType;
public Object aValue;
}
@@ -1249,99 +1373,125 @@ public class NumericalHelper {
/**
* simple class to construct a hexadecimal value from a long number
*/
- private static class TransformNumToHex {
+ private static class TransformNumToHex
+ {
+
private StringBuffer val;
- public TransformNumToHex(long number) {
+ public TransformNumToHex(long number)
+ {
val = new StringBuffer();
transform(number);
}
- private void transform(long number) {
- int index = (int)(number % HEX_BASE);
+ private void transform(long number)
+ {
+ int index = (int) (number % HEX_BASE);
number = number / HEX_BASE;
- if (index < DEC_BASE) {
- val.insert(0,index);
+ if (index < DEC_BASE)
+ {
+ val.insert(0, index);
}
- else {
- val.insert(0,(char)(ASCII_LETTER_A_OFFSET + index));
+ else
+ {
+ val.insert(0, (char) (ASCII_LETTER_A_OFFSET + index));
}
- if (number >0) {
+ if (number > 0)
+ {
transform(number);
}
}
- public String getResult() {
+ public String getResult()
+ {
return val.toString();
}
}
private static TypeObject convertSequenceToObjectArray(
TypeObject sourceObject)
- throws com.sun.star.lang.IllegalArgumentException {
+ throws com.sun.star.lang.IllegalArgumentException
+ {
TypeObject destObject = new TypeObject();
Object array = sourceObject.aValue;
destObject.iType = ARRAY_TYPE;
Class c = array.getClass();
Object[] aShortVal = null;
- if (c.equals(byte[].class)) {
- byte[] vals = (byte[])array;
+ if (c.equals(byte[].class))
+ {
+ byte[] vals = (byte[]) array;
aShortVal = new Object[vals.length];
- for (int i=0; i<vals.length; i++) {
+ for (int i = 0; i < vals.length; i++)
+ {
aShortVal[i] = new Byte(vals[i]);
}
}
- else if (c.equals(short[].class)) {
- short[] vals = (short[])array;
+ else if (c.equals(short[].class))
+ {
+ short[] vals = (short[]) array;
aShortVal = new Object[vals.length];
- for (int i=0; i<vals.length; i++) {
+ for (int i = 0; i < vals.length; i++)
+ {
aShortVal[i] = new Short(vals[i]);
}
}
- else if (c.equals(int[].class)) {
- int[] vals = (int[])array;
+ else if (c.equals(int[].class))
+ {
+ int[] vals = (int[]) array;
aShortVal = new Object[vals.length];
- for (int i=0; i<vals.length; i++) {
+ for (int i = 0; i < vals.length; i++)
+ {
aShortVal[i] = new Integer(vals[i]);
}
}
- else if (c.equals(long[].class)) {
- long[] vals = (long[])array;
+ else if (c.equals(long[].class))
+ {
+ long[] vals = (long[]) array;
aShortVal = new Object[vals.length];
- for (int i=0; i<vals.length; i++) {
+ for (int i = 0; i < vals.length; i++)
+ {
aShortVal[i] = new Long(vals[i]);
}
}
- else if (c.equals(float[].class)) {
- float[] vals = (float[])array;
+ else if (c.equals(float[].class))
+ {
+ float[] vals = (float[]) array;
aShortVal = new Object[vals.length];
- for (int i=0; i<vals.length; i++) {
+ for (int i = 0; i < vals.length; i++)
+ {
aShortVal[i] = new Float(vals[i]);
}
}
- else if (c.equals(double[].class)) {
- double[] vals = (double[])array;
+ else if (c.equals(double[].class))
+ {
+ double[] vals = (double[]) array;
aShortVal = new Object[vals.length];
- for (int i=0; i<vals.length; i++) {
+ for (int i = 0; i < vals.length; i++)
+ {
aShortVal[i] = new Double(vals[i]);
}
}
- else if (c.equals(boolean[].class)) {
- boolean[] vals = (boolean[])array;
+ else if (c.equals(boolean[].class))
+ {
+ boolean[] vals = (boolean[]) array;
aShortVal = new Object[vals.length];
- for (int i=0; i<vals.length; i++) {
+ 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;
+ if (aShortVal == null)
+ {
+ try
+ {
+ aShortVal = (Object[]) array;
}
- catch(java.lang.ClassCastException e) {
+ catch (java.lang.ClassCastException e)
+ {
// unknown type cannot be converted
throw new com.sun.star.lang.IllegalArgumentException(
- "Cannot convert unknown type: '" + e.getMessage() + "'");
+ "Cannot convert unknown type: '" + e.getMessage() + "'");
}
}
destObject.aValue = aShortVal;
@@ -1368,18 +1518,17 @@ public class NumericalHelper {
// DebugHelper.exception(1 /*BasicErrorCode.SbERR_METHOD_FAILED*/, "");
// return false;
// }}
-
-
/**
* Helper class for roman numbering
*/
- private static class RomanNumbering {
+ private static class RomanNumbering
+ {
/** the used roman lettesrs **/
- private static final String [] ROMAN_EQUIV = new String[]{
+ private static final String[] ROMAN_EQUIV = new String[]
+ {
"I", "V", "X", "L", "C", "D", "M"
};
-
/** max number that can be converted **/
private static final int MAX_NUMBER = 3999;
/** min number that can be converted **/
@@ -1393,7 +1542,6 @@ public class NumericalHelper {
/** special number for the conversion algorithm **/
private static final int NINE = 9;
-
/**
* Get the roman equivalent to an arabic number, e.g. 17 -> XVII.
* The allowed range for numbers goes from 1 to 3999. These can be
@@ -1403,11 +1551,14 @@ public class NumericalHelper {
* @throws BasicErrorException if the number cannot be converted.
*/
public static String getRomanEquivalent(int n)
- throws Exception {
+ throws Exception
+ {
StringBuffer romanNumber = new StringBuffer();
- try {
- if (n > MAX_NUMBER || n < MIN_NUMBER) {
- DebugHelper.exception(1 /*BasicErrorCode.SbERR_OUT_OF_RANGE*/ , "");
+ try
+ {
+ if (n > MAX_NUMBER || n < MIN_NUMBER)
+ {
+ DebugHelper.exception(1 /*BasicErrorCode.SbERR_OUT_OF_RANGE*/, "");
}
String number = NumericalHelper.toString(new Integer(n));
/* converison idea: every digit is written with a maximum of two
@@ -1417,23 +1568,29 @@ public class NumericalHelper {
* special cases 4 and 9.
*/
int symbolIndex = 0;
- for(int i = number.length() - 1; i >= 0; i--){
+ for (int i = number.length() - 1; i >= 0; i--)
+ {
StringBuffer romanDigit = new StringBuffer();
- int b = (int)number.charAt(i) - ASCII_CODE_0;
- if (b == FOUR) { // special case IV
+ int b = (int) number.charAt(i) - ASCII_CODE_0;
+ if (b == FOUR)
+ { // special case IV
romanDigit.append(ROMAN_EQUIV[symbolIndex]);
romanDigit.append(ROMAN_EQUIV[symbolIndex + 1]);
}
- else if (b == NINE) { // special case IX
+ else if (b == NINE)
+ { // special case IX
romanDigit.append(ROMAN_EQUIV[symbolIndex]);
romanDigit.append(ROMAN_EQUIV[symbolIndex + 2]);
}
- else {
- if (b >= FIVE) { // special case V
+ else
+ {
+ if (b >= FIVE)
+ { // special case V
romanDigit.append(ROMAN_EQUIV[symbolIndex + 1]);
b = b - FIVE;
}
- for (int j = 0; j < b; j++) { // append I's
+ for (int j = 0; j < b; j++)
+ { // append I's
romanDigit.append(ROMAN_EQUIV[symbolIndex]);
}
}
@@ -1443,7 +1600,8 @@ public class NumericalHelper {
romanNumber.append(romanDigit.reverse());
}
}
- catch(com.sun.star.lang.IllegalArgumentException e) {
+ catch (com.sun.star.lang.IllegalArgumentException e)
+ {
DebugHelper.exception(e);
}
// reverse again to get the number
@@ -1451,22 +1609,21 @@ public class NumericalHelper {
}
}
-
- public static boolean representsIntegerNumber(double _dblvalue){
+ public static boolean representsIntegerNumber(double _dblvalue)
+ {
double dblsecvalue = (double) ((int) _dblvalue);
return Double.compare(_dblvalue, dblsecvalue) == 0;
}
-
- public static double roundDouble(Double _Dblvalue, int _ndecimals){
+ public static double roundDouble(Double _Dblvalue, int _ndecimals)
+ {
return roundDouble(_Dblvalue.doubleValue(), _ndecimals);
}
-
- public static double roundDouble(double _dblvalue, int _ndecimals){
+ public static double roundDouble(double _dblvalue, int _ndecimals)
+ {
double dblfactor = java.lang.Math.pow(10.0, (double) _ndecimals);
- double dblretvalue = ((double) ((int) (_dblvalue * dblfactor)))/dblfactor;
+ double dblretvalue = ((double) ((int) (_dblvalue * dblfactor))) / dblfactor;
return dblretvalue;
}
-
}