Class WffBMArray

All Implemented Interfaces:
WffBMData, WffData, Serializable, Cloneable, Iterable<Object>, Collection<Object>, Deque<Object>, List<Object>, Queue<Object>
Direct Known Subclasses:
WffBMNumberArray

public class WffBMArray extends LinkedList<Object> implements WffBMData
The java array object representation for JavaScript array.
Sample code :-
 WffBMObject bmObject = new WffBMObject();

 WffBMArray stringArray = new WffBMArray(BMValueType.STRING);
 stringArray.add("array value 1");
 stringArray.add("array value 2");

 bmObject.put("stringArray", BMValueType.BM_ARRAY, stringArray);

 WffBMArray numberArray = new WffBMArray(BMValueType.NUMBER);
 numberArray.add(555);
 numberArray.add(5);
 numberArray.add(55);

 bmObject.put("numberArray", BMValueType.BM_ARRAY, numberArray);

 // to store bytes in an array use WffBMByteArray
 WffBMByteArray byteArray = new WffBMByteArray();
 byteArray.write("こんにちは WFFWEB".getBytes(StandardCharsets.UTF_8));

 bmObject.put("byteArray", BMValueType.BM_BYTE_ARRAY, byteArray);

 WffBMArray booleanArray = new WffBMArray(BMValueType.BOOLEAN);
 booleanArray.add(true);
 booleanArray.add(false);
 booleanArray.add(true);

 bmObject.put("booleanArray", BMValueType.BM_ARRAY, booleanArray);

 WffBMArray regexArray = new WffBMArray(BMValueType.REG_EXP);
 regexArray.add("[w]");
 regexArray.add("[f]");
 regexArray.add("[f]");

 bmObject.put("regexArray", BMValueType.BM_ARRAY, regexArray);

 WffBMArray funcArray = new WffBMArray(BMValueType.FUNCTION);
 funcArray.add("function(arg) {console.log(arg);}");
 funcArray.add("function(arg1) {console.log(arg1);}");
 funcArray.add("function(arg2) {console.log(arg2);}");

 bmObject.put("funcArray", BMValueType.BM_ARRAY, funcArray);

 WffBMArray nullArray = new WffBMArray(BMValueType.NULL);
 nullArray.add(null);
 nullArray.add(null);
 nullArray.add(null);

 bmObject.put("nullArray", BMValueType.BM_ARRAY, nullArray);

 WffBMArray undefinedArray = new WffBMArray(BMValueType.UNDEFINED);
 undefinedArray.add(null);
 undefinedArray.add(null);
 undefinedArray.add(null);

 bmObject.put("undefinedArray", BMValueType.BM_ARRAY, undefinedArray);

 WffBMArray arrayArray = new WffBMArray(BMValueType.BM_ARRAY);
 arrayArray.add(funcArray);
 arrayArray.add(funcArray);
 arrayArray.add(funcArray);

 bmObject.put("arrayArray", BMValueType.BM_ARRAY, arrayArray);

 WffBMArray objectArray = new WffBMArray(BMValueType.BM_OBJECT);
 objectArray.add(bmObject.clone());
 objectArray.add(bmObject.clone());
 objectArray.add(bmObject.clone());

 bmObject.put("objectArray", BMValueType.BM_ARRAY, objectArray);
 
See Also:
  • Constructor Details

    • WffBMArray

      public WffBMArray(BMValueType valueType)
    • WffBMArray

      public WffBMArray(BMValueType valueType, boolean outer)
    • WffBMArray

      public WffBMArray(byte[] bmArrayBytes)
    • WffBMArray

      public WffBMArray(byte[] bmArrayBytes, boolean outer)
  • Method Details

    • isOuter

      public boolean isOuter()
    • setOuter

      public void setOuter(boolean outer)
    • build

      public byte[] build()
    • build

      @Deprecated public byte[] build(boolean outer) throws UnsupportedEncodingException
      Deprecated.
      building bytes implementation doesn't throw UnsupportedEncodingException so deprecated this method. The same goal can be achieved using buildBytes method.
      NB: use buildBytes instead of this method.
      Specified by:
      build in interface WffBMData
      Parameters:
      outer -
      Returns:
      the bytes representation of the object
      Throws:
      UnsupportedEncodingException - throwing this exception will be removed in future version because its internal implementation will never make this exception due to the code changes since 3.0.1.
      Since:
      1.1.5
    • buildBytes

      public byte[] buildBytes(boolean outer)
      Specified by:
      buildBytes in interface WffBMData
      Parameters:
      outer -
      Returns:
      bytes for this WffBMArray object
    • getValueType

      public BMValueType getValueType()
      gets value type of this array only if it contains any value otherwise returns null.
      Returns:
      the value type of this array
      Since:
      2.1.0
    • getBMType

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