当前位置: 首页>>代码示例>>Java>>正文


Java JSONArray.isEmpty方法代码示例

本文整理汇总了Java中org.json.simple.JSONArray.isEmpty方法的典型用法代码示例。如果您正苦于以下问题:Java JSONArray.isEmpty方法的具体用法?Java JSONArray.isEmpty怎么用?Java JSONArray.isEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.json.simple.JSONArray的用法示例。


在下文中一共展示了JSONArray.isEmpty方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getContainers

import org.json.simple.JSONArray; //导入方法依赖的package包/类
public List<DockerContainer> getContainers() {
    try {
        JSONArray value = (JSONArray) doGetRequest("/containers/json?all=1",
                Collections.singleton(HttpURLConnection.HTTP_OK));
        List<DockerContainer> ret = new ArrayList<>(value.size());
        for (Object o : value) {
            JSONObject json = (JSONObject) o;
            String id = (String) json.get("Id");
            String image = (String) json.get("Image");
            String name = null;
            JSONArray names = (JSONArray) json.get("Names");
            if (names != null && !names.isEmpty()) {
                name = (String) names.get(0);
            }
            DockerContainer.Status status = DockerUtils.getContainerStatus((String) json.get("Status"));
            ret.add(new DockerContainer(instance, id, image, name, status));
        }
        return ret;
    } catch (DockerException ex) {
        LOGGER.log(Level.INFO, null, ex);
    }
    return Collections.emptyList();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:DockerAction.java

示例2: process

import org.json.simple.JSONArray; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void process(ProcessingContext<Corpus> ctx, Corpus corpus) throws ModuleException {
	Logger logger = getLogger(ctx);
	EvaluationContext evalCtx = new EvaluationContext(logger);
	PubAnnotationExportResolvedObjects resObj = getResolvedObjects();
	JSONArray result = new JSONArray();
	for (Section sec : Iterators.loop(sectionIterator(evalCtx, corpus))) {
		JSONObject j = resObj.convert(evalCtx, sec);
		result.add(j);
	}
	if (result.isEmpty()) {
		return;
	}
	try (Writer w = new OutputStreamWriter(new FileOutputStream(outFile), "UTF-8")) {
		if (result.size() == 1) {
			((JSONObject) result.get(0)).writeJSONString(w);
		}
		else {
			result.writeJSONString(w);
		}
		w.flush();
	}
	catch (IOException e) {
		rethrow(e);
	}
}
 
开发者ID:Bibliome,项目名称:alvisnlp,代码行数:28,代码来源:PubAnnotationExport.java

示例3: getDetail

import org.json.simple.JSONArray; //导入方法依赖的package包/类
public DockerContainerDetail getDetail(DockerContainer container) throws DockerException {
    JSONObject value = (JSONObject) doGetRequest("/containers/" + container.getId() + "/json",
            Collections.singleton(HttpURLConnection.HTTP_OK));
    String name = (String) value.get("Name");
    DockerContainer.Status status = DockerContainer.Status.STOPPED;
    JSONObject state = (JSONObject) value.get("State");
    if (state != null) {
        boolean paused = (Boolean) getOrDefault(state, "Paused", false);
        if (paused) {
            status = DockerContainer.Status.PAUSED;
        } else {
            boolean running = (Boolean) getOrDefault(state, "Running", false);
            if (running) {
                status = DockerContainer.Status.RUNNING;
            }
        }
    }

    boolean tty = false;
    boolean stdin = false;
    JSONObject config = (JSONObject) value.get("Config");
    if (config != null) {
        tty = (boolean) getOrDefault(config, "Tty", false);
        stdin = (boolean) getOrDefault(config, "OpenStdin", false);
    }
    JSONObject ports = (JSONObject) ((JSONObject) value.get("NetworkSettings")).get("Ports");
    if (ports == null || ports.isEmpty()) {
        return new DockerContainerDetail(name, status, stdin, tty);
    } else {
        List<PortMapping> portMapping = new ArrayList<>();
        for (String containerPortData : (Set<String>) ports.keySet()) {
            JSONArray hostPortsArray = (JSONArray) ports.get(containerPortData);
            if (hostPortsArray != null && !hostPortsArray.isEmpty()) {
                Matcher m = PORT_PATTERN.matcher(containerPortData);
                if (m.matches()) {
                    int containerPort = Integer.parseInt(m.group(1));
                    String type = m.group(2).toUpperCase(Locale.ENGLISH);
                    int hostPort = Integer.parseInt((String) ((JSONObject) hostPortsArray.get(0)).get("HostPort"));
                    String hostIp = (String) ((JSONObject) hostPortsArray.get(0)).get("HostIp");
                    portMapping.add(new PortMapping(ExposedPort.Type.valueOf(type), containerPort, hostPort, hostIp));
                } else {
                    LOGGER.log(Level.FINE, "Unparsable port: {0}", containerPortData);
                }
            }
        }
        return new DockerContainerDetail(name, status, stdin, tty, portMapping);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:49,代码来源:DockerAction.java

示例4: getCommonMilestoneBlockId

import org.json.simple.JSONArray; //导入方法依赖的package包/类
private long getCommonMilestoneBlockId(Peer peer) {

			String lastMilestoneBlockId = null;

			while (true) {
				JSONObject milestoneBlockIdsRequest = new JSONObject();
				milestoneBlockIdsRequest.put("requestType", "getMilestoneBlockIds");
				if (lastMilestoneBlockId == null) {
					milestoneBlockIdsRequest.put("lastBlockId", blockchain.getLastBlock().getStringId());
				} else {
					milestoneBlockIdsRequest.put("lastMilestoneBlockId", lastMilestoneBlockId);
				}

				JSONObject response = peer.send(JSON.prepareRequest(milestoneBlockIdsRequest));
				if (response == null) {
					return 0;
				}
				JSONArray milestoneBlockIds = (JSONArray) response.get("milestoneBlockIds");
				if (milestoneBlockIds == null) {
					return 0;
				}
				if (milestoneBlockIds.isEmpty()) {
					return Genesis.GENESIS_BLOCK_ID;
				}
				// prevent overloading with blockIds
				if (milestoneBlockIds.size() > 20) {
					Logger.logDebugMessage("Obsolete or rogue peer " + peer.getPeerAddress() + " sends too many milestoneBlockIds, blacklisting");
					peer.blacklist();
					return 0;
				}
				if (Boolean.TRUE.equals(response.get("last"))) {
					peerHasMore = false;
				}
				for (Object milestoneBlockId : milestoneBlockIds) {
					long blockId = Convert.parseUnsignedLong((String) milestoneBlockId);
					if (BlockDb.hasBlock(blockId)) {
						if (lastMilestoneBlockId == null && milestoneBlockIds.size() > 1) {
							peerHasMore = false;
						}
						return blockId;
					}
					lastMilestoneBlockId = (String) milestoneBlockId;
				}
			}

		}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:47,代码来源:BlockchainProcessorImpl.java

示例5: buildPackagePolicy

import org.json.simple.JSONArray; //导入方法依赖的package包/类
/**
 * This function collects information (layers and objects) about a given package.
 *
 * @param packageName the package name to collect the information about.
 * @param objectsInUse the objects that were already collected
 *
 * @return {@link PolicyPackage} contains information about the package
 */
private static PolicyPackage buildPackagePolicy(String packageName, JSONArray objectsInUse) {

    List<Layer> accessLayers = new ArrayList<>();
    List<Layer> threatLayers = new ArrayList<>();
    Layer natLayer;
    PolicyPackage policyPackage = null;
    try {
        //The vpn communities which were collected are common to all of the policy packages.
        //Clone these objects in order to include the vpn communities in all the packages.
        addObjectsInfoIntoCollections(objectsInUse);

        //Fill the layer and the layer's list with information about the package's layers.
        configuration.getLogger().debug("Starting to process layers of package '" + packageName + "'");

        natLayer = aggregatePackageLayers(packageName, accessLayers, threatLayers);
        //Handle access layer
        configuration.getLogger().debug("Handle access layers");
        for (Layer accessLayer : accessLayers) {
            showAccessRulebase(accessLayer, packageName);
        }

        //Handle nat layer
        if (natLayer != null) {
            configuration.getLogger().debug("Handle nat layer");
            showNatRulebase(natLayer, packageName);
        }

        //Handle threat layers
        configuration.getLogger().debug("Handle threat layers");
        for (Layer threatLayer : threatLayers) {
            showThreatRulebase(packageName, threatLayer);
        }
        //Crete a Html page that contains the objects of the package
        writeDictionary(packageName);

        //Create a policy package
        policyPackage = new PolicyPackage(packageName, accessLayers, threatLayers, natLayer, allTypes);

        //Handle gateways that the policy is install on
        JSONArray gatewayObjects = new JSONArray();
        for (GatewayAndServer gateway : configuration.getGatewaysWithPolicy()) {
            //Add all the relevant gateways and servers for the current package
            if (gateway.getAccessPolicy() != null && packageName.equalsIgnoreCase(gateway.getAccessPolicy()) ||
                    gateway.getThreatPolicy() != null && packageName.equalsIgnoreCase(gateway.getThreatPolicy())) {
                gatewayObjects.add(gateway.getGatewayObject());
                policyPackage.setGatewayAndServer(gateway);
            }
        }

        //Create a html page that contains the gateways
        if (!gatewayObjects.isEmpty()) {
            writeGateways(packageName, gatewayObjects);
        }
    }
    catch (Exception e){

        handleException(e, "Error: failed while creating policy package: '" + packageName + "'. Exception: " + e.getMessage());
    }
    finally {
        // initialize it for he next package
        allTypes = null;
        configuration.getUidToName().clear();
    }
    return policyPackage;
}
 
开发者ID:CheckPoint-APIs-Team,项目名称:ShowPolicyPackage,代码行数:74,代码来源:ShowPackageTool.java


注:本文中的org.json.simple.JSONArray.isEmpty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。