Class JSCollection<T extends JSConvertable>

java.lang.Object
com.amalgamasimulation.desktop.html.js.JSCollection<T>
Type Parameters:
T - the type of elements in the collection, which must implement JSConvertable
All Implemented Interfaces:
JSConvertable

public class JSCollection<T extends JSConvertable> extends Object implements JSConvertable
Represents a collection of JavaScript-convertible elements. It implements the JSConvertable interface, allowing it to be converted to a JavaScript array.
Author:
Alexey Glazyrin
  • Constructor Details

    • JSCollection

      public JSCollection(List<T> value)
      Constructs a new JSCollection instance with the specified collection of elements.
      Parameters:
      value - the collection of elements to include in the JavaScript array
    • JSCollection

      public JSCollection()
      Constructs a new JSCollection instance
  • Method Details

    • createPrimitive

      public static <T> JSCollection<? extends JSConvertable> createPrimitive(Collection<T> value)
      Creates a new JSCollection instance from a collection of primitive values. Each value is wrapped in a JSPrimitive object.
      Type Parameters:
      T - the type of primitive values in the collection
      Parameters:
      value - the collection of primitive values
      Returns:
      a new JSCollection instance containing the wrapped primitive values
    • createFunctions

      public static JSCollection<JSFunction> createFunctions(Collection<String> value)
    • add

      public void add(T element)
      Adds an element to the collection.
      Parameters:
      element - the element to add
    • set

      public void set(int index, T element)
    • size

      public int size()
    • toJS

      public String toJS()
      Converts the collection to a JavaScript array string representation.
      Specified by:
      toJS in interface JSConvertable
      Returns:
      the JavaScript array representation of the collection