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


Java ArrayNode.forEach方法代碼示例

本文整理匯總了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();
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:39,代碼來源:FlowsWebResource.java

示例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;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:30,代碼來源:OpenstackInterfaceManager.java

示例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;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:28,代碼來源:OpenstackInterfaceManager.java

示例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;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:24,代碼來源:OpenstackInterfaceManager.java

示例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;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:27,代碼來源:OpenstackInterfaceManager.java

示例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);
    }
}
 
開發者ID:spring-sprout,項目名稱:osoon,代碼行數:17,代碼來源:MeetingUpdateService.java

示例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);
    }
}
 
開發者ID:spring-sprout,項目名稱:osoon,代碼行數:17,代碼來源:MeetingUpdateService.java

示例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)));
    });
}
 
開發者ID:andreschaffer,項目名稱:event-sourcing-cqrs-examples,代碼行數:11,代碼來源:ClientAccountsIT.java

示例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 ;
}
 
開發者ID:csap-platform,項目名稱:csap-core,代碼行數:28,代碼來源:ActiveUsers.java

示例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;
}
 
開發者ID:csap-platform,項目名稱:csap-core,代碼行數:11,代碼來源:DefinitionRequests.java

示例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() );
	}
 
開發者ID:csap-platform,項目名稱:csap-core,代碼行數:41,代碼來源:DefinitionRequests.java

示例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();
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:34,代碼來源:PortPairGroupCodec.java

示例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;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:34,代碼來源:OpenstackSubnetCodec.java

示例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;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:20,代碼來源:Config.java

示例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;
}
 
開發者ID:csap-platform,項目名稱:csap-core,代碼行數:44,代碼來源:ExplorerRequests.java


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