当前位置:   article > 正文

java object isempty,Java JsonObject.isEmpty方法代码示例

object.isempty

import org.json.simple.JsonObject; //导入方法依赖的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 = new ArrayList<>();

for (String containerPortData : (Set) 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);

}

}

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/611978
推荐阅读
相关标签
  

闽ICP备14008679号