當前位置: 首頁>>代碼示例>>Java>>正文


Java ScriptObjectMirror.isArray方法代碼示例

本文整理匯總了Java中jdk.nashorn.api.scripting.ScriptObjectMirror.isArray方法的典型用法代碼示例。如果您正苦於以下問題:Java ScriptObjectMirror.isArray方法的具體用法?Java ScriptObjectMirror.isArray怎麽用?Java ScriptObjectMirror.isArray使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在jdk.nashorn.api.scripting.ScriptObjectMirror的用法示例。


在下文中一共展示了ScriptObjectMirror.isArray方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: convert

import jdk.nashorn.api.scripting.ScriptObjectMirror; //導入方法依賴的package包/類
public static Object convert(Object original) {
	if (original == null) {
		return null;
	} else if (original instanceof String || original instanceof Integer || original instanceof Long || original instanceof Boolean || original instanceof Double) {
		return original;
	} else if (original instanceof ScriptObjectMirror) {
		ScriptObjectMirror jsOriginal = (ScriptObjectMirror)original;
		if (jsOriginal.isArray()) {
			List<Object> listResult = new ArrayList<Object>();
			Integer length = (Integer)jsOriginal.get("length");
			for (int i = 0; i < length; i++) {
				listResult.add(convert(jsOriginal.get("" + i)));
			}
			return listResult;
		} else if (jsOriginal.isFunction()) {
			// can't convert it...
			return null;
		}
		Map<String,Object> mapResult = new LinkedHashMap<String,Object>();
		for (Map.Entry<String,Object> entry: jsOriginal.entrySet()) {
			mapResult.put(entry.getKey(), convert(entry.getValue()));
		}
		return mapResult;
	}
	return original;
}
 
開發者ID:marrow16,項目名稱:Nasapi,代碼行數:27,代碼來源:ScriptObjectMirrors.java

示例2: logMessage

import jdk.nashorn.api.scripting.ScriptObjectMirror; //導入方法依賴的package包/類
private static String logMessage(Object value) {
    final int length = length(value);
    if (length < 0) {
        return String.valueOf(value);
    }

    if (length == 1) {
        @SuppressWarnings("unchecked")
        final Object first = ((Map<String, Object>) value).get("0");
        if (first instanceof ScriptObjectMirror) {
            final ScriptObjectMirror firstMirror = (ScriptObjectMirror) first;
            if (firstMirror.isArray()) {
                return logMessage(firstMirror, length(firstMirror));
            }
        }

        return String.valueOf(first);
    } else {
        return logMessage((ScriptObjectMirror) value, length);
    }
}
 
開發者ID:line,項目名稱:centraldogma,代碼行數:22,代碼來源:Polyfills.java

示例3: jsToNode

import jdk.nashorn.api.scripting.ScriptObjectMirror; //導入方法依賴的package包/類
private org.antology.db.Node jsToNode(Object object) throws Exception {
    if (object instanceof ScriptObjectMirror) {
        ScriptObjectMirror mirror = (ScriptObjectMirror) object;

        if (mirror.isArray()) {
            List<org.antology.db.Node> list = new LinkedList<>();
            for (int i = 0; i < mirror.size(); i++) {
                list.add(jsToNode(mirror.get(Integer.toString(i))));
            }
            return new Node(Schema.Type.LIST, list);
        } else {
            Map<String, org.antology.db.Node> struct = new HashMap<>();
            for (String key : mirror.getOwnKeys(false)) {
                java.lang.Object value = mirror.get(key);
                struct.put(key, jsToNode(value));
            }
            return new Node(Schema.Type.STRUCT, struct);
        }
    } else if (object instanceof String) {
        return new Node(Schema.Type.STRING, object);
    } else if (object instanceof Integer) {
        return new Node(Schema.Type.INTEGER, object);
    } else if (object instanceof Double) {
        return new Node(Schema.Type.FLOAT, object);
    } else if (object instanceof Boolean) {
        return new Node(Schema.Type.BOOLEAN, object);
    } else {
        throw new Exception("Unknown type " + object.getClass().getName());
    }
}
 
開發者ID:antology,項目名稱:a6y-server,代碼行數:31,代碼來源:Action.java

示例4: StringifyObject

import jdk.nashorn.api.scripting.ScriptObjectMirror; //導入方法依賴的package包/類
private static void StringifyObject(Object object, StringBuilder builder, boolean inObjectOrArray) {
	if (object == null) {
		builder.append("null");
	} else if (object instanceof String && inObjectOrArray) {
		builder.append("\"").append(((String) object).replaceAll("\"", "\\\"")).append("\"");
	} else if (object instanceof String) {
		builder.append(object);
	} else if (object instanceof Integer || object instanceof Long || object instanceof Boolean || object instanceof Double) {
		builder.append(object.toString());
	} else if (object instanceof ScriptObjectMirror) {
		ScriptObjectMirror scriptObject = (ScriptObjectMirror)object;
		if (scriptObject.isArray()) {
			builder.append("[");
			Integer length = (Integer) scriptObject.get("length");
			for (int i = 0; i < length; i++) {
				StringifyObject(scriptObject.get("" + i), builder, true);
			}
			builder.append("]");
		} else if (scriptObject.isFunction()) {
			builder.append("[function()]");
		} else {
			builder.append("{");
			boolean isFirst = true;
			for (Map.Entry<String, Object> entry : scriptObject.entrySet()) {
				builder.append(isFirst ? "" : ", ")
						.append("\"")
						.append(entry.getKey())
						.append("\": ");
				StringifyObject(entry.getValue(), builder, true);
				isFirst = false;
			}
			builder.append("}");
		}
	} else {
		builder.append(object.toString());
	}
}
 
開發者ID:marrow16,項目名稱:Nasapi,代碼行數:38,代碼來源:ScriptObjectMirrors.java

示例5: ScriptValue

import jdk.nashorn.api.scripting.ScriptObjectMirror; //導入方法依賴的package包/類
public ScriptValue(Object value, String source) {
    this.value = value;
    this.source = source;
    if (value == null) {
        type = Type.NULL;
    } else if (value instanceof DocumentContext) {
        type = Type.JSON;
    } else if (value instanceof Node) {
        type = Type.XML;
    } else if (value instanceof List) {
        type = Type.LIST;
    } else if (value instanceof Map) {
        if (value instanceof ScriptObjectMirror) {
            ScriptObjectMirror som = (ScriptObjectMirror) value;
            if (som.isArray()) {
                type = Type.JS_ARRAY;
            } else if (som.isFunction()) {
                type = Type.JS_FUNCTION;
            } else {
                type = Type.JS_OBJECT;
            }
        } else {
            type = Type.MAP;
        }
    } else if (value instanceof String) {
        type = Type.STRING;
    } else if (value instanceof byte[]) {
        type = Type.BYTE_ARRAY;
    } else if (value instanceof InputStream) {
        type = Type.INPUT_STREAM;
    } else if (Script.isPrimitive(value.getClass())) {
        type = Type.PRIMITIVE;
    } else if (value instanceof FeatureWrapper) {
        type = Type.FEATURE_WRAPPER;
    } else {
        type = Type.UNKNOWN;
    }
}
 
開發者ID:intuit,項目名稱:karate,代碼行數:39,代碼來源:ScriptValue.java

示例6: serialize

import jdk.nashorn.api.scripting.ScriptObjectMirror; //導入方法依賴的package包/類
@Override
public JsonElement serialize(ScriptObjectMirror src, java.lang.reflect.Type typeOfSrc, JsonSerializationContext context) {
    Gson gson = new Gson();
    
    if (src.isArray()) {
        return gson.toJsonTree(src.values());
    } else {
        return gson.toJsonTree(src);
    }
}
 
開發者ID:mcdcorp,項目名稱:opentest,代碼行數:11,代碼來源:ScriptObjectMirrorSerializer.java


注:本文中的jdk.nashorn.api.scripting.ScriptObjectMirror.isArray方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。