List of usage examples for com.google.gwt.json.client JSONValue isArray
public JSONArray isArray()
From source file:org.cruxframework.crux.core.client.utils.JsUtils.java
License:Apache License
/** * Extract the associated native javascript object from the given json object * @param jsonValue//from w ww . j a v a 2s .c om * @return */ public static JavaScriptObject fromJSONValue(JSONValue jsonValue) { if (jsonValue.isNull() != null) { return null; } JSONArray jsonArray = jsonValue.isArray(); if (jsonArray != null) { return jsonArray.getJavaScriptObject(); } return jsonValue.isObject().getJavaScriptObject(); }
From source file:org.dashbuilder.displayer.client.json.DataSetLookupJSONMarshaller.java
License:Apache License
public DataSetLookup fromJson(JSONObject json) { if (json == null) return null; DataSetLookup dataSetLookup = new DataSetLookup(); dataSetLookup.setDataSetUUID(json.get(UUID) != null ? json.get(UUID).isString().stringValue() : null); dataSetLookup.setNumberOfRows(/* w ww. j a va 2 s. c o m*/ json.get(ROWCOUNT) != null ? Integer.parseInt(json.get(ROWCOUNT).isString().stringValue(), 10) : 0); dataSetLookup.setNumberOfRows( json.get(ROWOFFSET) != null ? Integer.parseInt(json.get(ROWOFFSET).isString().stringValue(), 10) : 0); List<DataSetOp> dataSetOpList = dataSetLookup.getOperationList(); Collection c = null; JSONValue array = json.get(FILTEROPS); if ((c = parseFilterOperations(array != null ? array.isArray() : null)) != null) dataSetOpList.addAll(c); if ((c = parseGroupOperations((array = json.get(GROUPOPS)) != null ? array.isArray() : null)) != null) dataSetOpList.addAll(c); if ((c = parseSortOperations((array = json.get(SORTOPS)) != null ? array.isArray() : null)) != null) dataSetOpList.addAll(c); return dataSetLookup; }
From source file:org.dashbuilder.displayer.client.json.DataSetLookupJSONMarshaller.java
License:Apache License
private ColumnFilter parseColumnFilter(JSONObject columnFilterJson) { if (columnFilterJson == null) return null; String columnId = null;//from w w w .j a v a 2 s . co m String functionType = null; JSONValue value = columnFilterJson.get(COLUMNID); if (checkNotNull(value, false, "the column id field of a column filter cannot be null.")) { columnId = value.isString() != null ? value.isString().stringValue() : null; } value = columnFilterJson.get(FUNCTION_TYPE); if (checkNotNull(value, false, "the function type field of a column filter cannot be null.")) { functionType = value.isString() != null ? value.isString().stringValue() : null; } value = columnFilterJson.get(FUNCTION_TERMS); if (isCoreFilter(functionType)) { CoreFunctionFilter cff = new CoreFunctionFilter(); cff.setColumnId(columnId); cff.setType(CoreFunctionType.getByName(functionType)); if (checkNotNull(value, false, "the parameters of a core function filter cannot be null.")) { cff.setParameters(parseCoreFunctionParameters(value.isArray()).toArray(new Comparable[] {})); } return cff; } else if (isLogicalFilter(functionType)) { LogicalExprFilter lef = new LogicalExprFilter(); lef.setColumnId(columnId); lef.setLogicalOperator(LogicalExprType.getByName(functionType)); if (checkNotNull(value, false, "the parameters of a logical expression filter cannot be null.")) { // Logical expression terms are an an array of column filters lef.setLogicalTerms(parseColumnFilters(value.isArray())); } return lef; } else throw new RuntimeException("Wrong type of column filter has been specified."); }
From source file:org.dashbuilder.displayer.client.json.DataSetLookupJSONMarshaller.java
License:Apache License
private DataSetGroup parseDataSetGroup(JSONObject dataSetGroupJson) { if (dataSetGroupJson == null) return null; DataSetGroup dataSetGroup = new DataSetGroup(); dataSetGroup.setColumnGroup(null);/* w ww . j av a 2 s. c o m*/ JSONValue value = dataSetGroupJson.get(COLUMNGROUP); if (value != null) dataSetGroup.setColumnGroup(parseColumnGroup(value.isObject())); List<GroupFunction> groupFunctions = parseGroupFunctions( (value = dataSetGroupJson.get(GROUPFUNCTIONS)) != null ? value.isArray() : null); if (groupFunctions != null) dataSetGroup.getGroupFunctions().addAll(groupFunctions); dataSetGroup.setSelectedIntervalNames(null); value = dataSetGroupJson.get(SELECTEDINTERVALS); if (value != null) dataSetGroup.setSelectedIntervalNames(parseSelectedIntervals(value.isArray())); dataSetGroup.setJoin(false); value = dataSetGroupJson.get(JOIN); if (value != null) dataSetGroup.setJoin(Boolean.valueOf(value.isString().stringValue())); return dataSetGroup; }
From source file:org.drools.workbench.screens.scenariosimulation.client.collectioneditor.CollectionPresenter.java
License:Apache License
protected void populateList(JSONValue jsonValue) { final JSONArray array = jsonValue.isArray(); for (int i = 0; i < array.size(); i++) { final JSONObject jsonObject = array.get(i).isObject(); final Map<String, String> propertiesValues = getSimplePropertiesMap(jsonObject); final Map<String, Map<String, String>> expandablePropertiesValues = getExpandablePropertiesValues( jsonObject);//from w w w .j a va 2s . c om addListItem(propertiesValues, expandablePropertiesValues); } }
From source file:org.drools.workbench.screens.scenariosimulation.client.renderers.ScenarioGridColumnRenderer.java
License:Apache License
protected String getCollectionString(String jsonString, boolean isList) { try {/*w w w. j a v a2 s .co m*/ int size = -1; String toFormat = isList ? "List(%s)" : "Map(%s)"; JSONValue jsonValue = JSONParser.parseStrict(jsonString); if (isList) { size = jsonValue.isArray().size(); } else { size = jsonValue.isObject().keySet().size(); } return toFormat.replace("%s", String.valueOf(size)); } catch (Exception e) { return jsonString; } }
From source file:org.eclipse.che.api.languageserver.util.EitherUtil.java
License:Open Source License
private static boolean matches(JSONValue element, JsonDecision decision) { if (decision == JsonDecision.LIST) { return element.isArray() != null; }//from ww w .j av a2s. co m if (decision == JsonDecision.BOOLEAN) { return element.isBoolean() != null; } if (decision == JsonDecision.NUMBER) { return element.isNumber() != null; } if (decision == JsonDecision.STRING) { return element.isString() != null; } return element.isObject() != null; }
From source file:org.eclipse.che.ide.ext.java.jdt.core.util.JSONUtil.java
License:Open Source License
/** * @param json/*ww w.j a v a2 s .c o m*/ * @return */ public static long[] parseJsonAsLongArray(JSONValue json) { JSONValue value = parse(json); if (value.isArray() == null) throw new IllegalArgumentException("'json' parameter must represent a JSON array"); return jsonArrayToLongArray(value.isArray()); }
From source file:org.eclipse.che.ide.ext.java.jdt.core.util.JSONUtil.java
License:Open Source License
public static byte[] parseArrayToByteArray(JSONValue value) { value = parse(value);//from w w w . j a v a 2 s.com if (value.isArray() == null) throw new IllegalArgumentException("'json' parameter must represent a JSON array"); return jsonArrayToByteArray(value.isArray()); }
From source file:org.eclipse.che.ide.ext.java.jdt.core.util.JSONUtil.java
License:Open Source License
public static char[] parseArrayToCharArray(JSONValue json) { JSONValue value = parse(json); if (value.isArray() == null) throw new IllegalArgumentException("'json' parameter must represent a JSON array"); return jsonArrayToCharArray(value.isArray()); }