本文整理汇总了Java中com.fasterxml.jackson.databind.node.ArrayNode.forEach方法的典型用法代码示例。如果您正苦于以下问题:Java ArrayNode.forEach方法的具体用法?Java ArrayNode.forEach怎么用?Java ArrayNode.forEach使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.databind.node.ArrayNode
的用法示例。
在下文中一共展示了ArrayNode.forEach方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createFlows
import com.fasterxml.jackson.databind.node.ArrayNode; //导入方法依赖的package包/类
/**
* Creates new flow rules. Creates and installs a new flow rules.<br>
* Instructions description:
* https://wiki.onosproject.org/display/ONOS/Flow+Rule+Instructions
* <br>
* Criteria description:
* https://wiki.onosproject.org/display/ONOS/Flow+Rule+Criteria
*
* @param stream flow rules JSON
* @return status of the request - CREATED if the JSON is correct,
* BAD_REQUEST if the JSON is invalid
* @onos.rsModel FlowsBatchPost
*/
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createFlows(@QueryParam("appId") String appId, InputStream stream) {
try {
ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
ArrayNode flowsArray = (ArrayNode) jsonTree.get(FLOWS);
if (appId != null) {
flowsArray.forEach(flowJson -> ((ObjectNode) flowJson).put("appId", appId));
}
List<FlowRule> rules = codec(FlowRule.class).decode(flowsArray, this);
service.applyFlowRules(rules.toArray(new FlowRule[rules.size()]));
rules.forEach(flowRule -> {
ObjectNode flowNode = mapper().createObjectNode();
flowNode.put(DEVICE_ID, flowRule.deviceId().toString())
.put(FLOW_ID, flowRule.id().value());
flowsNode.add(flowNode);
});
} catch (IOException ex) {
throw new IllegalArgumentException(ex);
}
return Response.ok(root).build();
}
示例2: getNetworks
import com.fasterxml.jackson.databind.node.ArrayNode; //导入方法依赖的package包/类
/**
* Returns network information stored in Neutron.
*
* @return List of OpenstackNetwork
*/
public Collection<OpenstackNetwork> getNetworks() {
Invocation.Builder builder = getClientBuilder(neutronUrl + URI_NETWORKS);
String response = builder.accept(MediaType.APPLICATION_JSON_TYPE).
header(HEADER_AUTH_TOKEN, getToken()).get(String.class);
log.debug("networks response:" + response);
ObjectMapper mapper = new ObjectMapper();
List<OpenstackNetwork> openstackNetworks = Lists.newArrayList();
try {
ObjectNode node = (ObjectNode) mapper.readTree(response);
ArrayNode networkList = (ArrayNode) node.path(PATH_NETWORKS);
OpenstackNetworkCodec networkCodec = new OpenstackNetworkCodec();
networkList.forEach(n -> openstackNetworks.add(networkCodec.decode((ObjectNode) n, null)));
} catch (IOException e) {
log.warn("getNetworks()", e);
}
openstackNetworks.removeAll(Collections.singleton(null));
openstackNetworks.forEach(n -> log.debug("network ID: {}", n.id()));
return openstackNetworks;
}
示例3: getPorts
import com.fasterxml.jackson.databind.node.ArrayNode; //导入方法依赖的package包/类
/**
* Returns port information stored in Neutron.
*
* @return List of OpenstackPort
*/
public Collection<OpenstackPort> getPorts() {
Invocation.Builder builder = getClientBuilder(neutronUrl + URI_PORTS);
String response = builder.accept(MediaType.APPLICATION_JSON_TYPE).
header(HEADER_AUTH_TOKEN, getToken()).get(String.class);
ObjectMapper mapper = new ObjectMapper();
List<OpenstackPort> openstackPorts = Lists.newArrayList();
try {
ObjectNode node = (ObjectNode) mapper.readTree(response);
ArrayNode portList = (ArrayNode) node.path(PATH_PORTS);
OpenstackPortCodec portCodec = new OpenstackPortCodec();
portList.forEach(p -> openstackPorts.add(portCodec.decode((ObjectNode) p, null)));
} catch (IOException e) {
log.warn("getPorts()", e);
}
log.debug("port response:" + response);
openstackPorts.forEach(n -> log.debug("port ID: {}", n.id()));
return openstackPorts;
}
示例4: getRouters
import com.fasterxml.jackson.databind.node.ArrayNode; //导入方法依赖的package包/类
public Collection<OpenstackRouter> getRouters() {
Invocation.Builder builder = getClientBuilder(neutronUrl + PATH_ROUTERS);
String response = builder.accept(MediaType.APPLICATION_JSON_TYPE).
header(HEADER_AUTH_TOKEN, getToken()).get(String.class);
ObjectMapper mapper = new ObjectMapper();
List<OpenstackRouter> openstackRouters = Lists.newArrayList();
try {
ObjectNode node = (ObjectNode) mapper.readTree(response);
ArrayNode routerList = (ArrayNode) node.path(PATH_ROUTERS);
OpenstackRouterCodec openstackRouterCodec = new OpenstackRouterCodec();
routerList.forEach(r -> openstackRouters
.add(openstackRouterCodec.decode((ObjectNode) r, null)));
} catch (IOException e) {
log.warn("getRouters()", e);
}
log.debug("router response:" + response);
openstackRouters.forEach(r -> log.debug("router ID: {}", r.id()));
return openstackRouters;
}
示例5: getSubnets
import com.fasterxml.jackson.databind.node.ArrayNode; //导入方法依赖的package包/类
/**
* Returns Subnet information in Neutron.
*
* @return List of OpenstackSubnet
*/
public Collection<OpenstackSubnet> getSubnets() {
Invocation.Builder builder = getClientBuilder(neutronUrl + URI_SUBNETS);
String response = builder.accept(MediaType.APPLICATION_JSON_TYPE).
header(HEADER_AUTH_TOKEN, getToken()).get(String.class);
ObjectMapper mapper = new ObjectMapper();
List<OpenstackSubnet> subnets = Lists.newArrayList();
try {
ObjectNode node = (ObjectNode) mapper.readTree(response);
ArrayNode subnetList = (ArrayNode) node.path(PATH_SUBNETS);
OpenstackSubnetCodec subnetCodec = new OpenstackSubnetCodec();
subnetList.forEach(s -> subnets.add(subnetCodec.decode((ObjectNode) s, null)));
} catch (IOException e) {
log.warn("getSubnets()", e);
}
log.debug("subnets response:" + response);
subnets.forEach(s -> log.debug("subnet ID: {}", s.id()));
return subnets;
}
示例6: updateTopics
import com.fasterxml.jackson.databind.node.ArrayNode; //导入方法依赖的package包/类
private void updateTopics(JsonNode updateBody, Meeting existingMeeting) {
if (updateBody.has("topics")) {
ArrayNode topicsNode = (ArrayNode) updateBody.get("topics");
Set<Topic> topics = new HashSet<>();
topicsNode.forEach(node -> {
try {
Topic topic = objectMapper.treeToValue(node, Topic.class);
Topic loadedTopic = topicService.loadOrCreateNewTopic(topic);
topics.add(loadedTopic);
} catch (JsonProcessingException e) {
throw new MeetingUpdateException("모임 주제", e.getCause());
}
});
existingMeeting.setTopics(topics);
}
}
示例7: updateAdmins
import com.fasterxml.jackson.databind.node.ArrayNode; //导入方法依赖的package包/类
private void updateAdmins(JsonNode updateBody, Meeting existingMeeting) {
if (updateBody.has("admins")) {
ArrayNode adminsNode = (ArrayNode) updateBody.get("admins");
Set<User> admins = new HashSet<>();
adminsNode.forEach(node -> {
try {
User user = objectMapper.treeToValue(node, User.class);
Optional<User> byId = userRepository.findById(user.getId(), 1);
byId.ifPresent(admins::add);
} catch (JsonProcessingException e) {
throw new MeetingUpdateException("모임 관리자", e.getCause());
}
});
existingMeeting.setAdmins(admins);
}
}
示例8: verifyClientAccounts
import com.fasterxml.jackson.databind.node.ArrayNode; //导入方法依赖的package包/类
private void verifyClientAccounts(String clientId, Map<String, BigDecimal> expectedAccountsBalances) {
Response response = resourcesClient.getClientAccounts(clientId);
ArrayNode accounts = response.readEntity(ArrayNode.class);
accounts.forEach(account -> {
String accountId = account.get("accountId").asText();
BigDecimal balance = new BigDecimal(account.get("balance").asText());
assertThat(balance, equalTo(expectedAccountsBalances.get(accountId)));
});
}
示例9: allAdminUsers
import com.fasterxml.jackson.databind.node.ArrayNode; //导入方法依赖的package包/类
@Cacheable(CsapCoreService.TIMEOUT_CACHE_60s)
synchronized public ArrayNode allAdminUsers () {
ArrayNode users = jacksonMapper.createArrayNode() ;
// remove calls for other hosts
csapApp.getAllPackages()
.getServiceInstances( "admin" )
.filter( instance -> ! instance.getHostName().equals( Application.getHOST_NAME() ) )
.map( this::getUsersOnRemoteAdmins )
.forEach( users::addAll );
// add the local host entries
users.addAll( getActive() ) ;
// now make them distinct
HashSet<String> uniqueUsers = new HashSet<>() ;
users.forEach( userJson -> uniqueUsers.add( userJson.asText() ));
// Now transform
users.removeAll() ;
uniqueUsers.forEach( users::add );
return users ;
}
示例10: extractEmbeddedServiceFiles
import com.fasterxml.jackson.databind.node.ArrayNode; //导入方法依赖的package包/类
private ArrayNode extractEmbeddedServiceFiles ( ArrayNode files ) {
ArrayNode internalOnly = jacksonMapper.createArrayNode();
files.forEach( propFile -> {
if ( propFile.has( ServiceAttributes.FileAttributes.external.json )
&& !propFile.get( ServiceAttributes.FileAttributes.external.json ).asBoolean() ) {
internalOnly.add( propFile );
}
} );
return internalOnly;
}
示例11: addToPendingResources
import com.fasterxml.jackson.databind.node.ArrayNode; //导入方法依赖的package包/类
private void addToPendingResources ( ObjectNode serviceNode, String serviceName ) {
// File resourceDir = csapApp.getResourcesFolder( serviceName );
File serviceResourceDir = csapApp.getResourcesWorkingFolder();
// only internal files are stored.
ArrayNode files = (ArrayNode) serviceNode.get( ServiceAttributes.files.value );
ArrayNode internalOnly = extractEmbeddedServiceFiles( files );
serviceNode.set( ServiceAttributes.files.value, internalOnly );
files.forEach( propFile -> {
String targetLife = propFile.get( ServiceAttributes.FileAttributes.lifecycle.json ).asText();
String targetName = propFile.get( ServiceAttributes.FileAttributes.name.json ).asText();
String targetPath = serviceName + "/resources/" + targetLife + "/" + targetName;
if ( propFile.has( ServiceAttributes.FileAttributes.external.json )
&& propFile.get( ServiceAttributes.FileAttributes.external.json ).asBoolean() ) {
if ( propFile.has( ServiceAttributes.FileAttributes.newFile.json )
&& propFile.get( ServiceAttributes.FileAttributes.newFile.json ).asBoolean() ) {
writePropertyFile( serviceResourceDir, targetPath, propFile );
csapApp.getPendingResourceAdds().add( targetPath );
} else if ( propFile.has( ServiceAttributes.FileAttributes.contentUpdated.json )
&& propFile.get( ServiceAttributes.FileAttributes.contentUpdated.json ).asBoolean() ) {
writePropertyFile( serviceResourceDir, targetPath, propFile );
}
if ( propFile.has( ServiceAttributes.FileAttributes.deleteFile.json )
&& propFile.get( ServiceAttributes.FileAttributes.deleteFile.json ).asBoolean() ) {
csapApp.getPendingResourceDeletes().add( targetPath );
}
}
} );
logger.info( "Pending Operations: {}", csapApp.getPendingResourceOperations() );
}
示例12: decode
import com.fasterxml.jackson.databind.node.ArrayNode; //导入方法依赖的package包/类
@Override
public PortPairGroup decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
PortPairGroup.Builder resultBuilder = new DefaultPortPairGroup.Builder();
CoreService coreService = context.getService(CoreService.class);
String id = nullIsIllegal(json.get(ID),
ID + MISSING_MEMBER_MESSAGE).asText();
resultBuilder.setId(PortPairGroupId.of(id));
String tenantId = nullIsIllegal(json.get(TENANT_ID),
TENANT_ID + MISSING_MEMBER_MESSAGE).asText();
resultBuilder.setTenantId(TenantId.tenantId(tenantId));
String name = nullIsIllegal(json.get(NAME),
NAME + MISSING_MEMBER_MESSAGE).asText();
resultBuilder.setName(name);
String description = nullIsIllegal(json.get(DESCRIPTION),
DESCRIPTION + MISSING_MEMBER_MESSAGE).asText();
resultBuilder.setDescription(description);
List<PortPairId> list = Lists.newArrayList();
ArrayNode arrayNode = (ArrayNode) json.path(PORT_PAIRS);
arrayNode.forEach(i -> list.add(PortPairId.of(i.asText())));
resultBuilder.setPortPairs(list);
return resultBuilder.build();
}
示例13: decode
import com.fasterxml.jackson.databind.node.ArrayNode; //导入方法依赖的package包/类
@Override
public OpenstackSubnet decode(ObjectNode json, CodecContext context) {
checkNotNull(json);
JsonNode subnetInfo = json.get(SUBNET);
if (subnetInfo == null) {
subnetInfo = json;
}
String name = subnetInfo.path(NAME).asText();
boolean enableDhcp = subnetInfo.path(ENABLE_DHCP).asBoolean();
String networkId = subnetInfo.path(NETWORK_ID).asText();
String tenantId = subnetInfo.path(TENANT_ID).asText();
ArrayNode dnsNameservsers = (ArrayNode) subnetInfo.path(DNS_NAMESERVERS);
List<Ip4Address> dnsList = Lists.newArrayList();
if (dnsNameservsers != null && !dnsNameservsers.isMissingNode()) {
dnsNameservsers.forEach(dns -> dnsList.add(Ip4Address.valueOf(dns.asText())));
}
String gatewayIp = subnetInfo.path(GATEWAY_IP).asText();
String cidr = subnetInfo.path(CIDR).asText();
String id = subnetInfo.path(ID).asText();
OpenstackSubnet openstackSubnet = OpenstackSubnet.builder()
.setName(name)
.setEnableDhcp(enableDhcp)
.setNetworkId(networkId)
.setTenantId(tenantId)
.setDnsNameservers(dnsList)
.setGatewayIp(gatewayIp)
.setCidr(cidr)
.setId(id)
.build();
return openstackSubnet;
}
示例14: getList
import com.fasterxml.jackson.databind.node.ArrayNode; //导入方法依赖的package包/类
/**
* Gets the specified array property as a list of items.
*
* @param name property name
* @param function mapper from string to item
* @param defaultValue default value if property not set
* @param <T> type of item
* @return list of items
*/
protected <T> List<T> getList(String name, Function<String, T> function, List<T> defaultValue) {
List<T> list = Lists.newArrayList();
JsonNode jsonNode = object.path(name);
if (jsonNode.isMissingNode()) {
return defaultValue;
}
ArrayNode arrayNode = (ArrayNode) jsonNode;
arrayNode.forEach(i -> list.add(function.apply(i.asText())));
return list;
}
示例15: processes
import com.fasterxml.jackson.databind.node.ArrayNode; //导入方法依赖的package包/类
@RequestMapping ( "/processes" )
public ArrayNode processes ()
throws Exception {
ArrayNode processesGroupedByCommandPath = jacksonMapper.createArrayNode();
osManager.checkForProcessStatusUpdate();
ArrayNode processStatusItems = osManager.processStatus();
ObjectNode processKeys = jacksonMapper.createObjectNode();
ObjectNode rootKeys = jacksonMapper.createObjectNode();
processStatusItems.forEach( processAttributes -> {
String processCommandPath = "";
String[] params = processAttributes.get( "command" ).asText().split( " " );
if ( params.length >= 3 )
processCommandPath = params[2];
if ( processCommandPath.trim().length() == 0 ) {
// every process should have a command path - but just in case a
// parising error.
processCommandPath += "Pid: " + processAttributes.get( "pid" ).asText();
}
if ( !processKeys.has( processCommandPath ) ) {
ObjectNode keyItem = processesGroupedByCommandPath.addObject();
processKeys.set( processCommandPath, keyItem );
keyItem.put( "label", processCommandPath );
keyItem.putArray( "attributes" );
keyItem.put( "folder", true );
keyItem.put( "lazy", true );
}
ArrayNode keyList = (ArrayNode) processKeys.get( processCommandPath ).get( "attributes" );
keyList.add( processAttributes );
} );
return processesGroupedByCommandPath;
}