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


Java ArrayNode.size方法代碼示例

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


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

示例1: addToArray

import com.fasterxml.jackson.databind.node.ArrayNode; //導入方法依賴的package包/類
static JsonNode addToArray(final JsonPointer path, final JsonNode node, final JsonNode value) {
    final ArrayNode target = (ArrayNode) node.at(path.head());
    final String rawToken = path.last().getMatchingProperty();

    if (rawToken.equals(LAST_ARRAY_ELEMENT)) {
        target.add(value);
        return node;
    }

    final int size = target.size();
    final int index;
    try {
        index = Integer.parseInt(rawToken);
    } catch (NumberFormatException ignored) {
        throw new JsonPatchException("not an index: " + rawToken + " (expected: a non-negative integer)");
    }

    if (index < 0 || index > size) {
        throw new JsonPatchException("index out of bounds: " + index +
                                     " (expected: >= 0 && <= " + size + ')');
    }

    target.insert(index, value);
    return node;
}
 
開發者ID:line,項目名稱:centraldogma,代碼行數:26,代碼來源:AddOperation.java

示例2: generateNagiosPassiveMonitors

import com.fasterxml.jackson.databind.node.ArrayNode; //導入方法依賴的package包/類
static private String generateNagiosPassiveMonitors(String monitor, String host, String modelShortName) {

		StringBuilder nagiosHostServiceDefinition = new StringBuilder();
		nagiosHostServiceDefinition.append("\ndefine service{");
		nagiosHostServiceDefinition.append("\n\t use \t\t generic-service");
		nagiosHostServiceDefinition.append("\n\t host_name \t " + host);
		nagiosHostServiceDefinition.append("\n\t service_description \t  Csap_" + monitor);
		nagiosHostServiceDefinition.append("\n\t check_command \t  " + modelShortName + "_" + monitor);
		ArrayNode nagiosOptionsFromCsapDefn = getNagiosOptionsFromCsapDefn();
		if (nagiosOptionsFromCsapDefn != null && nagiosOptionsFromCsapDefn.size() > 0) {
			for (JsonNode configLine : nagiosOptionsFromCsapDefn) {
				if (configLine.asText().contains("active_checks_enabled"))
					continue;
				nagiosHostServiceDefinition.append("\n\t " + configLine.asText());
			}
		} else {
			nagiosHostServiceDefinition.append("\n\t passive_checks_enabled \t  1");
		}
		nagiosHostServiceDefinition.append("\n\t active_checks_enabled  \t  0");
		nagiosHostServiceDefinition.append("\n\t }\n\n");

		return nagiosHostServiceDefinition.toString();
	}
 
開發者ID:csap-platform,項目名稱:csap-core,代碼行數:24,代碼來源:NagiosIntegration.java

示例3: updateMetricData

import com.fasterxml.jackson.databind.node.ArrayNode; //導入方法依賴的package包/類
private ObjectNode updateMetricData(long nowMs, String hostName, ObjectNode testData) {
	ObjectNode data;
	data = testData.deepCopy(); // copy test data, modify it

	ObjectNode attNode = (ObjectNode) data.path( "attributes" );
	attNode.put( "hostName", hostName );
	attNode.put( "currentTimeMillis", nowMs );

	ArrayNode timeStamps = (ArrayNode) data.path( "data" ).path( "timeStamp" );
	for (int i = 0; i < timeStamps.size(); i++) {
		long offset = i * 30000; // timeStamps in reverse order LIFO. latest
									// time is first
		timeStamps.set( i, LongNode.valueOf( nowMs - offset ) );
	}
	return data;
}
 
開發者ID:csap-platform,項目名稱:csap-core,代碼行數:17,代碼來源:Agent_Capacity_Tests.java

示例4: string2Map

import com.fasterxml.jackson.databind.node.ArrayNode; //導入方法依賴的package包/類
/**
 * Десериализатор TreeNode массива в Map где четный элемент ключ а не четный
 * значение
 * 
 * @param <T>
 *            тип ключя карты
 * @param <V>
 *            тип значения карты
 * @param node
 *            узел
 * @param keyClass
 *            класс для ключа карты
 * @param valueClass
 *            класс для значения карты
 * @throws IOException
 *             исключение парсера
 * @return карта
 */
private static <T, V> Map<T, V> string2Map(TreeNode node, Class<T> keyClass, Class<V> valueClass)
		throws IOException {
	ObjectMapper mapper = new ObjectMapper();
	Map<T, V> ret = new HashMap<T, V>();
	if (node.isArray()) {
		T key = null;
		ArrayNode key2value = (ArrayNode) node;
		for (int i = 0; i < key2value.size(); i++) {
			if (i % 2 == 0) {
				key = mapper.treeToValue(key2value.get(i), keyClass);
			} else {
				V value = mapper.treeToValue(key2value.get(i), valueClass);
				ret.put(key, value);
			}
		}
	}
	return ret;
}
 
開發者ID:onixred,項目名稱:golos4j,代碼行數:37,代碼來源:Util.java

示例5: saveFiles

import com.fasterxml.jackson.databind.node.ArrayNode; //導入方法依賴的package包/類
protected void saveFiles(final ItemId itemId, File filesDir) throws IOException
{
	ObjectNode files = itemRequests.listFiles(itemId);
	ArrayNode fileList = files.withArray("files");
	if( fileList.size() > 0 )
	{
		filesDir.mkdirs();
		for( JsonNode file : fileList )
		{
			final String name = file.get("name").asText();
			ByteSource src = new ByteSource()
			{
				@Override
				public InputStream openStream() throws IOException
				{
					return itemRequests.file(itemRequests.successfulRequest(), itemId, name).body().asInputStream();
				}
			};
			File destFile = new File(filesDir, name);
			destFile.getParentFile().mkdirs();
			src.copyTo(Files.asByteSink(destFile));
		}
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:25,代碼來源:SaveInstitutionToFile.java

示例6: deserialize

import com.fasterxml.jackson.databind.node.ArrayNode; //導入方法依賴的package包/類
@Override
public Object deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
    throws IOException, JsonProcessingException {
  ObjectCodec oc = jsonParser.getCodec();
  JsonNode node = oc.readTree(jsonParser);
  if (node instanceof ArrayNode) {
    ArrayNode arrayNode = (ArrayNode) node;
    ArrayList<String> ret = new ArrayList<>();
    for (int i = 0; i < arrayNode.size(); i++) {
      ret.add(arrayNode.get(i).textValue());
    }
    return ret.toArray(new String[0]);
  } else {
    return new String[]{node.textValue()};
  }

}
 
開發者ID:pinterest,項目名稱:soundwave,代碼行數:18,代碼來源:StringArrayOrElementStringDeserializer.java

示例7: deserialize

import com.fasterxml.jackson.databind.node.ArrayNode; //導入方法依賴的package包/類
@Override
public Object deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
    throws IOException, JsonProcessingException {
  ObjectCodec oc = jsonParser.getCodec();
  JsonNode node = oc.readTree(jsonParser);
  if (node instanceof ArrayNode) {
    ArrayNode arrayNode = (ArrayNode) node;
    ArrayList<String> ret = new ArrayList<>();
    for (int i = 0; i < arrayNode.size(); i++) {
      ret.add(arrayNode.get(i).textValue());
    }
    return ret;
  } else {
    return Arrays.asList(node.textValue());
  }
}
 
開發者ID:pinterest,項目名稱:soundwave,代碼行數:17,代碼來源:StringListOrElementDeserializer.java

示例8: readList

import com.fasterxml.jackson.databind.node.ArrayNode; //導入方法依賴的package包/類
protected Object readList(ListSchema schema, JsonNode node) {
    List list = Lists.newArrayList();
    ArrayNode arrayNode = (ArrayNode) node;
    for (int i = 0; i < arrayNode.size(); i++) {
        JsonNode val = arrayNode.get(i);
        list.add(getNodeData(schema.getValueSchema(), val));
    }
    return list;
}
 
開發者ID:atlascon,項目名稱:travny,代碼行數:10,代碼來源:JsonReader.java

示例9: parseJson

import com.fasterxml.jackson.databind.node.ArrayNode; //導入方法依賴的package包/類
public Query parseJson(String queryName, ObjectNode fullQuery) throws QueryException {
	Query query = new Query(queryName, packageMetaData);
	if (fullQuery.has("defines")) {
		JsonNode defines = fullQuery.get("defines");
		if (defines instanceof ObjectNode) {
			parseDefines(query, (ObjectNode)fullQuery.get("defines"));
		} else {
			throw new QueryException("\"defines\" must be of type object");
		}
	}
	if (fullQuery.has("queries")) {
		JsonNode queriesNode = fullQuery.get("queries");
		if (queriesNode instanceof ArrayNode) {
			ArrayNode queries = (ArrayNode) fullQuery.get("queries");
			if (queries.size() == 0) {
				throw new QueryException("\"queries\" must contain at least one query");
			}
			for (int i=0; i<queries.size(); i++) {
				parseJsonQuery(query, (ObjectNode)queries.get(i));
			}
		} else {
			throw new QueryException("\"queries\" must be of type array");
		}
	} else if (fullQuery.has("query")) {
		JsonNode queryNode = fullQuery.get("query");
		if (queryNode instanceof ObjectNode) {
			parseJsonQuery(query, (ObjectNode) fullQuery.get("query"));
		} else {
			throw new QueryException("\"query\" must be of type object");
		}
	} else if (!fullQuery.has("defines")) {
		parseJsonQuery(query, fullQuery);
	}
	return query;
}
 
開發者ID:shenan4321,項目名稱:BIMplatform,代碼行數:36,代碼來源:JsonQueryObjectModelConverter.java

示例10: getInterfaces

import com.fasterxml.jackson.databind.node.ArrayNode; //導入方法依賴的package包/類
/**
 * Returns the list of interfaces enabled on this router.
 *
 * @return list of interface names that are enabled, or an empty list if
 * all available interfaces should be used
 */
public List<String> getInterfaces() {
    JsonNode intfNode = object.path(INTERFACES);
    if (intfNode.isMissingNode() || !intfNode.isArray()) {
        return Collections.emptyList();
    }
    ArrayNode array = (ArrayNode) intfNode;
    List<String> interfaces = new ArrayList<>(array.size());
    for (JsonNode intf : array) {
        interfaces.add(intf.asText());
    }
    return interfaces;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:19,代碼來源:RouterConfig.java

示例11: validateFilters

import com.fasterxml.jackson.databind.node.ArrayNode; //導入方法依賴的package包/類
private void validateFilters(JsonNode filtersJson) {
    if (filtersJson == null || filtersJson.isNull()) {
        throw new IncorrectParameterException("Rule filters are required!");
    }
    if (!filtersJson.isArray()) {
        throw new IncorrectParameterException("Filters json is not an array!");
    }
    ArrayNode filtersArray = (ArrayNode) filtersJson;
    for (int i = 0; i < filtersArray.size(); i++) {
        validateComponentJson(filtersArray.get(i), ComponentType.FILTER);
    }
}
 
開發者ID:osswangxining,項目名稱:iotplatform,代碼行數:13,代碼來源:BaseRuleService.java

示例12: getGroups

import com.fasterxml.jackson.databind.node.ArrayNode; //導入方法依賴的package包/類
@NotNull
private static ArrayNode getGroups(@NotNull JsonNode node) {
    @NotNull final ArrayNode groups = requireArrayValue(node, GROUPS_NAME);
    if (groups.size() == 0) {
        throw new RuntimeException("Value of groups is an empty array. At least one group is required.");
    }
    return groups;
}
 
開發者ID:mgrand,項目名稱:crypto-shuffle,代碼行數:9,代碼來源:JsonUtil.java

示例13: resolveArrayNode

import com.fasterxml.jackson.databind.node.ArrayNode; //導入方法依賴的package包/類
private JsonNode resolveArrayNode(LogEvent event, JsonNode srcNode) {
    ArrayNode dstNode = objectMapper.createArrayNode();
    for (int nodeIndex = 0; nodeIndex < srcNode.size(); nodeIndex++) {
        JsonNode srcChildNode = srcNode.get(nodeIndex);
        JsonNode dstChildNode = resolveNode(event, srcChildNode);
        if (dstChildNode != null) {
            dstNode.add(dstChildNode);
        }
    }
    return dstNode.size() > 0 ? dstNode : null;
}
 
開發者ID:vy,項目名稱:log4j2-logstash-layout,代碼行數:12,代碼來源:TemplateRenderer.java

示例14: removeSpeaker

import com.fasterxml.jackson.databind.node.ArrayNode; //導入方法依賴的package包/類
/**
 * Removes BGP speaker from configuration.
 *
 * @param speakerName BGP speaker name
 */
public void removeSpeaker(String speakerName) {
    ArrayNode speakersArray = (ArrayNode) object.get(SPEAKERS);

    for (int i = 0; i < speakersArray.size(); i++) {
        if (speakersArray.get(i).hasNonNull(NAME) &&
                speakersArray.get(i).get(NAME).asText().equals(speakerName)) {
            speakersArray.remove(i);
            return;
        }
    }
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:17,代碼來源:BgpConfig.java

示例15: handleTabbedFields

import com.fasterxml.jackson.databind.node.ArrayNode; //導入方法依賴的package包/類
private ObjectNode handleTabbedFields(ObjectMapper mapper, Field[] declaredFields, Map<Field, JsonNode> nodes) {
	Predicate<? super Field> checkTabAnnotation = field -> field.isAnnotationPresent(Tab.class);

	Comparator<? super Field> tabIndexComparator = (field1, field2) -> Integer
			.compare(field1.getAnnotation(Tab.class).index(), field2.getAnnotation(Tab.class).index());

	Comparator<? super Field> fieldIndexComparator = (entry1, entry2) -> {
		Index field1Index = entry1.getAnnotation(Index.class);
		Index field2Index = entry2.getAnnotation(Index.class);
		return Integer.compare((field1Index != null ? field1Index.value() : Integer.MAX_VALUE),
				field2Index != null ? field2Index.value() : Integer.MAX_VALUE);
	};

	Map<String, List<JsonNode>> groupedFieldsByTab = new LinkedHashMap<>();

	Arrays.stream(declaredFields).filter(checkTabAnnotation).sorted(fieldIndexComparator).sorted(tabIndexComparator)
			.forEach(field -> groupFieldsByTab(nodes, field, groupedFieldsByTab));

	ArrayNode tabs = mapper.createArrayNode();

	groupedFieldsByTab.entrySet().stream().forEachOrdered(tabElements -> {
		ObjectNode tabNode = mapper.createObjectNode();
		tabNode.put(KEY_TITLE, tabElements.getKey());
		ArrayNode tabItems = mapper.createArrayNode();
		tabElements.getValue().stream().forEach(tabItems::add);
		tabNode.set(KEY_ITEMS, tabItems);
		tabs.add(tabNode);
	});
	if (tabs.size() > 0) {
		ObjectNode tabsNode = mapper.createObjectNode();
		tabsNode.put(KEY_TYPE, KEY_TABS);
		tabsNode.set(KEY_TABS, tabs);
		return tabsNode;
	}
	return null;

}
 
開發者ID:JsonSchema-JavaUI,項目名稱:sf-java-ui,代碼行數:38,代碼來源:UiFormSchemaGenerator.java


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