Java Code Examples for org.json.simple.JSONArray#remove()

The following examples show how to use org.json.simple.JSONArray#remove() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UtilsClustering.java    From apogen with Apache License 2.0 6 votes vote down vote up
private static String getMaster(String s, JSONArray array) {

		for (int i = 0; i < array.size(); i++) {

			JSONObject cluster = (JSONObject) array.get(i);

			String master = (String) cluster.get("master");
			JSONArray slaves = (JSONArray) cluster.get("slaves");
			slaves.remove(master);

			if (slaves.contains(s)) {
				return master;
			}
		}
		return "";
	}
 
Example 2
Source File: RepositoryBrowserController.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public JSONArray storeRecentSearch( String recentSearch ) {
  JSONArray recentSearches = getRecentSearches();
  try {
    if ( recentSearch == null || recentSearches.contains( recentSearch ) ) {
      return recentSearches;
    }
    recentSearches.add( recentSearch );
    if ( recentSearches.size() > 5 ) {
      recentSearches.remove( 0 );
    }

    PropsUI props = PropsUI.getInstance();
    String jsonValue = props.getRecentSearches();
    JSONParser jsonParser = new JSONParser();
    JSONObject jsonObject = jsonValue != null ? (JSONObject) jsonParser.parse( jsonValue ) : new JSONObject();
    jsonObject.put( getLogin(), recentSearches );
    props.setRecentSearches( jsonObject.toJSONString() );
  } catch ( Exception e ) {
    e.printStackTrace();
  }

  return recentSearches;
}
 
Example 3
Source File: RepositoryBrowserController.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public JSONArray storeRecentSearch( String recentSearch ) {
  JSONArray recentSearches = getRecentSearches();
  try {
    if ( recentSearch == null || recentSearches.contains( recentSearch ) ) {
      return recentSearches;
    }
    recentSearches.add( recentSearch );
    if ( recentSearches.size() > 5 ) {
      recentSearches.remove( 0 );
    }

    PropsUI props = PropsUI.getInstance();
    String jsonValue = props.getRecentSearches();
    JSONParser jsonParser = new JSONParser();
    JSONObject jsonObject = jsonValue != null ? (JSONObject) jsonParser.parse( jsonValue ) : new JSONObject();
    jsonObject.put( getLogin(), recentSearches );
    props.setRecentSearches( jsonObject.toJSONString() );
  } catch ( Exception e ) {
    e.printStackTrace();
  }

  return recentSearches;
}
 
Example 4
Source File: UtilsClustering.java    From apogen with Apache License 2.0 5 votes vote down vote up
private static JSONObject removeCandidateElement(String id, JSONObject allStates) {

		for (Object o : allStates.keySet()) {
			JSONObject jo = (JSONObject) allStates.get(o);
			JSONArray ca = (JSONArray) jo.get("candidateElements");
			for (int i = 0; i < ca.size(); i++) {
				JSONObject c = (JSONObject) ca.get(i);
				if (c.get("xpath").equals(id)) {
					ca.remove(i);
				}
			}
		}

		return allStates;
	}
 
Example 5
Source File: TradeBuyOrderDMLStmtJson.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private void deleteElementFromJsonArray(JSONArray jsonBuyorderArray , int oid){
  
  for ( int currElement =0 ; currElement < jsonBuyorderArray.size() ; currElement++  ) {
    JSONObject jsonBuyorderCurrentObject = (JSONObject)jsonBuyorderArray.get(currElement);        
    int currentOid =  ((Long)jsonBuyorderCurrentObject.get("oid")).intValue();
    if ( currentOid == oid)  {
        jsonBuyorderArray.remove(currElement);
        break;
    }
  }
}
 
Example 6
Source File: TradeBuyOrderDMLStmtJson.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private void deleteElementFromJsonArray(JSONArray jsonBuyorderArray , int oid){
  
  for ( int currElement =0 ; currElement < jsonBuyorderArray.size() ; currElement++  ) {
    JSONObject jsonBuyorderCurrentObject = (JSONObject)jsonBuyorderArray.get(currElement);        
    int currentOid =  ((Long)jsonBuyorderCurrentObject.get("oid")).intValue();
    if ( currentOid == oid)  {
        jsonBuyorderArray.remove(currElement);
        break;
    }
  }
}
 
Example 7
Source File: JSONUtilities.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
public static void removeModelJson(JSONObject jsondb, UUID modelUUID) {
    // Find models node and remove modelUUID from list of children
    JSONObject models_json = ((JSONObject) jsondb.get("object"));
    JSONArray models_children = (JSONArray) models_json.get("children");

    for (int index = 0; index < models_children.size(); index++){
        JSONObject nextModelJson = (JSONObject) models_children.get(index);
        String nextModelUUID =  (String) nextModelJson.get("uuid");
        if (nextModelUUID.equals(modelUUID.toString())){
            models_children.remove(index);
            break;
        }
    }
}
 
Example 8
Source File: UserDataPropertyDateTimeTest.java    From io with Apache License 2.0 4 votes vote down vote up
/**
 * 配列のPropertyのTypeがEdmDateTimeのときnullで更新できること. 配列にEdmDateTime型のPropertyを登録できないため、Ignoreとしている.
 */
@SuppressWarnings("unchecked")
@Test
@Ignore
public final void 配列のPropertyのTypeがEdmDateTimeのときnullで更新できること() {
    final String time = "/Date(1359340262406)/";
    // リクエストボディを設定
    JSONArray etListPropStr = new JSONArray();
    etListPropStr.add(time);
    etListPropStr.add(time);
    JSONObject body = new JSONObject();
    body.put("__id", USERDATA_ID);
    body.put(PROP_NAME, etListPropStr);

    try {
        createEntities();
        createProperty(EdmSimpleType.DATETIME.getFullyQualifiedTypeName(), null, "List");

        // ユーザデータ作成
        TResponse response = createUserData(body, HttpStatus.SC_CREATED,
                cellName, boxName, COL_NAME, ENTITY_TYPE_NAME);

        JSONObject json = response.bodyAsJson();
        JSONObject results = (JSONObject) ((JSONObject) json.get("d")).get("results");
        assertEquals("[/Date(1360037777872)/,/Date(1360037777872)/]", results.get(PROP_NAME).toString());

        etListPropStr.add(null);
        etListPropStr.add(null);
        etListPropStr.remove(0);
        etListPropStr.remove(0);
        body.put(PROP_NAME, etListPropStr);
        // ユーザデータ更新
        updateUserData(cellName, boxName, COL_NAME, ENTITY_TYPE_NAME, USERDATA_ID, body);

        // ユーザデータ一件取得
        TResponse getResponse = getUserData(cellName, boxName, COL_NAME, ENTITY_TYPE_NAME, USERDATA_ID,
                Setup.MASTER_TOKEN_NAME, HttpStatus.SC_OK);
        JSONObject getJson = getResponse.bodyAsJson();
        JSONObject getResults = (JSONObject) ((JSONObject) getJson.get("d")).get("results");
        assertEquals("[null,null]", getResults.get(PROP_NAME).toString());
    } finally {
        // ユーザデータ削除
        deleteUserData(USERDATA_ID);

        deleteProperty();
        deleteEntities();
    }
}
 
Example 9
Source File: ModelVisualizationJson.java    From opensim-gui with Apache License 2.0 4 votes vote down vote up
public void deletePathPointVisuals(GeometryPath currentPath, int index) {
    boolean hasWrapping = currentPath.getWrapSet().getSize()>0;
    AbstractPathPoint appoint = currentPath.getPathPointSet().get(index);
    ArrayList<UUID> uuids = mapComponentToUUID.get(appoint);
    // Remove uuids[0] from visualizer
    UUID appoint_uuid = uuids.get(0);
    // cleanup maps
    mapComponentToUUID.remove(appoint);
    mapUUIDToComponent.remove(appoint_uuid);
    // If Conditional remove it from proxyPathPoints
    if (ConditionalPathPoint.safeDownCast(appoint)!= null)
        proxyPathPoints.remove(appoint);
    else if (MovingPathPoint.safeDownCast(appoint)!=null){
        movingComponents.remove(appoint);
    }
    if (hasWrapping) {
    // If deleted point was used in wrapping, update accordingly
        int pathNoWrapLength = currentPath.getPathPointSet().getSize();
        // remove computed points that depends on appoint
        Set<UUID> computedPointsInfo = computedPathPoints.keySet();
        ArrayList<UUID> toDelete = new ArrayList<UUID>();
        for (UUID pathpointUuid : computedPointsInfo) {
            ComputedPathPointInfo pathpointInfo = computedPathPoints.get(pathpointUuid);
            if (pathpointInfo.pt1.equals(appoint) || (pathpointInfo.pt2.equals(appoint) && index==pathNoWrapLength-1)) {
                toDelete.add(pathpointUuid);
            }
            else if (pathpointInfo.pt2.equals(appoint)){
                // replace pathpointInfo.pt2 by next point in path
                pathpointInfo.pt2 = currentPath.getPathPointSet().get(index+1);
            }
        }
        JSONArray pathpoint_jsonArr = pathsWithWrapping.get(currentPath);
        for (UUID delPpoint : toDelete) {
            computedPathPoints.remove(delPpoint);
            pathpoint_jsonArr.remove(delPpoint.toString());
        }
        // Remove pathpoint being deleted from cached uuids
        pathpoint_jsonArr.remove(appoint_uuid.toString());
        
    }
    
}