Class JSObject

java.lang.Object
com.amalgamasimulation.desktop.html.js.JSObject
All Implemented Interfaces:
JSConvertable

public class JSObject extends Object implements JSConvertable
The JSObject class represents a JavaScript object that can be converted to a JSON-like string. It implements the JSConvertable interface, allowing it to be used in contexts where JavaScript objects are required.
Author:
Alexey Glazyrin
  • Constructor Details

    • JSObject

      public JSObject()
  • Method Details

    • put

      public JSObject put(String path, JSConvertable value, boolean ifNotExists)
      Adds a key-value pair to the JavaScript object.
      Parameters:
      path - the path to the key (e.g., "chart.type")
      value - the value to associate with the key
      ifNotExists - if true, the value is only added if the key does not already exist
      Returns:
      this JSObject instance for method chaining
    • put

      public JSObject put(String path, JSConvertable value)
      Adds a key-value pair to the JavaScript object.
      Parameters:
      path - the path to the key (e.g., "chart.type")
      value - the value to associate with the key
      Returns:
      this JSObject instance for method chaining
    • getByPath

      public JSConvertable getByPath(String path)
      Retrieves the value associated with the specified path.
      Parameters:
      path - the path to the key (e.g., "chart.type")
      Returns:
      the value associated with the path, or null if the path does not exist
    • isEmpty

      public boolean isEmpty()
    • toJS

      public String toJS()
      Converts the JavaScript object to a JSON-like string representation.
      Specified by:
      toJS in interface JSConvertable
      Returns:
      the JSON-like string representation of the object