Java Utililty Methods Nashorn Javascript Library

List of utility methods to do Nashorn Javascript Library

Description

The list of methods to do Nashorn Javascript Library are organized into topic(s).

Method

voidaddToArray(final Object array, final Object value)
add To Array
((ScriptObjectMirror) array).callMember("push", value);
voidaddToNativeObject(final Object object, final String key, final Object value)
add To Native Object
((ScriptObject) object).put(key, value, false);
Stringdecode(final Object self, final String string, final boolean component)
decode
if (string.isEmpty()) {
    return string;
final int len = string.length();
final StringBuilder sb = new StringBuilder();
for (int k = 0; k < len; k++) {
    final char ch = string.charAt(k);
    if (ch != '%') {
...
Stringencode(final Object self, final String string, final boolean component)
encode
if (string.isEmpty()) {
    return string;
final int len = string.length();
final StringBuilder sb = new StringBuilder();
for (int k = 0; k < len; k++) {
    final char C = string.charAt(k);
    if (isUnescaped(C, component)) {
...
Stringerror(final String string, final int index)
error
throw uriError("bad.uri", string, Integer.toString(index));
Stringescape(Object value)
escape
if (value == null) {
    return "NULL";
if (Number.class.isAssignableFrom(value.getClass())) {
    return value.toString();
if (Boolean.class.isAssignableFrom(value.getClass())) {
    return (boolean) value ? "1" : "0";
...
intgetArrayLength(NativeArray arr)
get Array Length
Object length = arr.getLength();
if (length instanceof Long) {
    return ((Long) length).intValue();
} else if (length instanceof Integer) {
    return (Integer) length;
} else {
    return Integer.parseInt(length.toString());
booleanisArrayType(final Object value)
is Array Type
return (value instanceof ScriptObjectMirror) && ((ScriptObjectMirror) value).isArray();
booleanisDateType(final ScriptObjectMirror value)
is Date Type
return "Date".equalsIgnoreCase(value.getClassName());
booleanisNashornScript(final String className)
is Nashorn Script
return className.startsWith("jdk.nashorn.internal.scripts.Script$");