org.openbp.common
Class CommonUtil

java.lang.Object
  extended by org.openbp.common.CommonUtil

public final class CommonUtil
extends java.lang.Object

General utility functions.

Author:
Heiko Erhardt

Method Summary
static int compareNull(java.lang.Object o1, java.lang.Object o2)
          Compares two objects that implement the java.lang.Comparable interface that may also be null.
static boolean equalsNull(java.lang.Object o1, java.lang.Object o2)
          Checks if two objects are equal or both null.
static int getJavaVersionInt()
          Gets the java version as 3 digit integer (e\.g\. 141).
static java.lang.String getJavaVersionStr()
          Gets the java version as string (e\.g\. "1.4.1").
static boolean isJava14()
          Checks if the current Java version is 1\.4 or higher.
static int rnd(double v)
          Rounds a double to an integer value using neares-number-rounding.
static int rnd(float v)
          Rounds a float to an integer value using neares-number-rounding.
static java.lang.String setSystemProperty(java.lang.String key, java.lang.String value)
          Sets the spcecified system property, including null value check.
static java.lang.String toStringNull(java.lang.Object o)
          Null-safe toString implementation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

equalsNull

public static boolean equalsNull(java.lang.Object o1,
                                 java.lang.Object o2)
Checks if two objects are equal or both null.

Parameters:
o1 - First object
o2 - Second object
Returns:
true Both objects are null or equal (using Objects.equals)
false The objects are not equal or only one of them is null.

compareNull

public static int compareNull(java.lang.Object o1,
                              java.lang.Object o2)
Compares two objects that implement the java.lang.Comparable interface that may also be null.

Parameters:
o1 - First object or null
o2 - Second object or null
Returns:
0 Both objects are null or equal
< 0 The first object os lexicographically smaller than the second object
> 0 The first object os lexicographically larger than the second object
Throws:
java.lang.ClassCastException - If one of the objects does not implement the Comparable interface

toStringNull

public static java.lang.String toStringNull(java.lang.Object o)
Null-safe toString implementation

Parameters:
o - Object to print
Returns:
o != null ? o.toString : null

rnd

public static int rnd(float v)
Rounds a float to an integer value using neares-number-rounding.

Parameters:
v - Value to round
Returns:
(int) Math.floor (v + 0.5f)

rnd

public static int rnd(double v)
Rounds a double to an integer value using neares-number-rounding.

Parameters:
v - Value to round
Returns:
(int) Math.floor (v + 0.5d)

setSystemProperty

public static java.lang.String setSystemProperty(java.lang.String key,
                                                 java.lang.String value)
Sets the spcecified system property, including null value check. System.setProperty will cause a null pointer exception if the value is null. This method will remove the property from the system properties on null values.

Parameters:
key - Property name
value - Value or null
Returns:
The old property value

isJava14

public static boolean isJava14()
Checks if the current Java version is 1\.4 or higher.


getJavaVersionStr

public static java.lang.String getJavaVersionStr()
Gets the java version as string (e\.g\. "1.4.1").


getJavaVersionInt

public static int getJavaVersionInt()
Gets the java version as 3 digit integer (e\.g\. 141).



Copyright © 2011. All Rights Reserved.