Package net.solarnetwork.util
Class NodeControlUtils
java.lang.Object
net.solarnetwork.util.NodeControlUtils
Utilities for working with
NodeControlInfo.- Since:
- 1.52
- Version:
- 1.0
- Author:
- Matt Magoffin
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringbooleanControlValue(Object value) Convert an object to a boolean control value.static StringcontrolValue(NodeControlPropertyType type, Object value) Convert an arbitrary object into a string suitable for using as a control value.static StringfloatControlValue(Object value) Convert an object to a floating point control value.static StringintegerControlValue(Object value) Convert an object to an integer control value.static StringpercentControlValue(Object value) Convert an object to a percentage control value.static StringstringControlValue(Object value) Convert an object to a string control value.
-
Constructor Details
-
NodeControlUtils
public NodeControlUtils()
-
-
Method Details
-
controlValue
Convert an arbitrary object into a string suitable for using as a control value.- Parameters:
type- the desired control property typevalue- the value- Returns:
- a string value derived from
value, or null ifvaluecannot be converted to an appropriate value
-
booleanControlValue
Convert an object to a boolean control value.This method converts
valueto a boolean value using the following rules:- if
valueis aBooleanthen use directly - if
valueis aStringthen return the result ofStringUtils.parseBoolean(String) - if
valueis aNumberthen ifNumber.intValue()is 0 then false otherwise true - if
valueis null then false otherwise true - otherwise the result of passing the value's
Object.toString()toStringUtils.parseBoolean(String)is returned
The resulting boolean value is then returned as a string, using "true" or "false".
- Parameters:
value- the value to convert to a boolean control value- Returns:
- either "true" or "false", never null
- if
-
floatControlValue
Convert an object to a floating point control value.This method converts
valueto aBigDecimalvalue using the following rules:- if
valueis aBigDecimalthen use directly - if
valueis aNumberthen create aBigDecimalfrom the string value of the number - otherwise null is returned
The resulting
BigDecimalvalue is then returned as a string.- Parameters:
value- the value to convert to a floating point control value- Returns:
- a decimal string representation of a float, or null if
valueis not a number
- if
-
integerControlValue
Convert an object to an integer control value.This method converts
valueto aBigIntegervalue using the following rules:- if
valueis aBigIntegerthen use directly - if
valueis aNumberthen create aBigDecimalfrom the string value of the number and convert that to a roundedBigIntegervalue - otherwise null is returned
The resulting
BigIntegervalue is then returned as a string.- Parameters:
value- the value to convert to an integer control value- Returns:
- a decimal string representation of an integer, or null
if
valueis not a number
- if
-
percentControlValue
Convert an object to a percentage control value.This method converts
valueto aBigDecimalvalue using the following rules:- if
valueis aBigDecimalthen use directly - if
valueis aBigDecimal,Integer, orLongthen convert to aBigDecimaland shift the decimal point left by 2 - if
valueis aNumberthen create aBigDecimalfrom the string value of the number - otherwise null is returned
The resulting
BigDecimalvalue is then returned as a string.- Parameters:
value- the value to convert to a percentage control value- Returns:
- a decimal string representation of a float, or null if
valueis not a number
- if
-
stringControlValue
Convert an object to a string control value.- Parameters:
value- the value to convert to an integer control value- Returns:
- a decimal string representation of an integer, or null
if
valueis not a number
-