1 ProcessBuilder

Class Ax.lang.ProcessBuilder


This class lets you run a shell command new Ax.lang.ProcessBuilder().command("bash", "-c", "ls /home/mkyong/");

Constructor Summary

Method
Description
Creates a new process.

Method Summary

Modifier and Type
Method
Description
int 
command(String[] args)
Sets the command for the process to execute, executes it, and returns 0 if there has not been any execution error, or !=0 otherwise.
Ax.io.File 
Returns the directory the process is at.
Ax.lang.ProcessBuilder 
directory(Ax.io.File file)
Sets the directory the process is at.
Ax.lang.ProcessBuilder 
directory(Ax.text.String file)
Sets the directory the process is at.
Ax.text.String 
Returns the std error of the command execution.
Ax.text.String 
Returns the std output of the command execution.
Ax.lang.ProcessBuilder 
setTimeout(int seconds)
Sets a timeout for the process, that is, the process will end ofter the defined time.

Constructor Detail

Ax.lang.ProcessBuilder.JSProcessBuilder

Ax.lang.ProcessBuilder.JSProcessBuilder()
Info:
Creates a new process.

Example
Copy
new Ax.lang.ProcessBuilder().command("bash", "-c", "ls /home/mkyong/");

Method Detail

Ax.lang.ProcessBuilder.command

smallint Ax.lang.ProcessBuilder.command(
	string[] args
)
Info:
Sets the command for the process to execute, executes it, and returns 0 if there has not been any execution error, or !=0 otherwise.
Parameters:
args - command arguments
Returns:
smallint

Example
Copy
var status = pb.directory('/tmp').command('/bin/bash', '-c', 'ls -l');

Ax.lang.ProcessBuilder.directory

file Ax.lang.ProcessBuilder.directory()
Info:
Returns the directory the process is at.
Returns:
file

Ax.lang.ProcessBuilder.directory

object Ax.lang.ProcessBuilder.directory(
	file file
)
Info:
Sets the directory the process is at.
Parameters:
file - file denoting the directory
Returns:
object

Ax.lang.ProcessBuilder.directory

object Ax.lang.ProcessBuilder.directory(
	string file
)
Info:
Sets the directory the process is at.
Parameters:
file - file denoting the directory
Returns:
object

Ax.lang.ProcessBuilder.getStdErr

string Ax.lang.ProcessBuilder.getStdErr()
Info:
Returns the std error of the command execution.
Returns:
string

Ax.lang.ProcessBuilder.getStdOut

string Ax.lang.ProcessBuilder.getStdOut()
Info:
Returns the std output of the command execution.
Returns:
string

Ax.lang.ProcessBuilder.setTimeout

object Ax.lang.ProcessBuilder.setTimeout(
	smallint seconds
)
Info:
Sets a timeout for the process, that is, the process will end ofter the defined time.
Parameters:
seconds - timeout in seconds
Returns:
object

2 Exception

Class Ax.lang.Exception


Class used to manage controlled and localized exceptions.

Constructor Summary

Method
Description
JSException(Ax.text.String error_code)
Creates a new exception with the specified code.
JSException(Ax.text.String error_code, Ax.text.String message)
Creates a new exception with the specified code and message.

Method Summary

Modifier and Type
Method
Description
void 
Returns the exception code.
Ax.text.String 
Returns the exception code.
Ax.text.String 
Returns the localized (locale-specific) exception message.
Ax.text.String 
Ax.text.String 
Returns the exception message, or the code if there is no message.
Ax.text.String 
void 
void 
void 
void 
setData(Object data)
setErrorCode(Ax.text.String error_code)
void 
Ax.text.String 

Constructor Detail

Ax.lang.Exception.JSException

Ax.lang.Exception.JSException(
	string error_code
						)
Info:
Creates a new exception with the specified code.
Parameters:
error_code - the exception code

Ax.lang.Exception.JSException

Ax.lang.Exception.JSException(
	string error_code,
	string message
						)
Info:
Creates a new exception with the specified code and message.
Parameters:
error_code - the exception code
message - the exception message

Example
Copy
throw new Ax.lang.Exception("E001", "Invoice XXX not found");

Method Detail

Ax.lang.Exception.addSuppressed

null Ax.lang.Exception.addSuppressed(
	object arg0
)
Parameters:
arg0 - 
Returns:
null

Ax.lang.Exception.fillInStackTrace

object Ax.lang.Exception.fillInStackTrace()
Returns:
object

Ax.lang.Exception.getCause

object Ax.lang.Exception.getCause()
Returns:
object

Ax.lang.Exception.getData

object Ax.lang.Exception.getData()
Info:
Returns the exception code.
Returns:
object

Ax.lang.Exception.getErrorCode

string Ax.lang.Exception.getErrorCode()
Info:
Returns the exception code.
Returns:
string

Ax.lang.Exception.getLocalizedMessage

string Ax.lang.Exception.getLocalizedMessage()
Info:
Returns the localized (locale-specific) exception message.
Returns:
string

Ax.lang.Exception.getLocalizedMessage

string Ax.lang.Exception.getLocalizedMessage()
Returns:
string

Ax.lang.Exception.getMessage

string Ax.lang.Exception.getMessage()
Info:
Returns the exception message, or the code if there is no message.
Returns:
string

Ax.lang.Exception.getMessage

string Ax.lang.Exception.getMessage()
Returns:
string

Ax.lang.Exception.getStackTrace

object Ax.lang.Exception.getStackTrace()
Returns:
object

Ax.lang.Exception.getSuppressed

object Ax.lang.Exception.getSuppressed()
Returns:
object

Ax.lang.Exception.initCause

object Ax.lang.Exception.initCause(
	object arg0
)
Parameters:
arg0 - 
Returns:
object

Ax.lang.Exception.printStackTrace

null Ax.lang.Exception.printStackTrace()
Returns:
null

Ax.lang.Exception.printStackTrace

null Ax.lang.Exception.printStackTrace(
	object arg0
)
Parameters:
arg0 - 
Returns:
null

Ax.lang.Exception.printStackTrace

null Ax.lang.Exception.printStackTrace(
	object arg0
)
Parameters:
arg0 - 
Returns:
null

Ax.lang.Exception.setCause

null Ax.lang.Exception.setCause(
	object arg0
)
Parameters:
arg0 - 
Returns:
null

Ax.lang.Exception.setData

object Ax.lang.Exception.setData(
	object data
)
Parameters:
data - 
Returns:
object

Ax.lang.Exception.setErrorCode

object Ax.lang.Exception.setErrorCode(
	string error_code
)
Parameters:
error_code - 
Returns:
object

Ax.lang.Exception.setStackTrace

null Ax.lang.Exception.setStackTrace(
	object arg0
)
Parameters:
arg0 - 
Returns:
null

Ax.lang.Exception.toString

string Ax.lang.Exception.toString()
Returns:
string

3 String

Class Ax.lang.String


A String wrapper that directly mimics String in many methods and implements others like lpad, rpad .. etc

Constructor Summary

Method
Description
JSString(Ax.text.String object)
Creates a new instance from a String.
JSString(byte[] object)
Creates a new instance from a byte array.
JSString(byte[] object, Ax.text.String encoding)
Creates a new instance from a byte array.

Method Summary

Modifier and Type
Method
Description
char 
charAt(int index)
Returns the char value at the specified index.
chars()
int 
Ax.lang.String 
Decode the XML escaped entities
Ax.lang.String 
Encodes the string for XML processing
boolean 
equals(Object obj)
Compares this string to the specified object.
Ax.lang.String 
format(Object[] args)
Formats the string with the given args.
Ax.lang.String 
format(Ax.text.String s, Object[] args)
Formats the string with the given args.
byte[] 
getBytes(Ax.text.String charsetName)
Encodes this
int 
Returns a hash code for this string.
boolean 
Returns true if the string is empty or contains only white space codepoints, otherwise false.
boolean 
Returns true if, and only if, length() is 0.
int 
length()
Returns the length of the sequence of characters represented by this string
Ax.lang.String 
lpad(char c, int length)
Adds the character c to the left of the string until the string has the specified length.
Ax.lang.String 
ltrim()
Deletes the spaces on the left of the string.
Ax.text.String 
ltrim(Ax.text.String s)
Deletes the spaces on the left of the string.
Ax.lang.String 
mask(Ax.text.String mask)
Masks the string with the provided mask
Ax.lang.String 
replace(CharSequence target, CharSequence replacement)
Replaces each substring of this string that matches the literal target sequence with the specified literal replacement sequence.
Ax.lang.String 
replaceAll(Ax.text.String regex,Ax.text.String replacement)
Replaces all the string subsequences defined by the regex with the specified replacement.
Ax.lang.String 
rpad(char c, int length)
Adds the character c to the right of the string until the string has the specified length.
Ax.lang.String 
rtrim()
Deletes the spaces on the right of the string.
Ax.text.String 
rtrim(Ax.text.String s)
Deletes the spaces on the right of the string.
subSequence(int start,int end)
Returns a character sequence that is a subsequence of this sequence.
Ax.text.String 
Mimics String, that is, returns a String from the JSString.
Ax.lang.String 
trim()
Deletes the spaces on the left and right of the string.
Ax.lang.String 
wrap(int wrapLength)
Wraps the string with the specified length, that is, separates the string in subsequences of wrapLength, adding a newline between them.
Ax.lang.String 
wrap(int wrapLength,Ax.text.String newLineStr)
Wraps the string with the specified length, that is, separates the string in subsequences of wrapLength, adding newLineStr between them.

Constructor Detail

Ax.lang.String.JSString

Ax.lang.String.JSString(
	string object
						)
Info:
Creates a new instance from a String.
Parameters:
object - source String

Ax.lang.String.JSString

Ax.lang.String.JSString(
	byte[] object
						)
Info:
Creates a new instance from a byte array.
Parameters:
object - source byte array

Ax.lang.String.JSString

Ax.lang.String.JSString(
	byte[] object,
	string encoding
						)
Info:
Creates a new instance from a byte array.
Parameters:
object - source byte array
encoding - encoding to use

Method Detail

Ax.lang.String.charAt

object Ax.lang.String.charAt(
	smallint index
)
Info:
Returns the char value at the specified index.
Parameters:
index - the index of the char value
Returns:
object

Ax.lang.String.chars

object Ax.lang.String.chars()
Returns:
object

Ax.lang.String.codePoints

object Ax.lang.String.codePoints()
Returns:
object

Ax.lang.String.compare

smallint Ax.lang.String.compare(
	string arg0,
	string arg1
)
Parameters:
arg0 - 
arg1 - 
Returns:
smallint

Ax.lang.String.decodeXML

object Ax.lang.String.decodeXML()
Info:
Decode the XML escaped entities
Returns:
object

Ax.lang.String.encodeXML

object Ax.lang.String.encodeXML()
Info:
Encodes the string for XML processing
Returns:
object

Ax.lang.String.equals

boolean Ax.lang.String.equals(
	object obj
)
Info:
Compares this string to the specified object. The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object.
Parameters:
obj - the object to compare this {@code String} against
Returns:
boolean

Ax.lang.String.format

object Ax.lang.String.format(
	object[] args
)
Info:
Formats the string with the given args.
Parameters:
args - parameters for the string formatting
Returns:
object

Example
Copy
var s = new Ax.lang.String('%s = %d').format('joe', 35);

Ax.lang.String.format

object Ax.lang.String.format(
	string s,
	object[] args
)
Info:
Formats the string with the given args. As it's static it can not decode the object[] of args using the engine! so we can not properly decode Nashorn/Graal native objects.
Parameters:
s - string to format
args - parameters for the string formatting
Returns:
object

Example
Copy
var s = Ax.lang.String.format("%s = %d", "joe", 35);

Ax.lang.String.getBytes

byte[] Ax.lang.String.getBytes(
	string charsetName
)
Info:
Encodes this
Parameters:
charsetName - encoding charset: US-ASCII, ISO-8859-1, UTF-8, UTF-16BE, UTF-16LE, UTF-16
Returns:
byte[]

Ax.lang.String.hashCode

smallint Ax.lang.String.hashCode()
Info:
Returns a hash code for this string. The hash code for a String object is computed as
Returns:
smallint

Example
Copy
s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
Example
Copy
Example
Copy
i

Ax.lang.String.isBlank

boolean Ax.lang.String.isBlank()
Info:
Returns true if the string is empty or contains only white space codepoints, otherwise false.
Returns:
boolean

Ax.lang.String.isEmpty

boolean Ax.lang.String.isEmpty()
Info:
Returns true if, and only if, length() is 0.
Returns:
boolean

Ax.lang.String.length

smallint Ax.lang.String.length()
Info:
Returns the length of the sequence of characters represented by this string
Returns:
smallint

Ax.lang.String.lpad

object Ax.lang.String.lpad(
	object c,
	smallint length
)
Info:
Adds the character c to the left of the string until the string has the specified length.
Parameters:
c - character to add
length - length to achieve
Returns:
object

Ax.lang.String.ltrim

object Ax.lang.String.ltrim()
Info:
Deletes the spaces on the left of the string.
Returns:
object

Ax.lang.String.ltrim

string Ax.lang.String.ltrim(
	string s
)
Info:
Deletes the spaces on the left of the string.
Parameters:
s - string to trim
Returns:
string

Ax.lang.String.mask

object Ax.lang.String.mask(
	string mask
)
Info:
Masks the string with the provided mask
Parameters:
mask - mask to apply
Returns:
object

Ax.lang.String.replace

object Ax.lang.String.replace(
	string target,
	string replacement
)
Info:
Replaces each substring of this string that matches the literal target sequence with the specified literal replacement sequence. The replacement proceeds from the beginning of the string to the end, for example, replacing "aa" with "b" in the string "aaa" will result in "ba" rather than "ab".
Parameters:
target - the sequence of char values to be replaced
replacement - the replacement sequence of char values
Returns:
object

Ax.lang.String.replaceAll

object Ax.lang.String.replaceAll(
	string regex,
	string replacement
)
Info:
Replaces all the string subsequences defined by the regex with the specified replacement.
Parameters:
regex - regular expression to define subsequences
replacement - replacement for the string subsequences
Returns:
object

Ax.lang.String.rpad

object Ax.lang.String.rpad(
	object c,
	smallint length
)
Info:
Adds the character c to the right of the string until the string has the specified length.
Parameters:
c - character to add
length - length to achieve
Returns:
object

Ax.lang.String.rtrim

object Ax.lang.String.rtrim()
Info:
Deletes the spaces on the right of the string.
Returns:
object

Ax.lang.String.rtrim

string Ax.lang.String.rtrim(
	string s
)
Info:
Deletes the spaces on the right of the string.
Parameters:
s - string to trim
Returns:
string

Ax.lang.String.subSequence

string Ax.lang.String.subSequence(
	smallint start,
	smallint end
)
Info:
Returns a character sequence that is a subsequence of this sequence.
Parameters:
start - the begin index, inclusive
end - the end index, exclusive
Returns:
string

Ax.lang.String.toString

string Ax.lang.String.toString()
Info:
Mimics String, that is, returns a String from the JSString.
Returns:
string

Ax.lang.String.trim

object Ax.lang.String.trim()
Info:
Deletes the spaces on the left and right of the string.
Returns:
object

Ax.lang.String.wrap

object Ax.lang.String.wrap(
	smallint wrapLength
)
Info:
Wraps the string with the specified length, that is, separates the string in subsequences of wrapLength, adding a newline between them. It does not separate words:
Parameters:
wrapLength - line length
Returns:
object

Example
Copy
"Here is one line of text that is going to be wrapped after 20 columns."
Example
Copy
Example
Copy
"Here is one line of\ntext that is going\nto be wrapped after\n20 columns."
Example
Copy
Example
Copy

Ax.lang.String.wrap

object Ax.lang.String.wrap(
	smallint wrapLength,
	string newLineStr
)
Info:
Wraps the string with the specified length, that is, separates the string in subsequences of wrapLength, adding newLineStr between them. It does not separate words:
Parameters:
wrapLength - line length
newLineStr - the string to insert for a new line
Returns:
object

Example
Copy
"Here is one line of text that is going to be wrapped after 20 columns."
Example
Copy
Example
Copy
"Here is one line of" + newLineStr + "text that is going" + newLineStr + "to be wrapped after" + newLineStr + "20 columns."
Example
Copy
Example
Copy

4 StringBuilder

Class Ax.lang.StringBuilder


The type Js string builder.

Constructor Summary

Method
Description
Instantiates a new Js string builder.
JSStringBuilder(int capacity)
Instantiates a new Js string builder.
JSStringBuilder(Ax.text.String str)
Instantiates a new Js string builder.

Method Summary

Modifier and Type
Method
Description
Ax.lang.StringBuilder 
append(Object obj)
Append js string builder.
Ax.lang.StringBuilder 
append(Ax.text.String str)
Ax.lang.StringBuilder 
append(boolean b)
Append js string builder.
Ax.lang.StringBuilder 
append(int i)
Append js string builder.
Ax.lang.StringBuilder 
append(long lng)
Append js string builder.
Ax.lang.StringBuilder 
append(float f)
Append js string builder.
Ax.lang.StringBuilder 
append(double d)
Append js string builder.
Ax.text.String 

Constructor Detail

Ax.lang.StringBuilder.JSStringBuilder

Ax.lang.StringBuilder.JSStringBuilder()
Info:
Instantiates a new Js string builder.

Ax.lang.StringBuilder.JSStringBuilder

Ax.lang.StringBuilder.JSStringBuilder(
	smallint capacity
						)
Info:
Instantiates a new Js string builder.
Parameters:
capacity - the capacity

Ax.lang.StringBuilder.JSStringBuilder

Ax.lang.StringBuilder.JSStringBuilder(
	string str
						)
Info:
Instantiates a new Js string builder.
Parameters:
str - the str

Method Detail

Ax.lang.StringBuilder.append

object Ax.lang.StringBuilder.append(
	object obj
)
Info:
Append js string builder.
Parameters:
obj - the obj
Returns:
object

Ax.lang.StringBuilder.append

object Ax.lang.StringBuilder.append(
	string str
)
Parameters:
str - 
Returns:
object

Ax.lang.StringBuilder.append

object Ax.lang.StringBuilder.append(
	boolean b
)
Info:
Append js string builder.
Parameters:
b - the b
Returns:
object

Ax.lang.StringBuilder.append

object Ax.lang.StringBuilder.append(
	smallint i
)
Info:
Append js string builder.
Parameters:
i - the
Returns:
object

Ax.lang.StringBuilder.append

object Ax.lang.StringBuilder.append(
	long lng
)
Info:
Append js string builder.
Parameters:
lng - the lng
Returns:
object

Ax.lang.StringBuilder.append

object Ax.lang.StringBuilder.append(
	object f
)
Info:
Append js string builder.
Parameters:
f - the f
Returns:
object

Ax.lang.StringBuilder.append

object Ax.lang.StringBuilder.append(
	double d
)
Info:
Append js string builder.
Parameters:
d - the d
Returns:
object

Ax.lang.StringBuilder.toString

string Ax.lang.StringBuilder.toString()
Returns:
string

5 System

Class Ax.lang.System


Static class with useful system fields and methods.

Method Summary

Modifier and Type
Method
Description
static boolean 
getBooleanProperty(Ax.text.String key, boolean _default)
Gets the system property indicated by the specified key.
static Map 
getEnv()
Returns an unmodifiable string map view of the current system environment.
static Ax.text.String 
getEnv(Ax.text.String key)
Gets the value of the specified environment variable
static Ax.text.String 
Returns the system-dependent default name-separator character, represented as a string.
static int 
getIntProperty(Ax.text.String key, int _default)
Gets the system property indicated by the specified key.
static Ax.text.String 
getProperty(Ax.text.String key)
Gets the system property indicated by the specified key.
static Ax.text.String 
getProperty(Ax.text.String key, Ax.text.String _default)
Gets the system property indicated by the specified key.
static boolean 
Returns whether the script is run in batch mode.
static void 
sleep(long millis)
Causes the currently executing thread to sleep for the specified number of milliseconds

Method Detail

Ax.lang.System.getBooleanProperty

static boolean Ax.lang.System.getBooleanProperty(
	string key,
	boolean _default
)
Info:
Gets the system property indicated by the specified key. The _defaut is returned if property doesn't exist.
Parameters:
key - key to identify system property
_default - default value
Returns:
boolean

Ax.lang.System.getEnv

static object Ax.lang.System.getEnv()
Info:
Returns an unmodifiable string map view of the current system environment.
Returns:
object

Ax.lang.System.getEnv

static string Ax.lang.System.getEnv(
	string key
)
Info:
Gets the value of the specified environment variable
Parameters:
key - environment variable name, like "HOME"
Returns:
string

Ax.lang.System.getFileSeparator

static string Ax.lang.System.getFileSeparator()
Info:
Returns the system-dependent default name-separator character, represented as a string.
Returns:
string

Ax.lang.System.getIntProperty

static smallint Ax.lang.System.getIntProperty(
	string key,
	smallint _default
)
Info:
Gets the system property indicated by the specified key. The _defaut is returned if property doesn't exist.
Parameters:
key - key to identify system property
_default - default value
Returns:
smallint

Ax.lang.System.getProperty

static string Ax.lang.System.getProperty(
	string key
)
Info:
Gets the system property indicated by the specified key.
Parameters:
key - key to identify system property
Returns:
string

Ax.lang.System.getProperty

static string Ax.lang.System.getProperty(
	string key,
	string _default
)
Info:
Gets the system property indicated by the specified key. The _defaut is returned if property doesn't exist.
Parameters:
key - key to identify system property
_default - default value
Returns:
string

Ax.lang.System.isBatch

static boolean Ax.lang.System.isBatch()
Info:
Returns whether the script is run in batch mode.
Returns:
boolean

Ax.lang.System.sleep

static null Ax.lang.System.sleep(
	long millis
)
Info:
Causes the currently executing thread to sleep for the specified number of milliseconds
Parameters:
millis - milliseconds to sleep
Returns:
null

6 Types

Class Ax.lang.Types


Class is static, method don't need to be static. as it extends AScriptJavaClass it provides data conversion methods toJava toJavaArray toJavascript

Method Summary

Modifier and Type
Method
Description
static Object 
Convert an object to a javascript object.

Method Detail

Ax.lang.Types.toJavascript

static object Ax.lang.Types.toJavascript(
	object src
)
Info:
Convert an object to a javascript object. The input can be either a javascript native object or a java object.
Parameters:
src - source java object
Returns:
object

Example
Copy
let fileList =  new Ax.io.File("/tmp").list();
   let jsArray =  Ax.lang.Types.toJavascript(fileList)
   // sort is a method in native js arrays
   jsArray.sort();
Example
Copy
push
Example
Copy
slice
Example
Copy
filter