Class SV

All Implemented Interfaces:
javajs.api.JSONEncodable

public class SV extends T implements javajs.api.JSONEncodable
ScriptVariable class
  • Field Details

    • vT

      public static final SV vT
    • vF

      public static final SV vF
    • vNaN

      public static final SV vNaN
    • index

      public int index
    • myName

      public String myName
    • pt0

      static final javajs.util.P3 pt0
  • Constructor Details

    • SV

      public SV()
  • Method Details

    • newV

      public static SV newV(int tok, Object value)
    • newI

      public static SV newI(int i)
    • newF

      public static SV newF(float f)
    • newS

      public static SV newS(String s)
    • newT

      public static SV newT(T x)
    • newSV

      static SV newSV(int tok, int intValue, Object value)
    • setv

      SV setv(SV v)
      Creates a NEW version of the variable. Object values are not copied. (Just found no use for that.)
      Parameters:
      v -
      Returns:
      new ScriptVariable
    • sizeOf

      static int sizeOf(T x)
    • isVariableType

      public static boolean isVariableType(Object x)
      Must be updated if getVariable is updated!
      Parameters:
      x -
      Returns:
      if we recognize this as a variable
    • isArray

      private static boolean isArray(Object x)
      Must be updated if getVariable is updated!
      Parameters:
      x -
      Returns:
      if we recognize this as an primitive array type
    • getVariable

      public static SV getVariable(Object x)
      Parameters:
      x -
      Returns:
      a ScriptVariable of the input type, or if x is null, then a new ScriptVariable, or, if the type is not found, a string version
    • isASV

      private static boolean isASV(Object x)
    • newJSVar

      private static SV newJSVar(Object x)
      Conversion to Jmol variables of JavaScript variables using y = javascript("x")
      Parameters:
      x - a JavaScript variable, perhaps
      Returns:
      SV
    • getVariableMap

      public static SV getVariableMap(Map<String,?> x)
    • getVariableList

      public static SV getVariableList(javajs.util.Lst<?> v)
    • getVariableAV

      static SV getVariableAV(SV[] v)
    • getVariableAD

      public static SV getVariableAD(double[] f)
    • getVariableAO

      static SV getVariableAO(Object[] o)
    • getVariableAS

      static SV getVariableAS(String[] s)
    • getVariableAP

      static SV getVariableAP(javajs.util.T3[] p)
    • getVariableAFF

      static SV getVariableAFF(float[][] fx)
    • getVariableADD

      static SV getVariableADD(double[][] fx)
    • getVariableASS

      static SV getVariableASS(String[][] fx)
    • getVariableAII

      static SV getVariableAII(int[][] ix)
    • getVariableAF

      static SV getVariableAF(float[] f)
    • getVariableAI

      static SV getVariableAI(int[] ix)
    • getVariableAB

      static SV getVariableAB(byte[] ix)
    • setName

      public SV setName(String name)
    • canIncrement

      boolean canIncrement()
    • increment

      boolean increment(int n)
    • asBoolean

      public boolean asBoolean()
    • asInt

      public int asInt()
    • asFloat

      public float asFloat()
    • asString

      public String asString()
    • oValue

      public static Object oValue(Object xx)
      Parameters:
      xx -
      Returns:
      Object-wrapped value
    • nValue

      static Object nValue(T x)
      Parameters:
      x -
      Returns:
      numeric value -- integer or decimal
    • bValue

      public static boolean bValue(T x)
    • iValue

      public static int iValue(T x)
    • fValue

      public static float fValue(T x)
    • sValue

      public static String sValue(T x)
    • sValueArray

      private static void sValueArray(javajs.util.SB sb, SV vx, String path, String tabs, boolean isEscaped, boolean isRaw, boolean addValues, int maxLevels, boolean skipEmpty)
    • sValueAddKeys

      private static void sValueAddKeys(javajs.util.SB sb, String path, Map<String,SV> ht, String tabs, boolean isEscaped, boolean addValues, int maxLevels, boolean skipEmpty)
    • isRawType

      private static boolean isRawType(int tok)
    • ptValue

      public static javajs.util.P3 ptValue(SV x)
    • pt4Value

      public static javajs.util.P4 pt4Value(SV x)
    • toFloat

      private static float toFloat(String s)
    • concatList

      public static SV concatList(SV x1, SV x2, boolean asNew)
    • bsSelectToken

      private static javajs.util.BS bsSelectToken(T x)
    • bsSelectRange

      static javajs.util.BS bsSelectRange(T x, int n)
    • selectItemVar

      static SV selectItemVar(SV var)
    • selectItemTok

      static T selectItemTok(T tokenIn, int i2)
    • setSelectedValue

      void setSelectedValue(int pt1, int pt2, SV var)
    • escape

      public String escape()
    • unescapePointOrBitsetAsVariable

      public static Object unescapePointOrBitsetAsVariable(Object o)
    • getBoolean

      public static SV getBoolean(boolean value)
    • sprintf

      public static Object sprintf(String strFormat, SV var)
    • sprintf

      private static String sprintf(String strFormat, SV var, Object[] of, int[] vd, float[] vf, double[] ve, boolean getS, boolean getP, boolean getQ)
    • getFormatType

      public static int getFormatType(String format)
      Parameters:
      format -
      Returns:
      0: JSON, 5: base64, 12: bytearray, 22: array
    • format

      public static Object format(SV[] args, int pt)
      Accepts arguments from the format() function First argument is a format string.
      Parameters:
      args -
      pt - 0: to JSON, 5: to base64, 12: to bytearray, 22: to array
      Returns:
      formatted string
    • getBitSet

      public static javajs.util.BS getBitSet(SV x, boolean allowNull)
    • unEscapeBitSetArray

      static javajs.util.BS unEscapeBitSetArray(javajs.util.Lst<SV> x, boolean allowNull)
      Turn an array of strings in the form of "{n,n,n:n...} or an array of integers into a bitset.
      Parameters:
      x -
      allowNull -
      Returns:
      bitset (or null if fails and allowNull is false)
    • areEqual

      public static boolean areEqual(SV x1, SV x2)
      For legacy reasons, "x" == "X" but see isLike()
      Parameters:
      x1 -
      x2 -
      Returns:
      x1 == x2
    • isLike

      public static boolean isLike(SV x1, SV x2)
      a LIKE "x" a is a string and equals x a LIKE "*x" a is a string and ends with x a LIKE "x*" a is a string and starts with x a LIKE "*x*" a is a string and contains x
      Parameters:
      x1 -
      x2 -
      Returns:
      x1 LIKE x2
    • sortOrReverse

      public SV sortOrReverse(int arrayPt)
      Parameters:
      arrayPt - 1-based or Integer.MIN_VALUE to reverse
      Returns:
      sorted or reversed array
    • pushPop

      public SV pushPop(SV mapKey, SV value)
      Script variables are pushed after cloning, because the name comes with them when we do otherwise they are not mutable anyway. We do want to have actual references to points, lists, and associative arrays
      Parameters:
      mapKey -
      value - null to pop
      Returns:
      array
    • unEscapeBitSet

      private static boolean unEscapeBitSet(SV x, javajs.util.BS bs)
      Turn the string "({3:5})" into a bitset
      Parameters:
      x -
      bs -
      Returns:
      a bitset or a string converted to one
    • strListValue

      public static String[] strListValue(T x)
    • getArrayDepth

      public static int getArrayDepth(T x)
    • fflistValue

      public static float[][] fflistValue(T x, int nMin)
    • flistValue

      public static float[] flistValue(T x, int nMin)
    • toArray

      public SV toArray()
    • mapValue

      SV mapValue(String key)
    • getList

      public javajs.util.Lst<SV> getList()
    • isScalar

      public static boolean isScalar(SV x)
    • toJSON

      public String toJSON()
      Specified by:
      toJSON in interface javajs.api.JSONEncodable
    • mapGet

      public SV mapGet(String key)
    • mapPut

      public void mapPut(String key, SV v)
    • getMap

      public Map<String,SV> getMap()
    • getMapKeys

      public String getMapKeys(int nLevels, boolean skipEmpty)
    • toString

      public String toString()
      Overrides:
      toString in class T
    • getKeys

      public String[] getKeys(boolean isAll)
    • getKeyList

      private void getKeyList(boolean isAll, javajs.util.Lst<String> keys, String prefix)
    • deepCopy

      public static Object deepCopy(Object v, boolean isHash, boolean isDeep)
      Copies a hash or array deeply; invoked by Jmol script x = @a where a.type == "hash" or a.type == "varray"
      Parameters:
      v - hash or array
      isHash -
      isDeep - TODO
      Returns:
      deeply copied variable
    • deepCopySV

      private static SV deepCopySV(SV vm)
    • sortMapArray

      public SV sortMapArray(String key)
    • safeJSON

      public static Object safeJSON(String key, Object property)
      Safely create a JSON key - object pair, allowing for already-named arrays
      Parameters:
      key -
      property -
      Returns:
      JSON object
    • isNaN

      public boolean isNaN()