Class WffBMObject

All Implemented Interfaces:
WffBMData, WffData, Serializable, Cloneable, Map<String,ValueValueType>, SequencedMap<String,ValueValueType>

public class WffBMObject extends LinkedHashMap<String,ValueValueType> implements WffBMData
The java object representation for JavaScript object.
Sample code :-

 WffBMObject bmObject = new WffBMObject();
 bmObject.put("serverKey", BMValueType.STRING, "value from server");
 bmObject.put("string", BMValueType.STRING, "sample string");
 bmObject.put("nul", BMValueType.NULL, null);
 bmObject.put("number", BMValueType.NUMBER, 555);
 bmObject.put("undef", BMValueType.UNDEFINED, null);
 bmObject.put("reg", BMValueType.REG_EXP, "[w]");
 bmObject.put("bool", BMValueType.BOOLEAN, true);
 bmObject.put("testFun", BMValueType.FUNCTION, "function(arg) {alert(arg);}");
 
The WffBMObject can also hold array and binary data (as byte array). Check out WffBMArray and WffBMByteArray respectively.
See Also:
  • Constructor Details

    • WffBMObject

      public WffBMObject()
    • WffBMObject

      public WffBMObject(boolean outer)
    • WffBMObject

      public WffBMObject(byte[] bMBytes)
    • WffBMObject

      public WffBMObject(byte[] bMBytes, boolean outer)
  • Method Details

    • put

      public ValueValueType put(String key, ValueValueType value)
      Specified by:
      put in interface Map<String,ValueValueType>
      Overrides:
      put in class HashMap<String,ValueValueType>
    • put

      public void put(String key, BMValueType valueType, Object value)
    • buildBytes

      public byte[] buildBytes()
      replacement method for build() method.
      Returns:
      Since:
      3.0.15
    • buildBytes

      public byte[] buildBytes(boolean outer)
      Specified by:
      buildBytes in interface WffBMData
      Parameters:
      outer -
      Returns:
      bytes for this WffBMObject
      Since:
      3.0.2
    • getBMBytes

      public byte[] getBMBytes()
      Returns:
      the bmBytes
      Since:
      3.0.16
    • isOuter

      public boolean isOuter()
    • setOuter

      public void setOuter(boolean outer)
    • getValue

      public Object getValue(String key)
      Parameters:
      key - the key name
      Since:
      2.0.0
    • getValueType

      public BMValueType getValueType(String key)
      Parameters:
      key -
      Returns:
      the value type of this key
      Since:
      2.0.0
    • getBMType

      public BMType getBMType()
      Specified by:
      getBMType in interface WffBMData
      Returns:
      the BMType
    • put

      public void put(String key, Number value)
      The value will be internally saved as a double and its BMValueType will be NUMBER. If you want to save a big value larger than double, save it as a string and get it by getValueAsBigInteger/getValueAsBigDecimal method.
      Parameters:
      key - the key.
      value - the value for the key.
      Since:
      12.0.3
    • put

      public void put(String key, Boolean value)
      The value will be internally saved as boolean and its BMValueType will be NUMBER.
      Parameters:
      key - the key.
      value - the value for the key.
      Since:
      12.0.3
    • put

      public void put(String key, WffBMObject value)
      The value will be internally saved as WffBMObject and its BMValueType will be BM_OBJECT.
      Parameters:
      key - the key.
      value - the value for the key.
      Since:
      12.0.3
    • put

      public void put(String key, WffBMArray value)
      The value will be internally saved as WffBMArray and its BMValueType will be BM_ARRAY.
      Parameters:
      key - the key.
      value - the value for the key.
      Since:
      12.0.3
    • put

      public void put(String key, WffBMByteArray value)
      The value will be internally saved as WffBMByteArray and its BMValueType will be BM_BYTE_ARRAY.
      Parameters:
      key - the key.
      value - the value for the key.
      Since:
      12.0.3
    • putNull

      public void putNull(String key)
      The value will be internally saved as null and its BMValueType will be NULL.
      Parameters:
      key - the key.
      Since:
      12.0.3
    • putUndefined

      public void putUndefined(String key)
      The value will be internally saved as null and its BMValueType will be UNDEFINED.
      Parameters:
      key - the key.
      Since:
      12.0.3
    • putRegex

      public void putRegex(String key, String regex)
      The value will be internally saved as regex string and its BMValueType will be REG_EXP. Eg:
      
           WffBMObject obj = new WffBMObject();
           obj.putRegex("regexStr", "[w]");
       
      Parameters:
      key - the key. @ param value the value for the key.
      Since:
      12.0.3
    • putString

      public void putString(String key, String string)
      The value will be internally saved as string and its BMValueType will be STRING.
      Parameters:
      key - the key. @ param value the value for the key.
      Since:
      12.0.3
    • putFunction

      public void putFunction(String key, String function)
      The value will be internally saved as function string and its BMValueType will be FUNCTION. Eg:
      
           WffBMObject obj = new WffBMObject();
           obj.putFunction("funKey", "function(arg) {console.log(arg);}");
       
      Parameters:
      key - the key. @ param value the value for the key.
      Since:
      12.0.3
    • getValueAsDouble

      public Double getValueAsDouble(String key) throws NumberFormatException
      Parameters:
      key - the key to get the value.
      Returns:
      the Double value.
      Throws:
      NumberFormatException - if the value is not convertible to Double.
      Since:
      12.0.3
    • getValueAsDouble

      public Double getValueAsDouble(String key, Predicate<ValueAndValueType> predicate, Double defaultValue) throws NumberFormatException
      To get value as Double if the predicate test returns true. Eg:
      
       WffBMObject wffBMObject = new WffBMObject();
       wffBMObject.put("keyForDouble", 14.01D);
       Double valueAsDouble = wffBMObject.getValueAsDouble("keyForDouble", valueValueType -> valueValueType.value() != null && BMValueType.NUMBER.equals(valueValueType.valueType()), 1401.19D);
       
      In the above code if the value is not null and valueType is NUMBER then only it will convert the value to Double otherwise it will return the default value passed in the third argument i.e. 1401.19D.
      Parameters:
      key - the key to get the value.
      predicate - to test the condition to return the converted value. If the predicate test returns true this method will return the converted value otherwise it will return default value.
      defaultValue - the default value to return.
      Returns:
      the Double value.
      Throws:
      NumberFormatException - if the value is not convertible to Double.
      Since:
      12.0.3
    • getValueAsFloat

      public Float getValueAsFloat(String key) throws NumberFormatException
      Parameters:
      key - the key to get the value.
      Returns:
      the Float value.
      Throws:
      NumberFormatException - if the value is not convertible to Float.
      Since:
      12.0.3
    • getValueAsFloat

      public Float getValueAsFloat(String key, Predicate<ValueAndValueType> predicate, Float defaultValue) throws NumberFormatException
      To get value as Float if the predicate test returns true. Eg:
      
       WffBMObject wffBMObject = new WffBMObject();
       wffBMObject.put("keyForFloat", 14.01F);
       Float valueAsFloat = wffBMObject.getValueAsFloat("keyForFloat", valueValueType -> valueValueType.value() != null && BMValueType.NUMBER.equals(valueValueType.valueType()), 1401.19F);
       
      In the above code if the value is not null and valueType is NUMBER then only it will convert the value to Float otherwise it will return the default value passed in the third argument i.e. 1401.19F.
      Parameters:
      key - the key to get the value.
      predicate - to test the condition to return the converted value. If the predicate test returns true this method will return the converted value otherwise it will return default value.
      defaultValue - the default value to return.
      Returns:
      the Float value.
      Throws:
      NumberFormatException - if the value is not convertible to Float.
      Since:
      12.0.3
    • getValueAsBigDecimal

      public BigDecimal getValueAsBigDecimal(String key) throws NumberFormatException
      Parameters:
      key - the key to get the value.
      Returns:
      the BigDecimal value.
      Throws:
      NumberFormatException - if the value is not convertible to BigDecimal.
      Since:
      12.0.3
    • getValueAsBigDecimal

      public BigDecimal getValueAsBigDecimal(String key, Predicate<ValueAndValueType> predicate, BigDecimal defaultValue) throws NumberFormatException
      To get value as BigDecimal if the predicate test returns true. Eg:
      
       WffBMObject wffBMObject = new WffBMObject();
       wffBMObject.put("keyForBigDecimal", new BigDecimal("14.01"));
       BigDecimal valueAsBigDecimal = wffBMObject.getValueAsBigDecimal("keyForBigDecimal", valueValueType -> valueValueType.value() != null && BMValueType.NUMBER.equals(valueValueType.valueType()), new BigDecimal("1401.19"));
       
      In the above code if the value is not null and valueType is NUMBER then only it will convert the value to BigDecimal otherwise it will return the default value passed in the third argument i.e. 1401.19.
      Parameters:
      key - the key to get the value.
      predicate - to test the condition to return the converted value. If the predicate test returns true this method will return the converted value otherwise it will return default value.
      defaultValue - the default value to return.
      Returns:
      the BigDecimal value.
      Throws:
      NumberFormatException - if the value is not convertible to BigDecimal.
      Since:
      12.0.3
    • getValueAsBigInteger

      public BigInteger getValueAsBigInteger(String key) throws NumberFormatException
      Parameters:
      key - the key to get the value.
      Returns:
      the BigInteger value.
      Throws:
      NumberFormatException - if the value is not convertible to BigInteger.
      Since:
      12.0.3
    • getValueAsBigInteger

      public BigInteger getValueAsBigInteger(String key, Predicate<ValueAndValueType> predicate, BigInteger defaultValue) throws NumberFormatException
      To get value as BigInteger if the predicate test returns true. Eg:
      
       WffBMObject wffBMObject = new WffBMObject();
       wffBMObject.put("keyForBigInteger", new BigInteger("14"));
       BigInteger valueAsBigInteger = wffBMObject.getValueAsBigInteger("keyForBigInteger", valueValueType -> valueValueType.value() != null && BMValueType.NUMBER.equals(valueValueType.valueType()), new BigInteger("1401"));
       
      In the above code if the value is not null and valueType is NUMBER then only it will convert the value to BigInteger otherwise it will return the default value passed in the third argument i.e. 1401.
      Parameters:
      key - the key to get the value.
      predicate - to test the condition to return the converted value. If the predicate test returns true this method will return the converted value otherwise it will return default value.
      defaultValue - the default value to return.
      Returns:
      the BigInteger value.
      Throws:
      NumberFormatException - if the value is not convertible to BigInteger.
      Since:
      12.0.3
    • getValueAsInteger

      public Integer getValueAsInteger(String key) throws NumberFormatException
      Parameters:
      key - the key to get the value.
      Returns:
      the Integer value.
      Throws:
      NumberFormatException - if the value is not convertible to Integer.
      Since:
      12.0.3
    • getValueAsInteger

      public Integer getValueAsInteger(String key, Predicate<ValueAndValueType> predicate, Integer defaultValue) throws NumberFormatException
      To get value as Integer if the predicate test returns true. Eg:
      
       WffBMObject wffBMObject = new WffBMObject();
       wffBMObject.put("keyForInteger", 14);
       Integer valueAsInteger = wffBMObject.getValueAsInteger("keyForInteger", valueValueType -> valueValueType.value() != null && BMValueType.NUMBER.equals(valueValueType.valueType()), 1401);
       
      In the above code if the value is not null and valueType is NUMBER then only it will convert the value to Integer otherwise it will return the default value passed in the third argument i.e. 1401.
      Parameters:
      key - the key to get the value.
      predicate - to test the condition to return the converted value. If the predicate test returns true this method will return the converted value otherwise it will return default value.
      defaultValue - the default value to return.
      Returns:
      the Integer value.
      Throws:
      NumberFormatException - if the value is not convertible to Integer.
      Since:
      12.0.3
    • getValueAsLong

      public Long getValueAsLong(String key)
      Parameters:
      key - the key to get the value.
      Returns:
      the Long value.
      Throws:
      NumberFormatException - if the value is not convertible to Long.
      Since:
      12.0.3
    • getValueAsLong

      public Long getValueAsLong(String key, Predicate<ValueAndValueType> predicate, Long defaultValue)
      To get value as Long if the predicate test returns true. Eg:
      
       WffBMObject wffBMObject = new WffBMObject();
       wffBMObject.put("keyForLong", 14L);
       Long valueAsLong = wffBMObject.getValueAsLong("keyForLong", valueValueType -> valueValueType.value() != null && BMValueType.NUMBER.equals(valueValueType.valueType()), 1401L);
       
      In the above code if the value is not null and valueType is NUMBER then only it will convert the value to Long otherwise it will return the default value passed in the third argument i.e. 1401L.
      Parameters:
      key - the key to get the value.
      predicate - to test the condition to return the converted value. If the predicate test returns true this method will return the converted value otherwise it will return default value.
      defaultValue - the default value to return.
      Returns:
      the Long value.
      Throws:
      NumberFormatException - if the value is not convertible to Long.
      Since:
      12.0.3
    • getValueAsString

      public String getValueAsString(String key)
      Parameters:
      key - the key to get the value.
      Returns:
      the value as String.
      Since:
      12.0.3
    • getValueAsString

      public String getValueAsString(String key, Predicate<ValueAndValueType> predicate, String defaultValue)
      To get value as String if the predicate test returns true. Eg:
      
       WffBMObject wffBMObject = new WffBMObject();
       wffBMObject.putString("keyForString", "wffweb");
       String valueAsString = wffBMObject.getValueAsString("keyForString", valueValueType -> valueValueType.value() != null && BMValueType.STRING.equals(valueValueType.valueType()), "some default value");
       
      In the above code if the value is not null and valueType is STRING then only it will convert the value to String otherwise it will return the default value passed in the third argument i.e. "some default value".
      Parameters:
      key - the key to get the value.
      predicate - to test the condition to return the converted value. If the predicate test returns true this method will return the converted value otherwise it will return default value.
      defaultValue - the default value to return.
      Returns:
      the value as String.
      Since:
      12.0.3
    • getValueAsBoolean

      public Boolean getValueAsBoolean(String key)
      Parameters:
      key - the key to get the value.
      Returns:
      the value as Boolean.
      Since:
      12.0.3
    • getValueAsBoolean

      public Boolean getValueAsBoolean(String key, Predicate<ValueAndValueType> predicate, Boolean defaultValue)
      To get value as Boolean if the predicate test returns true. Eg:
      
       WffBMObject wffBMObject = new WffBMObject();
       wffBMObject.put("keyForBoolean", true);
       Boolean valueAsBoolean = wffBMObject.getValueAsBoolean("keyForBoolean", valueValueType -> valueValueType.value() != null && BMValueType.BOOLEAN.equals(valueValueType.valueType()), null);
       
      In the above code if the value is not null and valueType is BOOLEAN then only it will convert the value to Boolean otherwise it will return the default value passed in the third argument, i.e null.
      Parameters:
      key - the key to get the value.
      predicate - to test the condition to return the converted value. If the predicate test returns true this method will return the converted value otherwise it will return default value.
      defaultValue - the default value to return.
      Returns:
      the value as Boolean.
      Since:
      12.0.3
    • getValueAsWffBMObject

      public WffBMObject getValueAsWffBMObject(String key)
      Parameters:
      key - the key to get the value.
      Returns:
      the value as WffBMObject.
      Since:
      12.0.4
    • getValueAsWffBMObject

      public WffBMObject getValueAsWffBMObject(String key, Predicate<ValueAndValueType> predicate, WffBMObject defaultValue)
      To get value as WffBMObject if the predicate test returns true. Eg:
      
       WffBMObject wffBMObject = new WffBMObject();
       wffBMObject.put("keyForWffBMObject", new WffBMObject());
       WffBMObject valueAsWffBMObject = wffBMObject.getValueAsWffBMObject("keyForWffBMObject", valueValueType -> valueValueType.value() != null && BMValueType.BM_OBJECT.equals(valueValueType.valueType()), null);
       
      In the above code if the value is not null and valueType is BM_OBJECT then only it will convert the value to WffBMObject otherwise it will return the default value passed in the third argument, i.e null.
      Parameters:
      key - the key to get the value.
      predicate - to test the condition to return the converted value. If the predicate test returns true this method will return the converted value otherwise it will return default value.
      defaultValue - the default value to return.
      Returns:
      the value as WffBMObject.
      Since:
      12.0.4
    • getValueAsWffBMArray

      public WffBMArray getValueAsWffBMArray(String key)
      Parameters:
      key - the key to get the value.
      Returns:
      the value as WffBMArray.
      Since:
      12.0.4
    • getValueAsWffBMArray

      public WffBMArray getValueAsWffBMArray(String key, Predicate<ValueAndValueType> predicate, WffBMArray defaultValue)
      To get value as WffBMArray if the predicate test returns true. Eg:
      
       WffBMObject wffBMObject = new WffBMObject();
       wffBMObject.put("keyForWffBMArray", new WffBMArray(BMValueType.STRING));
       WffBMArray valueAsWffBMArray = wffBMObject.getValueAsWffBMArray("keyForWffBMArray", valueValueType -> valueValueType.value() != null && BMValueType.BM_ARRAY.equals(valueValueType.valueType()), null);
       
      In the above code if the value is not null and valueType is BM_ARRAY then only it will convert the value to WffBMArray otherwise it will return the default value passed in the third argument, i.e null.
      Parameters:
      key - the key to get the value.
      predicate - to test the condition to return the converted value. If the predicate test returns true this method will return the converted value otherwise it will return default value.
      defaultValue - the default value to return.
      Returns:
      the value as WffBMArray.
      Since:
      12.0.4
    • getValueAsWffBMNumberArray

      public WffBMNumberArray<?> getValueAsWffBMNumberArray(String key)
      Parameters:
      key - the key to get the value.
      Returns:
      the value as WffBMNumberArray.
      Since:
      12.0.4
    • getValueAsWffBMNumberArray

      public WffBMNumberArray<?> getValueAsWffBMNumberArray(String key, Predicate<ValueAndValueType> predicate, WffBMNumberArray<?> defaultValue)
      To get value as WffBMNumberArray if the predicate test returns true. Eg:
      
       WffBMObject wffBMObject = new WffBMObject();
       wffBMObject.put("keyForWffBMNumberArray", new WffBMNumberArray<?>());
       WffBMNumberArray<?> valueAsWffBMArray = wffBMObject.getValueAsWffBMNumberArray("keyForWffBMNumberArray", valueValueType -> valueValueType.value() != null && BMValueType.BM_ARRAY.equals(valueValueType.valueType()), null);
       
      In the above code if the value is not null and valueType is BM_ARRAY then only it will convert the value to WffBMNumberArray otherwise it will return the default value passed in the third argument, i.e null.
      Parameters:
      key - the key to get the value.
      predicate - to test the condition to return the converted value. If the predicate test returns true this method will return the converted value otherwise it will return default value.
      defaultValue - the default value to return.
      Returns:
      the value as WffBMNumberArray.
      Since:
      12.0.4
    • getValueAsWffBMByteArray

      public WffBMByteArray getValueAsWffBMByteArray(String key)
      Parameters:
      key - the key to get the value.
      Returns:
      the value as WffBMByteArray.
      Since:
      12.0.4
    • getValueAsWffBMByteArray

      public WffBMByteArray getValueAsWffBMByteArray(String key, Predicate<ValueAndValueType> predicate, WffBMByteArray defaultValue)
      To get value as WffBMByteArray if the predicate test returns true. Eg:
      
       WffBMObject wffBMObject = new WffBMObject();
       wffBMObject.put("keyForWffBMArray", new WffBMByteArray());
       WffBMByteArray valueAsWffBMByteArray = wffBMObject.getValueAsWffBMByteArray("keyForWffBMArray", valueValueType -> valueValueType.value() != null && BMValueType.BM_BYTE_ARRAY.equals(valueValueType.valueType()), null);
       
      In the above code if the value is not null and valueType is BM_BYTE_ARRAY then only it will convert the value to WffBMByteArray otherwise it will return the default value passed in the third argument, i.e null.
      Parameters:
      key - the key to get the value.
      predicate - to test the condition to return the converted value. If the predicate test returns true this method will return the converted value otherwise it will return default value.
      defaultValue - the default value to return.
      Returns:
      the value as WffBMByteArray.
      Since:
      12.0.4
    • similar

      public boolean similar(WffBMObject other)
      Parameters:
      other - the other object for similarity checking.
      Returns:
      true if the other object also contains the same data otherwise false.
      Since:
      12.0.3