Class NodeControlUtils

java.lang.Object
net.solarnetwork.util.NodeControlUtils

public final class NodeControlUtils extends Object
Utilities for working with NodeControlInfo.
Since:
1.52
Version:
1.0
Author:
Matt Magoffin
  • Constructor Details

    • NodeControlUtils

      public NodeControlUtils()
  • Method Details

    • controlValue

      public static String controlValue(NodeControlPropertyType type, Object value)
      Convert an arbitrary object into a string suitable for using as a control value.
      Parameters:
      type - the desired control property type
      value - the value
      Returns:
      a string value derived from value, or null if value cannot be converted to an appropriate value
    • booleanControlValue

      public static String booleanControlValue(Object value)
      Convert an object to a boolean control value.

      This method converts value to a boolean value using the following rules:

      1. if value is a Boolean then use directly
      2. if value is a String then return the result of StringUtils.parseBoolean(String)
      3. if value is a Number then if Number.intValue() is 0 then false otherwise true
      4. if value is null then false otherwise true
      5. otherwise the result of passing the value's Object.toString() to StringUtils.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
    • floatControlValue

      public static String floatControlValue(Object value)
      Convert an object to a floating point control value.

      This method converts value to a BigDecimal value using the following rules:

      1. if value is a BigDecimal then use directly
      2. if value is a Number then create a BigDecimal from the string value of the number
      3. otherwise null is returned

      The resulting BigDecimal value 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 value is not a number
    • integerControlValue

      public static String integerControlValue(Object value)
      Convert an object to an integer control value.

      This method converts value to a BigInteger value using the following rules:

      1. if value is a BigInteger then use directly
      2. if value is a Number then create a BigDecimal from the string value of the number and convert that to a rounded BigInteger value
      3. otherwise null is returned

      The resulting BigInteger value 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 value is not a number
    • percentControlValue

      public static String percentControlValue(Object value)
      Convert an object to a percentage control value.

      This method converts value to a BigDecimal value using the following rules:

      1. if value is a BigDecimal then use directly
      2. if value is a BigDecimal, Integer, or Long then convert to a BigDecimal and shift the decimal point left by 2
      3. if value is a Number then create a BigDecimal from the string value of the number
      4. otherwise null is returned

      The resulting BigDecimal value 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 value is not a number
    • stringControlValue

      public static String stringControlValue(Object value)
      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 value is not a number