Jess Information

Jess Home
Jess 7 Features
Download Now!
Online Demo

Documentation
FAQ
Manual
Mailing List
Jess Wiki

More information Related Web Sites
User Contributions
JSR94 Info
Developer's Log
About This Site

JESS ®, the Rule Engine for the JavaTM Platform

Jess Wiki: Array Manipulation Tips

Here are some useful functions to create arrays of particular Java types in JESS:

; returns a new array of the given length of given primitive type
(deffunction new-array (?type ?length)
   (bind ?classType nil)
   (if
      (eq ?type byte)
   then
      (bind ?classType java.lang.Byte)
   )

   (if
      (eq ?type double)
   then
      (bind ?classType java.lang.Double)
   )

   (if
      (eq ?type float)
   then
      (bind ?classType java.lang.Float)
   )

   (if
      (eq ?type int)
   then
      (bind ?classType java.lang.Integer)
   )

   (if
      (eq ?type long)
   then
      (bind ?classType java.lang.Long)
   )

   (if
      (eq ?type short)
   then
      (bind ?classType java.lang.Short)
   )

   (if
      (eq ?classType nil)
   then
      (bind ?classType (call java.lang.Class forName ?type))
      (return (call java.lang.reflect.Array newInstance ?classType ?length))
   )

   (return (call java.lang.reflect.Array newInstance (get-member ?classType TYPE) ?length))
)

(deffunction array-set (?array ?index ?value)
   (call java.lang.reflect.Array set ?array ?index ?value)
)

(deffunction array-get (?array ?index)
   (return (call java.lang.reflect.Array get ?array ?index))
)

(deffunction array-length (?array)
   (return (call java.lang.reflect.Array getLength ?array))
)


Front Page | Sandbox | Recent Changes | Powered by Friki | Last Edited: 08 September 2008