Java Code Examples for org.json.simple.JSONObject#size()

The following examples show how to use org.json.simple.JSONObject#size() . 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: DockerConfig.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public List<Credentials> getAllCredentials() throws IOException {
    JSONObject currentAuths;
    synchronized (this) {
        loadCache();
        currentAuths = auths;
    }

    List<Credentials> ret = new ArrayList<>(currentAuths.size());
    for (Iterator<Map.Entry> it = currentAuths.entrySet().iterator(); it.hasNext();) {
        Map.Entry e = it.next();
        if (!(e.getKey() instanceof String)) {
            continue;
        }
        String registry = (String) e.getKey();
        JSONObject value = (JSONObject) e.getValue();
        if (value == null) {
            continue;
        }
        ret.add(createCredentials(registry, value)); // NOI18N
    }

    return ret;
}
 
Example 2
Source File: Performance.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
private void createHar(String pt, String rt) {
    Har<String, Log> har = new Har<>();
    Page p = new Page(pt, har.pages());
    har.addPage(p);
    for (Object res : (JSONArray) JSONValue.parse(rt)) {
        JSONObject jse = (JSONObject) res;
        if (jse.size() > 14) {
            Entry e = new Entry(jse.toJSONString(), p);
            har.addEntry(e);
        }
    }
    har.addRaw(pt, rt);
    Control.ReportManager.addHar(har, (TestCaseReport) Report,
            escapeName(Data));
}
 
Example 3
Source File: FavouriteSite.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static ListResponse<FavouriteSite> parseFavouriteSites(JSONObject jsonObject)
{
	JSONObject jsonList = (JSONObject)jsonObject.get("list");
	List<FavouriteSite> favouriteSites = new ArrayList<FavouriteSite>(jsonList.size());
	if(jsonList != null)
	{
		JSONArray jsonEntries = (JSONArray)jsonList.get("entries");
		if(jsonEntries != null)
		{
			for(int i = 0; i < jsonEntries.size(); i++)
			{
				JSONObject jsonEntry = (JSONObject)jsonEntries.get(i);
				JSONObject entry = (JSONObject)jsonEntry.get("entry");
				favouriteSites.add(parseFavouriteSite(entry));
			}
		}
	}

	ExpectedPaging paging = ExpectedPaging.parsePagination(jsonList);
	return new ListResponse<FavouriteSite>(paging, favouriteSites);
}
 
Example 4
Source File: StatusRecorder.java    From SB_Elsinore_Server with MIT License 6 votes vote down vote up
/**
 * Check to see if the objects are different.
 *
 * @param previous The first object to check.
 * @param current The second object to check
 * @return True if the objects are different
 */
protected final boolean isDifferent(final JSONObject previous,
        final JSONObject current) {
    if (previous.size() != current.size()) {
        return true;
    }

    for (Object key : previous.keySet()) {
        if (!"elapsed".equals(key)) {
            Object previousValue = previous.get(key);
            Object currentValue = current.get(key);

            if (compare(previousValue, currentValue)) {
                return true;
            }
        }
    }
    return false;
}
 
Example 5
Source File: DataFormatValidator.java    From AIDR with GNU Affero General Public License v3.0 6 votes vote down vote up
public static boolean isEmptyGeoJson(String jsonString){
    boolean isEmpty = false;
    //geometry
    JSONParser parser = new JSONParser();
    try{
        JSONObject geometry  = (JSONObject)parser.parse(jsonString) ;

        if(geometry.size() == 0){
            isEmpty = true;
        }

        JSONObject a = (JSONObject)geometry.get("geometry");

        if(a.size() == 0){
            isEmpty = true;
        }
    }
    catch(Exception e){
        isEmpty = true;
    }
    return isEmpty;
}
 
Example 6
Source File: GeoServiceImpl.java    From AIDR with GNU Affero General Public License v3.0 6 votes vote down vote up
private boolean isEmptyGeoJson(String jsonString){
    boolean isEmpty = false;
    //geometry
    try{
        JSONObject geometry  = (JSONObject)parser.parse(jsonString) ;

        if(geometry.size() == 0){
            isEmpty = true;
        }

        JSONObject a = (JSONObject)geometry.get("geometry");

        if(a.size() == 0){
            isEmpty = true;
        }
    }
    catch(Exception e){
        isEmpty = true;
    }
    return isEmpty;
}
 
Example 7
Source File: Select.java    From sepia-assist-server with MIT License 5 votes vote down vote up
/**
 * Try to match the selection options to the response.
 * @param response - User response given
 * @param customParameterName - parameter that will store the result
 * @param nluResult - NluResult given
 * @return null or JSONObject with match and number of match like this {"value": "green", "selection": 1}
 */
public static JSONObject matchSelection(String response, String customParameterName, NluResult nluResult){
	String optionsToParameterString = nluResult.getParameter(customParameterName.replace(PREFIX, OPTIONS_PREFIX));
	if (Is.nullOrEmpty(optionsToParameterString) || !optionsToParameterString.startsWith("{")){
		//User forgot to submit options .. this should not happen when using service-result builder properly
		Debugger.println("Missing or invalid options for select parameter '" + customParameterName + "': " + optionsToParameterString, 1);
		return null;
	}else{
		String match = "";
		int matchingKey = 0;
		try {
			JSONObject options = JSON.parseString(optionsToParameterString); 	//NOTE: Has to be built like this {"1":"Song", "2":"Playlist", "3":"Artist" ...}
			for (int i=0; i<options.size(); i++){
				String key = Integer.toString(i+1);
				String optionRegExp = JSON.getString(options, key);
				match = NluTools.stringFindFirst(response, optionRegExp);
				if (!match.isEmpty()){
					matchingKey = Integer.parseInt(key);
					break;
				}
			}
		}catch (Exception e){
			match = "";
			matchingKey = 0;
			Debugger.println("Missing or invalid options for select parameter '" + customParameterName + "': " + optionsToParameterString, 1);
		}
		return JSON.make(InterviewData.VALUE, match, "selection", matchingKey, InterviewData.INPUT, response);
	}
}
 
Example 8
Source File: DynamoDB.java    From sepia-assist-server with MIT License 5 votes vote down vote up
public static String makeExpressionAttributeName(String keyIn, JSONObject expressionAttributeNames){
	String keyOut = "";
	String[] elements = keyIn.split("\\.");
	for (String e : elements){
		String eNew = "#n" + expressionAttributeNames.size();
		JSON.add(expressionAttributeNames, eNew, e);
		keyOut += ("." + eNew);
	}
	return keyOut.replaceFirst("^\\.", "").trim();
}
 
Example 9
Source File: Command.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")    
public Command(String method, JSONObject params) {
    command = new JSONObject();
    command.put(COMMAND_ID, createUniqueID());
    command.put(COMMAND_METHOD, method);
    if (params != null && params.size() > 0) {
        command.put(COMMAND_PARAMS, params);
    }
}
 
Example 10
Source File: GrokParser.java    From metron with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private Optional<MessageParserResult<JSONObject>> parseSingleLine(byte[] rawMessage) {
  List<JSONObject> messages = new ArrayList<>();
  Map<Object,Throwable> errors = new HashMap<>();
  String originalMessage = null;
  try {
    originalMessage = new String(rawMessage, StandardCharsets.UTF_8);
    LOG.debug("Grok parser parsing message: {}",originalMessage);
    Match gm = grok.match(originalMessage);
    gm.captures();
    JSONObject message = new JSONObject();
    message.putAll(gm.toMap());

    if (message.size() == 0) {
      Throwable rte = new RuntimeException("Grok statement produced a null message. Original message was: "
              + originalMessage + " and the parsed message was: " + message + " . Check the pattern at: "
              + grokPath);
      errors.put(originalMessage, rte);
    } else {
      message.put("original_string", originalMessage);
      for (String timeField : timeFields) {
        String fieldValue = (String) message.get(timeField);
        if (fieldValue != null) {
          message.put(timeField, toEpoch(fieldValue));
        }
      }
      if (timestampField != null) {
        message.put(Constants.Fields.TIMESTAMP.getName(), formatTimestamp(message.get(timestampField)));
      }
      message.remove(patternLabel);
      postParse(message);
      messages.add(message);
      LOG.debug("Grok parser parsed message: {}", message);
    }
  } catch (Exception e) {
    LOG.error(e.getMessage(), e);
    Exception innerException = new IllegalStateException("Grok parser Error: "
            + e.getMessage()
            + " on "
            + originalMessage, e);
    return Optional.of(new DefaultMessageParserResult<>(innerException));
  }
  return Optional.of(new DefaultMessageParserResult<JSONObject>(messages, errors));
}