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


Java JSONArray.length方法代碼示例

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


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

示例1: verifyAMTaskAttempts

import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
public void verifyAMTaskAttempts(JSONObject json, Task task)
    throws JSONException {
  assertEquals("incorrect number of elements", 1, json.length());
  JSONObject attempts = json.getJSONObject("taskAttempts");
  assertEquals("incorrect number of elements", 1, json.length());
  JSONArray arr = attempts.getJSONArray("taskAttempt");
  for (TaskAttempt att : task.getAttempts().values()) {
    TaskAttemptId id = att.getID();
    String attid = MRApps.toString(id);
    Boolean found = false;

    for (int i = 0; i < arr.length(); i++) {
      JSONObject info = arr.getJSONObject(i);
      if (attid.matches(info.getString("id"))) {
        found = true;
        verifyAMTaskAttempt(info, att, task.getType());
      }
    }
    assertTrue("task attempt with id: " + attid
        + " not in web service output", found);
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:23,代碼來源:TestAMWebServicesAttempts.java

示例2: sandbox

import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
/**
 * 獲取沙箱信息.
 * 
 * @param appName 作業雲配置App的名字
 * @return 沙箱信息
 * @throws JSONException 解析JSON格式異常
 */
public JsonArray sandbox(final String appName) throws JSONException {
    JSONObject state = fetch(stateUrl);
    JsonArray result = new JsonArray();
    for (JSONObject each : findExecutors(state.getJSONArray("frameworks"), appName)) {
        JSONArray slaves = state.getJSONArray("slaves");
        String slaveHost = null;
        for (int i = 0; i < slaves.length(); i++) {
            JSONObject slave = slaves.getJSONObject(i);
            if (each.getString("slave_id").equals(slave.getString("id"))) {
                slaveHost = slave.getString("pid").split("@")[1];
            }
        }
        Preconditions.checkNotNull(slaveHost);
        JSONObject slaveState = fetch(String.format("http://%s/state", slaveHost));
        String workDir = slaveState.getJSONObject("flags").getString("work_dir");
        Collection<JSONObject> executorsOnSlave = findExecutors(slaveState.getJSONArray("frameworks"), appName);
        for (JSONObject executorOnSlave : executorsOnSlave) {
            JsonObject r = new JsonObject();
            r.addProperty("hostname", slaveState.getString("hostname"));
            r.addProperty("path", executorOnSlave.getString("directory").replace(workDir, ""));
            result.add(r);
        }
    }
    return result;
}
 
開發者ID:elasticjob,項目名稱:elastic-job-cloud,代碼行數:33,代碼來源:MesosStateService.java

示例3: findExecutors

import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
private Collection<JSONObject> findExecutors(final JSONArray frameworks, final String appName) throws JSONException {
    List<JSONObject> result = Lists.newArrayList();
    Optional<String> frameworkIDOptional = frameworkIDService.fetch();
    String frameworkID;
    if (frameworkIDOptional.isPresent()) {
        frameworkID = frameworkIDOptional.get();
    } else {
        return result;
    }
    for (int i = 0; i < frameworks.length(); i++) {
        JSONObject framework = frameworks.getJSONObject(i);
        if (!framework.getString("id").equals(frameworkID)) {
            continue;
        }
        JSONArray executors = framework.getJSONArray("executors");
        for (int j = 0; j < executors.length(); j++) {
            JSONObject executor = executors.getJSONObject(j);
            if (null == appName || appName.equals(getExecutorId(executor).split("@[email protected]")[0])) {
                result.add(executor);
            }
        }
    }
    return result;
}
 
開發者ID:elasticjob,項目名稱:elastic-job-cloud,代碼行數:25,代碼來源:MesosStateService.java

示例4: verifyHsJobTaskCounters

import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
public void verifyHsJobTaskCounters(JSONObject info, Task task)
    throws JSONException {

  assertEquals("incorrect number of elements", 2, info.length());

  WebServicesTestUtils.checkStringMatch("id", MRApps.toString(task.getID()),
      info.getString("id"));
  // just do simple verification of fields - not data is correct
  // in the fields
  JSONArray counterGroups = info.getJSONArray("taskCounterGroup");
  for (int i = 0; i < counterGroups.length(); i++) {
    JSONObject counterGroup = counterGroups.getJSONObject(i);
    String name = counterGroup.getString("counterGroupName");
    assertTrue("name not set", (name != null && !name.isEmpty()));
    JSONArray counters = counterGroup.getJSONArray("counter");
    for (int j = 0; j < counters.length(); j++) {
      JSONObject counter = counters.getJSONObject(j);
      String counterName = counter.getString("name");
      assertTrue("name not set",
          (counterName != null && !counterName.isEmpty()));
      long value = counter.getLong("value");
      assertTrue("value  >= 0", value >= 0);
    }
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:26,代碼來源:TestHsWebServicesTasks.java

示例5: verifyHsTask

import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
public void verifyHsTask(JSONArray arr, Job job, String type)
    throws JSONException {
  for (Task task : job.getTasks().values()) {
    TaskId id = task.getID();
    String tid = MRApps.toString(id);
    Boolean found = false;
    if (type != null && task.getType() == MRApps.taskType(type)) {

      for (int i = 0; i < arr.length(); i++) {
        JSONObject info = arr.getJSONObject(i);
        if (tid.matches(info.getString("id"))) {
          found = true;
          verifyHsSingleTask(info, task);
        }
      }
      assertTrue("task with id: " + tid + " not in web service output", found);
    }
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:20,代碼來源:TestHsWebServicesTasks.java

示例6: verifyHsTaskAttempts

import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
public void verifyHsTaskAttempts(JSONObject json, Task task)
    throws JSONException {
  assertEquals("incorrect number of elements", 1, json.length());
  JSONObject attempts = json.getJSONObject("taskAttempts");
  assertEquals("incorrect number of elements", 1, json.length());
  JSONArray arr = attempts.getJSONArray("taskAttempt");
  for (TaskAttempt att : task.getAttempts().values()) {
    TaskAttemptId id = att.getID();
    String attid = MRApps.toString(id);
    Boolean found = false;

    for (int i = 0; i < arr.length(); i++) {
      JSONObject info = arr.getJSONObject(i);
      if (attid.matches(info.getString("id"))) {
        found = true;
        verifyHsTaskAttempt(info, att, task.getType());
      }
    }
    assertTrue("task attempt with id: " + attid
        + " not in web service output", found);
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:23,代碼來源:TestHsWebServicesAttempts.java

示例7: verifyHsJobConf

import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
public void verifyHsJobConf(JSONObject info, Job job) throws JSONException {

    assertEquals("incorrect number of elements", 2, info.length());

    WebServicesTestUtils.checkStringMatch("path", job.getConfFile().toString(),
        info.getString("path"));
    // just do simple verification of fields - not data is correct
    // in the fields
    JSONArray properties = info.getJSONArray("property");
    for (int i = 0; i < properties.length(); i++) {
      JSONObject prop = properties.getJSONObject(i);
      String name = prop.getString("name");
      String value = prop.getString("value");
      assertTrue("name not set", (name != null && !name.isEmpty()));
      assertTrue("value not set", (value != null && !value.isEmpty()));
    }
  }
 
開發者ID:naver,項目名稱:hadoop,代碼行數:18,代碼來源:TestHsWebServicesJobConf.java

示例8: getCfgImports

import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
protected Map<String, String> getCfgImports(Key key, String key1, String key2) {
	try {
		Map<String, String> map = new HashMap<String, String>();
		JSONArray ar = jsonConfig.getJSONArray(key.name());
		for (int i=0; i<ar.length(); i++) {
			Object ob = ar.get(i);
			if (ob instanceof JSONObject) {
				JSONObject jsonImport = (JSONObject)ob;
				String val1 = jsonImport.getString(key1);
				String val2 = jsonImport.getString(key2);
				if (!val1.isEmpty() && !val2.isEmpty()) {
					map.put(val1, val2);
				}
			}
		}
		return map;
	} catch (JSONException e) {
		return new HashMap<String, String>();
	}
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:21,代碼來源:IonConfig.java

示例9: objectToStringList

import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
public List<String> objectToStringList(Object o){
    if(o == null) {
        return null;
    }

    List<String> stringList = null;

    if(o instanceof JSONArray) {
        JSONArray array = (JSONArray) o;
        stringList = new ArrayList<>(array.length());

        for (int i = 0; i < array.length(); i++) {
            try {
                stringList.add((String) array.get(i));
            } catch (JSONException e) {
                LOGGER.error("Error parsing sprint field", e);
            }
        }
    } else if(o instanceof List) {
        stringList = (List<String>) o;
    }

    return stringList;
}
 
開發者ID:BBVA,項目名稱:mirrorgate-jira-stories-collector,代碼行數:25,代碼來源:JiraIssueUtils.java

示例10: verifyHsJobTaskAttemptCounters

import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
public void verifyHsJobTaskAttemptCounters(JSONObject info, TaskAttempt att)
    throws JSONException {

  assertEquals("incorrect number of elements", 2, info.length());

  WebServicesTestUtils.checkStringMatch("id", MRApps.toString(att.getID()),
      info.getString("id"));

  // just do simple verification of fields - not data is correct
  // in the fields
  JSONArray counterGroups = info.getJSONArray("taskAttemptCounterGroup");
  for (int i = 0; i < counterGroups.length(); i++) {
    JSONObject counterGroup = counterGroups.getJSONObject(i);
    String name = counterGroup.getString("counterGroupName");
    assertTrue("name not set", (name != null && !name.isEmpty()));
    JSONArray counters = counterGroup.getJSONArray("counter");
    for (int j = 0; j < counters.length(); j++) {
      JSONObject counter = counters.getJSONObject(j);
      String counterName = counter.getString("name");
      assertTrue("name not set",
          (counterName != null && !counterName.isEmpty()));
      long value = counter.getLong("value");
      assertTrue("value  >= 0", value >= 0);
    }
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:27,代碼來源:TestHsWebServicesAttempts.java

示例11: getSubQueue

import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
private JSONObject getSubQueue(JSONObject queue, String subQueue)
  throws JSONException {
  JSONArray queues = queue.getJSONObject("queues").getJSONArray("queue");
  for (int i=0; i<queues.length(); ++i) {
    checkResourcesUsed(queues.getJSONObject(i));
    if (queues.getJSONObject(i).getString("queueName").equals(subQueue) ) {
      return queues.getJSONObject(i);
    }
  }
  return null;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:12,代碼來源:TestRMWebServicesCapacitySched.java

示例12: onDeletedDocs

import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
protected void onDeletedDocs(InternalHttpServletRequest request, JSONArray deletedDocs) throws EngineException, JSONException {		
	if (isEnabled()) {
		int len = deletedDocs.length();
		
		for (int i = 0; i < len;) {
			JSONArray docs = getChunk(deletedDocs, i);
			i += docs.length();
			executeSequence(request, docs);
		}
	}
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:12,代碼來源:AbstractFullSyncListener.java

示例13: getChunk

import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
protected JSONArray getChunk(JSONArray array, int offset) throws JSONException {
	if (offset == 0 && array.length() < chunk) {
		return array;
	}
	int limit = Math.min(array.length(), offset + chunk);
	JSONArray sub = new JSONArray();
	for (int i = offset; i < limit; i++) {
		sub.put(array.get(i));
	}
	return sub;
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:12,代碼來源:AbstractFullSyncListener.java

示例14: getNgImports

import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
protected Set<String> getNgImports(Key key) {
	try {
		Set<String> set = new HashSet<String>();
		JSONArray ar = jsonConfig.getJSONArray(key.name());
		for (int i=0; i<ar.length(); i++) {
			String s = ar.getString(i);
			if (!s.isEmpty()) {
				set.add(s);
			}
		}
		return set;
	} catch (JSONException e) {
		return new HashSet<String>();
	}
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:16,代碼來源:IonConfig.java

示例15: verifyHsJobCounters

import org.codehaus.jettison.json.JSONArray; //導入方法依賴的package包/類
public void verifyHsJobCounters(JSONObject info, Job job)
    throws JSONException {

  assertEquals("incorrect number of elements", 2, info.length());

  WebServicesTestUtils.checkStringMatch("id", MRApps.toString(job.getID()),
      info.getString("id"));
  // just do simple verification of fields - not data is correct
  // in the fields
  JSONArray counterGroups = info.getJSONArray("counterGroup");
  for (int i = 0; i < counterGroups.length(); i++) {
    JSONObject counterGroup = counterGroups.getJSONObject(i);
    String name = counterGroup.getString("counterGroupName");
    assertTrue("name not set", (name != null && !name.isEmpty()));
    JSONArray counters = counterGroup.getJSONArray("counter");
    for (int j = 0; j < counters.length(); j++) {
      JSONObject counter = counters.getJSONObject(j);
      String counterName = counter.getString("name");
      assertTrue("counter name not set",
          (counterName != null && !counterName.isEmpty()));

      long mapValue = counter.getLong("mapCounterValue");
      assertTrue("mapCounterValue  >= 0", mapValue >= 0);

      long reduceValue = counter.getLong("reduceCounterValue");
      assertTrue("reduceCounterValue  >= 0", reduceValue >= 0);

      long totalValue = counter.getLong("totalCounterValue");
      assertTrue("totalCounterValue  >= 0", totalValue >= 0);

    }
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:34,代碼來源:TestHsWebServicesJobs.java


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