本文整理汇总了Java中org.mozilla.javascript.NativeArray.size方法的典型用法代码示例。如果您正苦于以下问题:Java NativeArray.size方法的具体用法?Java NativeArray.size怎么用?Java NativeArray.size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.mozilla.javascript.NativeArray
的用法示例。
在下文中一共展示了NativeArray.size方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getKeyEntries
import org.mozilla.javascript.NativeArray; //导入方法依赖的package包/类
@Nullable
private List<KeyEntry> getKeyEntries(Map.Entry<Object, Object> entry) {
if (!(entry.getValue() instanceof NativeArray)) {
return null;
}
NativeArray nativeArray = (NativeArray) entry.getValue();
if (nativeArray.isEmpty()) {
return null;
}
List<KeyEntry> keyList = new ArrayList<>();
final int size = nativeArray.size();
for (int i = 0; i < size; i++) {
NativeObject elem = (NativeObject) nativeArray.get(i);
keyList.add(new KeyEntry(
Context.toString(elem.get("text")),
(int) Context.toNumber(elem.get("keyCode")),
Context.toBoolean(elem.get("enabled")),
Context.toBoolean(elem.get("isFunKey"))
));
}
return keyList;
}
示例2: setRange
import org.mozilla.javascript.NativeArray; //导入方法依赖的package包/类
private void setRange(NativeArray a, int off)
{
if (off > length) {
throw ScriptRuntime.constructError("RangeError", "offset out of range");
}
if ((off + a.size()) > length) {
throw ScriptRuntime.constructError("RangeError", "offset + length out of range");
}
int pos = off;
for (Object val : a) {
js_set(pos, val);
pos++;
}
}
示例3: randomElement
import org.mozilla.javascript.NativeArray; //导入方法依赖的package包/类
@Override
public Object randomElement(NativeArray array) {
if (array.size() == 0) {
return null;
}
int i = random(array.size());
return array.get(i);
}
示例4: setStrings
import org.mozilla.javascript.NativeArray; //导入方法依赖的package包/类
/**
* Wraps {@link Configuration#setStrings(String, String...)}.
*
* @param ctx the JavaScript context (unused)
* @param thisObj the 'this' object of the caller
* @param args the arguments for the call
* @param func the function called (unused)
*
* @return this
*/
@JSFunction
public static Object setStrings(final Context ctx, final Scriptable thisObj, final Object[] args,
final Function func) {
final Object arg0 = args.length >= 1 ? args[0] : Undefined.instance;
final Object arg1 = args.length >= 2 ? args[1] : Undefined.instance;
if (args.length < 2) {
throw Utils.makeError(ctx, thisObj, LembosMessages.TWO_ARGS_EXPECTED);
} else if (!JavaScriptUtils.isDefined(arg0)) {
throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_REQUIRED);
} else if (!JavaScriptUtils.isDefined(arg1)) {
throw Utils.makeError(ctx, thisObj, LembosMessages.SECOND_ARG_REQUIRED);
} else if (!(arg1 instanceof NativeArray)) {
throw Utils.makeError(ctx, thisObj, LembosMessages.SECOND_ARG_MUST_BE_ARRAY);
}
final NativeArray jsArray = (NativeArray)args[1];
final String[] strings = new String[jsArray.size()];
for (int i = 0; i < jsArray.size(); i++) {
strings[i] = jsArray.get(i).toString();
}
((ConfigurationWrap)thisObj).conf.setStrings(args[0].toString(), strings);
return thisObj;
}
示例5: setAnArray
import org.mozilla.javascript.NativeArray; //导入方法依赖的package包/类
public void setAnArray(NativeArray array) {
for (int i = 0; i < array.size(); i++) {
MLog.d(TAG, "setArrayList -> " + array.get(i));
}
}
示例6: setOutput
import org.mozilla.javascript.NativeArray; //导入方法依赖的package包/类
/**
* Java wrapper for {@link DBOutputFormat#setOutput(org.apache.hadoop.mapreduce.Job, String, int)} and
* {@link DBOutputFormat#setOutput(org.apache.hadoop.mapreduce.Job, String, String...)}.
*
* @param ctx the JavaScript context
* @param thisObj the 'this' object
* @param args the function arguments
* @param func the function being called
*/
@JSStaticFunction
public static void setOutput(final Context ctx, final Scriptable thisObj, final Object[] args,
final Function func) {
final Object arg0 = args.length >= 1 ? args[0] : Undefined.instance;
final Object arg1 = args.length >= 2 ? args[1] : Undefined.instance;
final Object arg2 = args.length >= 3 ? args[2] : Undefined.instance;
if (args.length != 3) {
throw Utils.makeError(ctx, thisObj, LembosMessages.THREE_ARGS_EXPECTED);
} else if (!JavaScriptUtils.isDefined(arg0)) {
throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_REQUIRED);
} else if (!JavaScriptUtils.isDefined(arg1)) {
throw Utils.makeError(ctx, thisObj, LembosMessages.SECOND_ARG_REQUIRED);
} else if (!JavaScriptUtils.isDefined(arg0)) {
throw Utils.makeError(ctx, thisObj, LembosMessages.THIRD_ARG_REQUIRED);
} else if (!(arg0 instanceof JobWrap)) {
throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_MUST_BE_JOB);
} else if (!(arg2 instanceof NativeArray) && !(arg2 instanceof Number)) {
throw Utils.makeError(ctx, thisObj, LembosMessages.THIRD_ARG_MUST_BE_ARR_OR_NUM);
}
try {
if (arg2 instanceof NativeArray) {
final NativeArray jsFieldNames = (NativeArray)arg2;
final String[] fieldNames = new String[jsFieldNames.size()];
for (int i = 0; i < jsFieldNames.size(); i++) {
fieldNames[i] = jsFieldNames.get(i).toString();
}
DBOutputFormat.setOutput(((JobWrap)arg0).getJob(), arg1.toString(), fieldNames);
} else {
DBOutputFormat.setOutput(((JobWrap)arg0).getJob(), arg1.toString(),
JavaScriptUtils.fromNumber(arg2).intValue());
}
} catch (IOException e) {
throw Utils.makeError(ctx, thisObj, e.getMessage());
}
}
示例7: setInputPaths
import org.mozilla.javascript.NativeArray; //导入方法依赖的package包/类
/**
* Java wrapper for {@link FileInputFormat#setInputPaths(Job, Path...)} and
* {@link FileInputFormat#setInputPaths(Job, String)}.
*
* @param clazz the class to invoke the method of
* @param ctx the JavaScript context
* @param thisObj the 'this' object
* @param args the function arguments
*/
public static void setInputPaths(final Class<?> clazz, final Context ctx, final Scriptable thisObj,
final Object[] args) {
validateClass(clazz, ctx, thisObj);
final Object arg0 = args.length >= 1 ? args[0] : Undefined.instance;
final Object arg1 = args.length >= 2 ? args[1] : Undefined.instance;
if (args.length < 2) {
throw Utils.makeError(ctx, thisObj, LembosMessages.TWO_ARGS_EXPECTED);
} else if (!JavaScriptUtils.isDefined(arg0)) {
throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_REQUIRED);
} else if (!JavaScriptUtils.isDefined(arg1)) {
throw Utils.makeError(ctx, thisObj, LembosMessages.SECOND_ARG_REQUIRED);
} else if (!(arg0 instanceof JobWrap)) {
throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_MUST_BE_JOB);
}
final Job job = ((JobWrap)arg0).getJob();
Class<?>[] methodTypes;
Object[] methodArgs;
if (arg1 instanceof NativeArray) {
final NativeArray jsInputPaths = (NativeArray)arg1;
final Path[] inputPaths = new Path[jsInputPaths.size()];
for (int i = 0; i < jsInputPaths.size(); i++) {
inputPaths[i] = new Path(URI.create(jsInputPaths.get(i).toString()));
}
methodTypes = new Class<?>[] {
Job.class, Path[].class
};
methodArgs = new Object[] {
job, inputPaths
};
} else {
methodTypes = new Class<?>[] {
Job.class, String.class
};
methodArgs = new Object[] {
job, arg1.toString()
};
}
try {
ReflectionUtils.invokeStatic(clazz, "setInputPaths", methodTypes, methodArgs);
} catch (Exception e) {
e.printStackTrace();
throw Utils.makeError(ctx, thisObj, e.getMessage());
}
}