org.json.simple.JSONArray#addAll ( )源码实例Demo

下面列出了org.json.simple.JSONArray#addAll ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Indra   文件: JSONUtil.java
private static JSONObject toJSONObject(Map<String, Object> map) {
    JSONObject object = new JSONObject();

    for (String key : map.keySet()) {
        Object content = map.get(key);
        if (content instanceof Collection) {
            JSONArray array = new JSONArray();
            array.addAll((Collection<?>) content);
            object.put(key, array);
        } else if (content instanceof Map) {
            object.put(key, toJSONObject((Map<String, Object>) content));
        } else {
            object.put(key, content);
        }
    }

    return object;
}
 
public static void loadDefaultTheme(JSONObject obj) {
    try {
        appSett.putAll(System.getProperties());
        Object Theme = appSett.get(RDS.TestSet.THEME);
        if (Theme == null || Theme.toString().isEmpty()) {
            Theme = getFirstTheme();
        }
        obj.put(RDS.TestSet.THEME, Theme.toString());
        if (appSett.get(RDS.TestSet.THEMES) != null) {
            String[] themes = appSett.get(RDS.TestSet.THEMES).toString().split(",");
            JSONArray jsthemes = new JSONArray();
            jsthemes.addAll(Arrays.asList(themes));
            obj.put(RDS.TestSet.THEMES, jsthemes);
        }
    } catch (Exception ex) {
        Logger.getLogger(ReportUtils.class.getName()).log(Level.WARNING, null, ex);
    }
}
 
源代码3 项目: jdbc-cb   文件: JDBCTestUtils.java
@SuppressWarnings("unchecked")
public static JSONArray sortJsonArray(JSONArray array) {
   	if(array.size() == 0){
   		return array;
   	}
       ArrayList<JSONObject> jsons = new ArrayList<JSONObject>();
       for (int i = 0; i < array.size(); i++) {
           jsons.add((JSONObject)array.get(i));
       }
       for(Object field:((JSONObject)array.get(0)).keySet()){
       	final Object field_val = field;
        Collections.sort(jsons, new Comparator<JSONObject>() {
        	@Override
            public int compare(JSONObject lhs, JSONObject rhs) {
                String lid = (String) lhs.get(field_val);
                String rid = (String) rhs.get(field_val);
                // Here you could parse string id to integer and then compare.
                return lid.compareTo(rid);
            }
       
       });}
       JSONArray returnValue = new JSONArray();
       returnValue.addAll(jsons);
       return returnValue;
   }
 
源代码4 项目: sqoop-on-spark   文件: SqoopIDFUtils.java
@SuppressWarnings("unchecked")
public static String toCSVList(Object[] list, Column column) {
  List<Object> elementList = new ArrayList<Object>();
  for (int n = 0; n < list.length; n++) {
    Column listType = ((AbstractComplexListType) column).getListType();
    // 2 level nesting supported
    if (isColumnListType(listType)) {
      Object[] listElements = (Object[]) list[n];
      JSONArray subArray = new JSONArray();
      for (int i = 0; i < listElements.length; i++) {
        subArray.add(listElements[i]);
      }
      elementList.add(subArray);
    } else {
      elementList.add(list[n]);
    }
  }
  JSONArray array = new JSONArray();
  array.addAll(elementList);
  return encloseWithQuotes(array.toJSONString());
}
 
源代码5 项目: Path-of-Leveling   文件: RecipeMerger.java
private JSONArray getAllZones(JSONArray acts) {
    JSONArray allZones = new JSONArray();
    for (JSONObject act : (Iterable<JSONObject>) acts) {
        JSONArray zonesInAct = (JSONArray) act.get("zones");
        allZones.addAll(zonesInAct);
    }
    return allZones;
}
 
源代码6 项目: TomboloDigitalConnector   文件: TimeseriesField.java
@Override
public JSONObject jsonValueForSubject(Subject subject, Boolean timeStamp) throws IncomputableFieldException {
    List<TimedValue> timedValues = TimedValueUtils.getBySubjectAndAttribute(subject, getAttribute());
    if (timedValues.isEmpty()) {
        throw new IncomputableFieldException(String.format("No TimedValue found for attribute %s", getAttribute().getLabel()));
    }
    JSONArray arr = new JSONArray();
    arr.addAll(timedValues.stream().map(timedValue -> {
        JSONObject pair = new JSONObject();
        pair.put("timestamp", timedValue.getId().getTimestamp().format(TimedValueId.DATE_TIME_FORMATTER));
        pair.put("value", timedValue.getValue());
        return pair;
        }).collect(Collectors.toList()));
    return withinMetadata(arr);
}
 
源代码7 项目: UltimateChat   文件: UltimateFancy.java
/**
 * Root text to show on chat, but in first position.
 *
 * @param text
 * @return instance of same {@link UltimateFancy}.
 */
public UltimateFancy textAtStart(String text) {
    JSONArray jarray = new JSONArray();
    jarray.addAll(parseColors(text));
    jarray.addAll(getStoredElements());
    this.constructor = jarray;
    return this;
}
 
源代码8 项目: UltimateChat   文件: UltimateFancy.java
public UltimateFancy appendAtFirst(JSONObject json) {
    JSONArray jarray = new JSONArray();
    jarray.add(json);
    jarray.addAll(getStoredElements());
    this.constructor = jarray;
    return this;
}
 
源代码9 项目: RedProtect   文件: UltimateFancy.java
/**
 * Root text to show on chat, but in first position.
 *
 * @param text
 * @return instance of same {@link UltimateFancy}.
 */
public UltimateFancy textAtStart(String text) {
    JSONArray jarray = new JSONArray();
    jarray.addAll(parseColors(text));
    jarray.addAll(getStoredElements());
    this.constructor = jarray;
    return this;
}
 
源代码10 项目: RedProtect   文件: UltimateFancy.java
public UltimateFancy appendAtFirst(JSONObject json) {
    JSONArray jarray = new JSONArray();
    jarray.add(json);
    jarray.addAll(getStoredElements());
    this.constructor = jarray;
    return this;
}
 
/**
 * Removes the active tokens that are cached on the API Gateway
 * @param activeTokens - The active access tokens to be removed from the gateway cache.
 */
public void invalidateCachedTokens(Set<String> activeTokens) {

    JSONArray tokenArray = new JSONArray();
    tokenArray.addAll(activeTokens);
    Object[] objectData = new Object[]{APIConstants.GATEWAY_KEY_CACHE_NAME, tokenArray.toJSONString()};
    Event event = new Event(APIConstants.CACHE_INVALIDATION_STREAM_ID, System.currentTimeMillis(),
            null, null, objectData);
    APIUtil.publishEventToEventHub(null, event);
}
 
/**
 * Removes given usernames that is cached on the API Gateway
 *
 * @param username_list - The list of usernames to be removed from the gateway cache.
 */
public void invalidateCachedUsernames(String[] username_list) {

    JSONArray userArray = new JSONArray();
    userArray.addAll(Arrays.asList(username_list));
    Object[] objectData = new Object[]{APIConstants.GATEWAY_USERNAME_CACHE_NAME, userArray.toJSONString()};
    Event event = new Event(APIConstants.CACHE_INVALIDATION_STREAM_ID, System.currentTimeMillis(),
            null, null, objectData);
    APIUtil.publishEventToEventHub(null, event);
}
 
源代码13 项目: sqoop-on-spark   文件: SchemaSerialization.java
@SuppressWarnings("unchecked")
private static JSONObject extractColumn(Column column) {
  JSONObject ret = new JSONObject();

  ret.put(NAME, column.getName());
  ret.put(NULLABLE, column.isNullable());
  ret.put(TYPE, column.getType().name());

  switch (column.getType()) {
  case MAP:
    JSONObject map = new JSONObject();
    ret.put(MAP, map);
    map.put(KEY, extractColumn(((Map) column).getKey()));
    map.put(VALUE, extractColumn(((Map) column).getValue()));
    break;
  case ENUM:
    JSONObject enumList = new JSONObject();
    ret.put(LIST, enumList);
    JSONArray optionsArray = new JSONArray();
    optionsArray.addAll(((Enum)column).getOptions());
    enumList.put(ENUM_OPTIONS, optionsArray);
    break;
  case SET:
    JSONObject set = new JSONObject();
    ret.put(LIST, set);
    set.put(LIST_TYPE, extractColumn(((AbstractComplexListType) column).getListType()));
    break;
  case ARRAY:
    JSONObject arrayList = new JSONObject();
    ret.put(LIST, arrayList);
    arrayList.put(SIZE, ((Array) column).getSize());
    arrayList.put(LIST_TYPE, extractColumn(((Array) column).getListType()));
    break;
  case BINARY:
  case TEXT:
    ret.put(CHAR_SIZE, ((AbstractString) column).getCharSize());
    break;
  case DATE_TIME:
    ret.put(FRACTION, ((DateTime) column).hasFraction());
    ret.put(TIMEZONE, ((DateTime) column).hasTimezone());
    break;
  case DECIMAL:
    ret.put(PRECISION, ((Decimal) column).getPrecision());
    ret.put(SCALE, ((Decimal) column).getScale());
    break;
  case FIXED_POINT:
    ret.put(BYTE_SIZE, ((FixedPoint) column).getByteSize());
    ret.put(SIGNED, ((FixedPoint) column).isSigned());
    break;
  case FLOATING_POINT:
    ret.put(BYTE_SIZE, ((FloatingPoint) column).getByteSize());
    break;
  case TIME:
    ret.put(FRACTION, ((Time) column).hasFraction());
    break;
  case UNKNOWN:
    ret.put(JDBC_TYPE, ((Unknown) column).getJdbcType());
    break;
  case DATE:
  case BIT:
    break;
  default:
    // TODO(jarcec): Throw an exception of unsupported type?
  }

  return ret;
}
 
源代码14 项目: io   文件: UserDataListTest.java
/**
 * UserDataの一覧でDouble配列型プロパティにnullを含むデータを取得できること.
 */
@SuppressWarnings("unchecked")
@Test
public final void UserDataの一覧でDouble配列型プロパティにnullを含むデータを取得できること() {
    String propName = "arrayDoubleTypeProperty";
    String userDataId = "userdata001";
    // リクエスト実行
    try {
        // Edm.Double配列のプロパティを作成
        PropertyUtils.create(AbstractCase.BEARER_MASTER_TOKEN, cellName, boxName, colName, entityTypeName,
                propName,
                EdmSimpleType.DOUBLE.getFullyQualifiedTypeName(),
                true, null, "List", false, null, HttpStatus.SC_CREATED);
        // リクエストボディを設定
        JSONObject body = new JSONObject();
        JSONArray arrayBody = new JSONArray();
        arrayBody.addAll(Arrays.asList(new Double[] {1.1, null, -1.2 }));
        body.put("__id", userDataId);
        body.put(propName, arrayBody);
        // ユーザデータ作成
        TResponse respons = createUserData(body, HttpStatus.SC_CREATED);

        Map<String, String> etagList = new HashMap<String, String>();
        etagList.put("userdata001", respons.getHeader(HttpHeaders.ETAG));

        // ユーザデータの一覧取得
        TResponse response = Http.request("box/odatacol/list.txt")
                .with("cell", cellName)
                .with("box", boxName)
                .with("collection", colName)
                .with("entityType", entityTypeName)
                .with("query", "")
                .with("accept", MediaType.APPLICATION_JSON)
                .with("token", DcCoreConfig.getMasterToken())
                .returns()
                .statusCode(HttpStatus.SC_OK)
                .debug();

        Map<String, String> uri = new HashMap<String, String>();
        uri.put(userDataId, UrlUtils.userData(cellName, boxName, colName, entityTypeName
                + "('" + userDataId + "')"));

        // プロパティ
        Map<String, Map<String, Object>> additional = new HashMap<String, Map<String, Object>>();
        Map<String, Object> additionalprop = new HashMap<String, Object>();
        additional.put(userDataId, additionalprop);
        additionalprop.put("__id", userDataId);
        additionalprop.put(propName, arrayBody);

        String nameSpace = getNameSpace(entityTypeName);
        ODataCommon
                .checkResponseBodyList(response.bodyAsJson(), uri, nameSpace, additional, "__id", null, etagList);

    } finally {
        // ユーザデータ削除
        deleteUserData(userDataId);
        // プロパティ削除
        PropertyUtils.delete(AbstractCase.BEARER_MASTER_TOKEN, cellName, boxName, colName, entityTypeName,
                propName, -1);
    }
}
 
源代码15 项目: io   文件: UserDataListTest.java
/**
 * UserDataの一覧でInt32配列型プロパティにnullを含むデータを取得できること.
 */
@SuppressWarnings("unchecked")
@Test
public final void UserDataの一覧でInt32配列型プロパティにnullを含むデータを取得できること() {
    String propName = "arrayIntTypeProperty";
    String userDataId = "userdata001";
    // リクエスト実行
    try {
        // Edm.Double配列のプロパティを作成
        PropertyUtils.create(AbstractCase.BEARER_MASTER_TOKEN, cellName, boxName, colName, entityTypeName,
                propName,
                EdmSimpleType.INT32.getFullyQualifiedTypeName(),
                true, null, "List", false, null, HttpStatus.SC_CREATED);
        // リクエストボディを設定
        JSONObject body = new JSONObject();
        JSONArray arrayBody = new JSONArray();
        arrayBody.addAll(Arrays.asList(new Integer[] {1, null, -1 }));
        body.put("__id", userDataId);
        body.put(propName, arrayBody);
        // ユーザデータ作成
        TResponse respons = createUserData(body, HttpStatus.SC_CREATED);

        Map<String, String> etagList = new HashMap<String, String>();
        etagList.put("userdata001", respons.getHeader(HttpHeaders.ETAG));

        // ユーザデータの一覧取得
        TResponse response = Http.request("box/odatacol/list.txt")
                .with("cell", cellName)
                .with("box", boxName)
                .with("collection", colName)
                .with("entityType", entityTypeName)
                .with("query", "")
                .with("accept", MediaType.APPLICATION_JSON)
                .with("token", DcCoreConfig.getMasterToken())
                .returns()
                .statusCode(HttpStatus.SC_OK)
                .debug();

        Map<String, String> uri = new HashMap<String, String>();
        uri.put(userDataId, UrlUtils.userData(cellName, boxName, colName, entityTypeName
                + "('" + userDataId + "')"));

        // プロパティ
        Map<String, Map<String, Object>> additional = new HashMap<String, Map<String, Object>>();
        Map<String, Object> additionalprop = new HashMap<String, Object>();
        additional.put(userDataId, additionalprop);
        additionalprop.put("__id", userDataId);
        additionalprop.put(propName, arrayBody);

        String nameSpace = getNameSpace(entityTypeName);
        ODataCommon
                .checkResponseBodyList(response.bodyAsJson(), uri, nameSpace, additional, "__id", null, etagList);

    } finally {
        // ユーザデータ削除
        deleteUserData(userDataId);
        // プロパティ削除
        PropertyUtils.delete(AbstractCase.BEARER_MASTER_TOKEN, cellName, boxName, colName, entityTypeName,
                propName, -1);
    }
}
 
源代码16 项目: io   文件: UserDataListTest.java
/**
 * UserDataの一覧でBoolean配列型プロパティにnullを含むデータを取得できること.
 */
@SuppressWarnings("unchecked")
@Test
public final void UserDataの一覧でBoolean配列型プロパティにnullを含むデータを取得できること() {
    String propName = "arrayIntTypeProperty";
    String userDataId = "userdata001";
    // リクエスト実行
    try {
        // Edm.Double配列のプロパティを作成
        PropertyUtils.create(AbstractCase.BEARER_MASTER_TOKEN, cellName, boxName, colName, entityTypeName,
                propName,
                EdmSimpleType.BOOLEAN.getFullyQualifiedTypeName(),
                true, null, "List", false, null, HttpStatus.SC_CREATED);
        // リクエストボディを設定
        JSONObject body = new JSONObject();
        JSONArray arrayBody = new JSONArray();
        arrayBody.addAll(Arrays.asList(new Boolean[] {true, null, false }));
        body.put("__id", userDataId);
        body.put(propName, arrayBody);
        // ユーザデータ作成
        TResponse respons = createUserData(body, HttpStatus.SC_CREATED);

        Map<String, String> etagList = new HashMap<String, String>();
        etagList.put("userdata001", respons.getHeader(HttpHeaders.ETAG));

        // ユーザデータの一覧取得
        TResponse response = Http.request("box/odatacol/list.txt")
                .with("cell", cellName)
                .with("box", boxName)
                .with("collection", colName)
                .with("entityType", entityTypeName)
                .with("query", "")
                .with("accept", MediaType.APPLICATION_JSON)
                .with("token", DcCoreConfig.getMasterToken())
                .returns()
                .statusCode(HttpStatus.SC_OK)
                .debug();

        Map<String, String> uri = new HashMap<String, String>();
        uri.put(userDataId, UrlUtils.userData(cellName, boxName, colName, entityTypeName
                + "('" + userDataId + "')"));

        // プロパティ
        Map<String, Map<String, Object>> additional = new HashMap<String, Map<String, Object>>();
        Map<String, Object> additionalprop = new HashMap<String, Object>();
        additional.put(userDataId, additionalprop);
        additionalprop.put("__id", userDataId);
        additionalprop.put(propName, arrayBody);

        String nameSpace = getNameSpace(entityTypeName);
        ODataCommon
                .checkResponseBodyList(response.bodyAsJson(), uri, nameSpace, additional, "__id", null, etagList);

    } finally {
        // ユーザデータ削除
        deleteUserData(userDataId);
        // プロパティ削除
        PropertyUtils.delete(AbstractCase.BEARER_MASTER_TOKEN, cellName, boxName, colName, entityTypeName,
                propName, -1);
    }
}
 
源代码17 项目: io   文件: UserDataListTest.java
/**
 * UserDataの一覧で文字列配列型プロパティにnullを含むデータを取得できること.
 */
@SuppressWarnings("unchecked")
@Test
public final void UserDataの一覧で文字列配列型プロパティにnullを含むデータを取得できること() {
    String propName = "arrayIntTypeProperty";
    String userDataId = "userdata001";
    // リクエスト実行
    try {
        // Edm.Double配列のプロパティを作成
        PropertyUtils.create(AbstractCase.BEARER_MASTER_TOKEN, cellName, boxName, colName, entityTypeName,
                propName,
                EdmSimpleType.STRING.getFullyQualifiedTypeName(),
                true, null, "List", false, null, HttpStatus.SC_CREATED);
        // リクエストボディを設定
        JSONObject body = new JSONObject();
        JSONArray arrayBody = new JSONArray();
        arrayBody.addAll(Arrays.asList(new String[] {"abc", null, "xyz", "null" }));
        body.put("__id", userDataId);
        body.put(propName, arrayBody);
        // ユーザデータ作成
        TResponse respons = createUserData(body, HttpStatus.SC_CREATED);

        Map<String, String> etagList = new HashMap<String, String>();
        etagList.put("userdata001", respons.getHeader(HttpHeaders.ETAG));

        // ユーザデータの一覧取得
        TResponse response = Http.request("box/odatacol/list.txt")
                .with("cell", cellName)
                .with("box", boxName)
                .with("collection", colName)
                .with("entityType", entityTypeName)
                .with("query", "")
                .with("accept", MediaType.APPLICATION_JSON)
                .with("token", DcCoreConfig.getMasterToken())
                .returns()
                .statusCode(HttpStatus.SC_OK)
                .debug();

        Map<String, String> uri = new HashMap<String, String>();
        uri.put(userDataId, UrlUtils.userData(cellName, boxName, colName, entityTypeName
                + "('" + userDataId + "')"));

        // プロパティ
        Map<String, Map<String, Object>> additional = new HashMap<String, Map<String, Object>>();
        Map<String, Object> additionalprop = new HashMap<String, Object>();
        additional.put(userDataId, additionalprop);
        additionalprop.put("__id", userDataId);
        additionalprop.put(propName, arrayBody);

        String nameSpace = getNameSpace(entityTypeName);
        ODataCommon
                .checkResponseBodyList(response.bodyAsJson(), uri, nameSpace, additional, "__id", null, etagList);

    } finally {
        // ユーザデータ削除
        deleteUserData(userDataId);
        // プロパティ削除
        PropertyUtils.delete(AbstractCase.BEARER_MASTER_TOKEN, cellName, boxName, colName, entityTypeName,
                propName, -1);
    }
}
 
源代码18 项目: Much-Assembly-Required   文件: SocketServer.java
private JSONArray intListToJSON(List<Integer> ints) {

        JSONArray jsonInts = new JSONArray();
        jsonInts.addAll(ints);

        return jsonInts;
    }