本文整理了Java中org.mozilla.javascript.Context.toNumber()
方法的一些代码示例,展示了Context.toNumber()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Context.toNumber()
方法的具体详情如下:
包路径:org.mozilla.javascript.Context
类名称:Context
方法名:toNumber
[英]Convert the value to a JavaScript Number value.
Returns a Java double for the JavaScript Number.
See ECMA 9.3.
[中]将该值转换为JavaScript数字值。
返回JavaScript编号的Java双精度值。
见ECMA 9.3。
代码示例来源:origin: org.freemarker/freemarker
public Number getAsNumber() {
return Double.valueOf(Context.toNumber(scriptable));
}
代码示例来源:origin: apache/incubator-druid
@Override
public double apply(Object[] args)
{
// ideally we need a close() function to discard the context once it is not used anymore
Context cx = Context.getCurrentContext();
if (cx == null) {
cx = contextFactory.enterContext();
}
return Context.toNumber(fn.call(cx, scope, scope, args));
}
};
代码示例来源:origin: pentaho/pentaho-kettle
public static Long jsToInteger( Object value, Class<?> clazz ) {
if ( Number.class.isAssignableFrom( clazz ) ) {
return ( (Number) value ).longValue();
} else {
String classType = clazz.getName();
if ( classType.equalsIgnoreCase( "java.lang.String" ) ) {
return ( new Long( (String) value ) );
} else if ( classType.equalsIgnoreCase( "org.mozilla.javascript.Undefined" ) ) {
return null;
} else if ( classType.equalsIgnoreCase( "org.mozilla.javascript.NativeNumber" ) ) {
Number nb = Context.toNumber( value );
return nb.longValue();
} else if ( classType.equalsIgnoreCase( "org.mozilla.javascript.NativeJavaObject" ) ) {
// Is it a Value?
//
try {
Value v = (Value) Context.jsToJava( value, Value.class );
return v.getInteger();
} catch ( Exception e2 ) {
String string = Context.toString( value );
return Long.parseLong( Const.trim( string ) );
}
} else {
return Long.parseLong( value.toString() );
}
}
}
代码示例来源:origin: pentaho/pentaho-kettle
public static Number jsToNumber( Object value, String classType ) {
if ( classType.equalsIgnoreCase( "org.mozilla.javascript.Undefined" ) ) {
return null;
} else if ( classType.equalsIgnoreCase( "org.mozilla.javascript.NativeJavaObject" ) ) {
try {
// Is it a java Value class ?
Value v = (Value) Context.jsToJava( value, Value.class );
return v.getNumber();
} catch ( Exception e ) {
String string = Context.toString( value );
return Double.parseDouble( Const.trim( string ) );
}
} else if ( classType.equalsIgnoreCase( "org.mozilla.javascript.NativeNumber" ) ) {
Number nb = Context.toNumber( value );
return nb.doubleValue();
} else {
Number nb = (Number) value;
return nb.doubleValue();
}
}
代码示例来源:origin: pentaho/pentaho-kettle
return null;
} else if ( classType.equalsIgnoreCase( "org.mozilla.javascript.NativeNumber" ) ) {
Number nb = Context.toNumber( value );
return new BigDecimal( nb.doubleValue() );
} else if ( classType.equalsIgnoreCase( "org.mozilla.javascript.NativeJavaObject" ) ) {
代码示例来源:origin: pentaho/pentaho-kettle
int iValue = (int) Context.toNumber( ArgList[2] );
Calendar cal = Calendar.getInstance();
cal.setTime( dIn );
代码示例来源:origin: pentaho/pentaho-kettle
public static Object abs( Context actualContext, Scriptable actualObject, Object[] ArgList,
Function FunctionContext ) {
if ( ArgList.length == 1 ) {
try {
if ( isNull( ArgList[0] ) ) {
return new Double( Double.NaN );
} else if ( isUndefined( ArgList[0] ) ) {
return Context.getUndefinedValue();
} else {
return new Double( Math.abs( Context.toNumber( ArgList[0] ) ) );
}
} catch ( Exception e ) {
return null;
}
} else {
throw Context.reportRuntimeError( "The function call abs requires 1 argument." );
}
}
代码示例来源:origin: pentaho/pentaho-kettle
public static Object[] createRowCopy( Context actualContext, Scriptable actualObject, Object[] ArgList,
Function FunctionContext ) {
if ( ArgList.length == 1 ) {
try {
int newSize = (int) Math.round( Context.toNumber( ArgList[0] ) );
Object scmO = actualObject.get( "row", actualObject );
Object[] row = (Object[]) Context.jsToJava( scmO, ( new Object[] {} ).getClass() );
return RowDataUtil.createResizedCopy( row, newSize );
} catch ( Exception e ) {
throw Context.reportRuntimeError( "Unable to create a row copy: " + Const.CR + e.toString() );
}
} else {
throw Context
.reportRuntimeError( "The function call createRowCopy requires a single arguments : the new size of the row" );
}
}
代码示例来源:origin: pentaho/pentaho-kettle
public static Object floor( Context actualContext, Scriptable actualObject, Object[] ArgList,
Function FunctionContext ) {
if ( ArgList.length == 1 ) {
try {
if ( isNull( ArgList[0] ) ) {
return new Double( Double.NaN );
} else if ( isUndefined( ArgList[0] ) ) {
return Context.getUndefinedValue();
} else {
return new Double( Math.floor( Context.toNumber( ArgList[0] ) ) );
}
} catch ( Exception e ) {
return null;
// throw Context.reportRuntimeError(e.toString());
}
} else {
throw Context.reportRuntimeError( "The function call floor requires 1 argument." );
}
}
代码示例来源:origin: pentaho/pentaho-kettle
public static Object ceil( Context actualContext, Scriptable actualObject, Object[] ArgList,
Function FunctionContext ) {
if ( ArgList.length == 1 ) {
try {
if ( isNull( ArgList[0] ) ) {
return Double.NaN;
} else if ( isUndefined( ArgList[0] ) ) {
return Context.getUndefinedValue();
} else {
return Math.ceil( Context.toNumber( ArgList[ 0 ] ) );
}
} catch ( Exception e ) {
return null;
}
} else {
throw Context.reportRuntimeError( "The function call ceil requires 1 argument." );
}
}
代码示例来源:origin: pentaho/pentaho-kettle
public static int indexOf( Context actualContext, Scriptable actualObject, Object[] ArgList,
Function FunctionContext ) {
int returnIndex = -1;
if ( ArgList.length == 2 || ArgList.length == 3 ) {
if ( !isNull( ArgList ) && !isUndefined( ArgList ) ) {
String string = Context.toString( ArgList[0] );
String subString = Context.toString( ArgList[1] );
int fromIndex = 0;
if ( ArgList.length == 3 ) {
fromIndex = (int) Math.round( Context.toNumber( ArgList[2] ) );
}
returnIndex = string.indexOf( subString, fromIndex );
}
} else {
throw Context.reportRuntimeError( "The function call indexOf requires 2 or 3 arguments" );
}
return returnIndex;
}
代码示例来源:origin: pentaho/pentaho-kettle
} else {
if ( classType.equalsIgnoreCase( "org.mozilla.javascript.NativeDate" ) ) {
dbl = Context.toNumber( value );
} else if ( classType.equalsIgnoreCase( "org.mozilla.javascript.NativeJavaObject" )
|| classType.equalsIgnoreCase( "java.util.Date" ) ) {
代码示例来源:origin: pentaho/pentaho-kettle
public static Object isNum( Context actualContext, Scriptable actualObject, Object[] ArgList,
Function FunctionContext ) {
if ( ArgList.length == 1 ) {
try {
if ( isNull( ArgList[0] ) ) {
return null;
} else if ( isUndefined( ArgList[0] ) ) {
return Context.getUndefinedValue();
}
double sArg1 = Context.toNumber( ArgList[0] );
if ( Double.isNaN( sArg1 ) ) {
return Boolean.FALSE;
} else {
return Boolean.TRUE;
}
} catch ( Exception e ) {
return Boolean.FALSE;
}
} else {
throw Context.reportRuntimeError( "The function call isNum requires 1 argument." );
}
}
代码示例来源:origin: pentaho/pentaho-kettle
int from = (int) Math.round( Context.toNumber( ArgList[1] ) );
sRC = sRC.substring( from );
} catch ( Exception e ) {
int from = (int) Math.round( Context.toNumber( ArgList[1] ) );
int len = (int) Math.round( Context.toNumber( ArgList[2] ) );
代码示例来源:origin: pentaho/pentaho-kettle
public static String fillString( Context actualContext, Scriptable actualObject, Object[] ArgList,
Function FunctionContext ) {
if ( ArgList.length == 2 ) {
try {
if ( isNull( ArgList, new int[] { 0, 1 } ) ) {
return null;
} else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {
return (String) Context.getUndefinedValue();
}
String fillChar = Context.toString( ArgList[0] );
int count = (int) Context.toNumber( ArgList[1] );
if ( fillChar.length() != 1 ) {
throw Context.reportRuntimeError( "Please provide a valid Char to the fillString" );
} else {
char[] chars = new char[count];
while ( count > 0 ) {
chars[--count] = fillChar.charAt( 0 );
}
return new String( chars );
}
} catch ( Exception e ) {
throw Context.reportRuntimeError( e.toString() );
}
} else {
throw Context.reportRuntimeError( "The function call fillString requires 2 arguments." );
}
}
代码示例来源:origin: pentaho/pentaho-kettle
return (String) Context.getUndefinedValue();
double sArg1 = Context.toNumber( ArgList[0] );
if ( Double.isNaN( sArg1 ) ) {
throw Context.reportRuntimeError( "The first Argument must be a Number." );
return (String) Context.getUndefinedValue();
double sArg1 = Context.toNumber( ArgList[0] );
if ( Double.isNaN( sArg1 ) ) {
throw Context.reportRuntimeError( "The first Argument must be a Number." );
return (String) Context.getUndefinedValue();
double sArg1 = Context.toNumber( ArgList[0] );
if ( Double.isNaN( sArg1 ) ) {
throw Context.reportRuntimeError( "The first Argument must be a Number." );
代码示例来源:origin: pentaho/pentaho-kettle
public static String lpad( Context actualContext, Scriptable actualObject, Object[] ArgList,
Function FunctionContext ) {
// (String valueToPad, String filler, int size) {
try {
if ( ArgList.length == 3 ) {
if ( isNull( ArgList, new int[] { 0, 1, 2 } ) ) {
return null;
} else if ( isUndefined( ArgList, new int[] { 0, 1, 2 } ) ) {
return (String) Context.getUndefinedValue();
}
String valueToPad = Context.toString( ArgList[0] );
String filler = Context.toString( ArgList[1] );
int size = (int) Context.toNumber( ArgList[2] );
while ( valueToPad.length() < size ) {
valueToPad = filler + valueToPad;
}
return valueToPad;
}
} catch ( Exception e ) {
throw Context.reportRuntimeError( "The function call lpad requires 3 arguments." );
}
return null;
}
代码示例来源:origin: pentaho/pentaho-kettle
public static String rpad( Context actualContext, Scriptable actualObject, Object[] ArgList,
Function FunctionContext ) {
try {
if ( ArgList.length == 3 ) {
if ( isNull( ArgList, new int[] { 0, 1, 2 } ) ) {
return null;
} else if ( isUndefined( ArgList, new int[] { 0, 1, 2 } ) ) {
return (String) Context.getUndefinedValue();
}
String valueToPad = Context.toString( ArgList[0] );
String filler = Context.toString( ArgList[1] );
int size = (int) Context.toNumber( ArgList[2] );
while ( valueToPad.length() < size ) {
valueToPad = valueToPad + filler;
}
return valueToPad;
}
} catch ( Exception e ) {
throw Context.reportRuntimeError( "The function call rpad requires 3 arguments." );
}
return null;
}
代码示例来源:origin: pentaho/pentaho-kettle
} else {
if ( classname.equalsIgnoreCase( "org.mozilla.javascript.NativeDate" ) ) {
dbl = Context.toNumber( result );
} else if ( classname.equalsIgnoreCase( "org.mozilla.javascript.NativeJavaObject" ) ) {
代码示例来源:origin: pentaho/pentaho-kettle
iTranStat = (int) Context.toNumber( data.scope.get( "trans_Status", data.scope ) );
} else {
iTranStat = CONTINUE_TRANSFORMATION;
内容来源于网络,如有侵权,请联系作者删除!