Class WffBMObject
java.lang.Object
- All Implemented Interfaces:
WffBMData
,WffData
,Serializable
,Cloneable
,Map<String,
,ValueValueType> SequencedMap<String,
ValueValueType>
The java object representation for JavaScript object.
Sample code :-
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:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,
V>, AbstractMap.SimpleImmutableEntry<K, V> -
Constructor Summary
ConstructorsConstructorDescriptionWffBMObject
(boolean outer) WffBMObject
(byte[] bMBytes) WffBMObject
(byte[] bMBytes, boolean outer) -
Method Summary
Modifier and TypeMethodDescriptionbyte[]
replacement method for build() method.byte[]
buildBytes
(boolean outer) byte[]
getValueAsBigDecimal
(String key, Predicate<ValueAndValueType> predicate, BigDecimal defaultValue) To get value as BigDecimal if the predicate test returns true.getValueAsBigInteger
(String key, Predicate<ValueAndValueType> predicate, BigInteger defaultValue) To get value as BigInteger if the predicate test returns true.getValueAsBoolean
(String key) getValueAsBoolean
(String key, Predicate<ValueAndValueType> predicate, Boolean defaultValue) To get value as Boolean if the predicate test returns true.getValueAsDouble
(String key) getValueAsDouble
(String key, Predicate<ValueAndValueType> predicate, Double defaultValue) To get value as Double if the predicate test returns true.getValueAsFloat
(String key) getValueAsFloat
(String key, Predicate<ValueAndValueType> predicate, Float defaultValue) To get value as Float if the predicate test returns true.getValueAsInteger
(String key) getValueAsInteger
(String key, Predicate<ValueAndValueType> predicate, Integer defaultValue) To get value as Integer if the predicate test returns true.getValueAsLong
(String key) getValueAsLong
(String key, Predicate<ValueAndValueType> predicate, Long defaultValue) To get value as Long if the predicate test returns true.getValueAsString
(String key) getValueAsString
(String key, Predicate<ValueAndValueType> predicate, String defaultValue) To get value as String if the predicate test returns true.getValueAsWffBMArray
(String key, Predicate<ValueAndValueType> predicate, WffBMArray defaultValue) To get value as WffBMArray if the predicate test returns true.getValueAsWffBMByteArray
(String key, Predicate<ValueAndValueType> predicate, WffBMByteArray defaultValue) To get value as WffBMByteArray if the predicate test returns true.getValueAsWffBMNumberArray
(String key, Predicate<ValueAndValueType> predicate, WffBMNumberArray<?> defaultValue) To get value as WffBMNumberArray if the predicate test returns true.getValueAsWffBMObject
(String key, Predicate<ValueAndValueType> predicate, WffBMObject defaultValue) To get value as WffBMObject if the predicate test returns true.getValueType
(String key) boolean
isOuter()
void
put
(String key, BMValueType valueType, Object value) put
(String key, ValueValueType value) void
put
(String key, WffBMArray value) The value will be internally saved as WffBMArray and its BMValueType will be BM_ARRAY.void
put
(String key, WffBMByteArray value) The value will be internally saved as WffBMByteArray and its BMValueType will be BM_BYTE_ARRAY.void
put
(String key, WffBMObject value) The value will be internally saved as WffBMObject and its BMValueType will be BM_OBJECT.void
The value will be internally saved as boolean and its BMValueType will be NUMBER.void
The value will be internally saved as a double and its BMValueType will be NUMBER.void
putFunction
(String key, String function) The value will be internally saved as function string and its BMValueType will be FUNCTION.void
The value will be internally saved as null and its BMValueType will be NULL.void
The value will be internally saved as regex string and its BMValueType will be REG_EXP.void
The value will be internally saved as string and its BMValueType will be STRING.void
putUndefined
(String key) The value will be internally saved as null and its BMValueType will be UNDEFINED.void
setOuter
(boolean outer) boolean
similar
(WffBMObject other) Methods inherited from class java.util.LinkedHashMap
clear, containsValue, entrySet, forEach, get, getOrDefault, keySet, newLinkedHashMap, putFirst, putLast, removeEldestEntry, replaceAll, reversed, sequencedEntrySet, sequencedKeySet, sequencedValues, values
Methods inherited from class java.util.HashMap
clone, compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, newHashMap, putAll, putIfAbsent, remove, remove, replace, replace, size
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, containsKey, equals, hashCode, isEmpty, merge, putAll, putIfAbsent, remove, remove, replace, replace, size
Methods inherited from interface java.util.SequencedMap
firstEntry, lastEntry, pollFirstEntry, pollLastEntry
-
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
- Specified by:
put
in interfaceMap<String,
ValueValueType> - Overrides:
put
in classHashMap<String,
ValueValueType>
-
put
-
buildBytes
public byte[] buildBytes()replacement method for build() method.- Returns:
- Since:
- 3.0.15
-
buildBytes
public byte[] buildBytes(boolean outer) - Specified by:
buildBytes
in interfaceWffBMData
- 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
-
getValueType
- Parameters:
key
-- Returns:
- the value type of this key
- Since:
- 2.0.0
-
getBMType
-
put
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
-
put
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
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
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
The value will be internally saved as null and its BMValueType will be NULL.- Parameters:
key
- the key.- Since:
- 12.0.3
-
putUndefined
The value will be internally saved as null and its BMValueType will be UNDEFINED.- Parameters:
key
- the key.- Since:
- 12.0.3
-
putRegex
-
putString
-
putFunction
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
- 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:
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.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);
- 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
- 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:
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.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);
- 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
- 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:
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.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"));
- 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
- 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:
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.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"));
- 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
- 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:
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.WffBMObject wffBMObject = new WffBMObject(); wffBMObject.put("keyForInteger", 14); Integer valueAsInteger = wffBMObject.getValueAsInteger("keyForInteger", valueValueType -> valueValueType.value() != null && BMValueType.NUMBER.equals(valueValueType.valueType()), 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
- 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
To get value as Long if the predicate test returns true. Eg:
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.WffBMObject wffBMObject = new WffBMObject(); wffBMObject.put("keyForLong", 14L); Long valueAsLong = wffBMObject.getValueAsLong("keyForLong", valueValueType -> valueValueType.value() != null && BMValueType.NUMBER.equals(valueValueType.valueType()), 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
-
getValueAsString
public String getValueAsString(String key, Predicate<ValueAndValueType> predicate, String defaultValue) To get value as String if the predicate test returns true. Eg:
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".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");
- 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
-
getValueAsBoolean
public Boolean getValueAsBoolean(String key, Predicate<ValueAndValueType> predicate, Boolean defaultValue) To get value as Boolean if the predicate test returns true. Eg:
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.WffBMObject wffBMObject = new WffBMObject(); wffBMObject.put("keyForBoolean", true); Boolean valueAsBoolean = wffBMObject.getValueAsBoolean("keyForBoolean", valueValueType -> valueValueType.value() != null && BMValueType.BOOLEAN.equals(valueValueType.valueType()), 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
- 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:
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.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);
- 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
- 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:
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.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);
- 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
- 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:
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.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);
- 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
- 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:
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.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);
- 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
- 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
-