com.fasterxml.jackson.databind.node.ArrayNode#iterator ( )源码实例Demo

下面列出了com.fasterxml.jackson.databind.node.ArrayNode#iterator ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

private List<GraphLabelV0> getLabels(final JsonNode jnode, final String position) {
    List<GraphLabelV0> labelList = new ArrayList<>();
    if (jnode.has(position)) {
        final ArrayNode labelsNode = (ArrayNode) jnode.get(position);
        final Iterator<JsonNode> it = labelsNode.iterator();
        while (it.hasNext()) {
            final JsonNode lnode = it.next();
            final String attr = lnode.get(GraphLabelsAndDecoratorsV0.FIELD_ATTR).textValue();
            final String color = lnode.get(GraphLabelsAndDecoratorsV0.FIELD_COLOR).textValue();
            final float radius = lnode.has(GraphLabelsAndDecoratorsV0.FIELD_RADIUS) ? (float) lnode.get(GraphLabelsAndDecoratorsV0.FIELD_RADIUS).asDouble() : 1f;

            final GraphLabelV0 label = new GraphLabelV0(attr, ConstellationColor.getColorValue(color), radius);
            labelList.add(label);
        }
    }
    return labelList;
}
 
源代码2 项目: arctic-sea   文件: AbstractJSONDecoder.java
protected PT_FreeText parseFreeText(JsonNode n) {
    LocalisedCharacterString localisedCharacterString = new LocalisedCharacterString("");
    if (n.isArray()) {
        ArrayNode arrayNode = (ArrayNode) n;
        Iterator<JsonNode> it = arrayNode.iterator();
        while (it.hasNext()) {
            final JsonNode next = it.next();
            checkAndAddTextAndLanguage(next, localisedCharacterString);
        }
    } else if (n.isTextual()) {
        localisedCharacterString.setValue(n.asText());
    } else if (n.isObject()) {
        checkAndAddTextAndLanguage(n, localisedCharacterString);
    }
    return new PT_FreeText().addTextGroup(localisedCharacterString);
}
 
public static boolean arrayNodeContains(ArrayNode arrayNode, Object value) {
    Iterator<JsonNode> iterator = arrayNode.iterator();
    while (iterator.hasNext()) {
        JsonNode jsonNode = iterator.next();
        if (value == null && jsonNode.isNull()) {
            return true;
        } else if (value != null) {
            if (value instanceof String && jsonNode.isTextual() && StringUtils.equals(jsonNode.asText(), (String) value)) {
                return true;
            } else if (value instanceof Number && jsonNode.isLong() && jsonNode.longValue() == ((Number) value).longValue()) {
                return true;
            } else if (value instanceof Number && jsonNode.isDouble() && jsonNode.doubleValue() == ((Number) value).doubleValue()) {
                return true;
            } else if (value instanceof Number && jsonNode.isInt() && jsonNode.intValue() == ((Number) value).intValue()) {
                return true;
            } else if (value instanceof Boolean && jsonNode.isBoolean() && jsonNode.booleanValue() == ((Boolean) value).booleanValue()) {
                return true;
            }
        }
    }   
    return false;
}
 
源代码4 项目: streams   文件: PropertyUtil.java
/**
 * clean an array.
 * @param content ArrayNode
 * @return cleaned ArrayNode
 */
private static ArrayNode cleanArray(ArrayNode content) {
  if( content.size() == 0) return null;
  Iterator<JsonNode> items = content.iterator();
  for ( ; items.hasNext(); ) {
    JsonNode item = items.next();
    if( item == null ) items.remove();
    if( item.getNodeType().equals(JsonNodeType.OBJECT)) {
      if( item.size() == 0 ) items.remove();
    }
    if( item.getNodeType().equals(JsonNodeType.ARRAY)) {
      if( item.size() == 0 ) items.remove();
    }
  }
  if( content.size() == 0) return null;
  else return content;
}
 
源代码5 项目: deptective   文件: ConfigParser.java
private List<String> parseReads(ArrayNode arrayNode) {
    if (arrayNode == null) {
        return Collections.emptyList();
    }

    Iterator<JsonNode> it = arrayNode.iterator();
    List<String> packages = new ArrayList<>();

    while (it.hasNext()) {
        packages.add(it.next().asText());
    }

    return packages;
}
 
源代码6 项目: deptective   文件: ConfigParser.java
private List<PackagePattern> parseContains(ArrayNode arrayNode) {
    if (arrayNode == null) {
        return Collections.emptyList();
    }

    Iterator<JsonNode> it = arrayNode.iterator();
    List<PackagePattern> components = new ArrayList<>();

    while (it.hasNext()) {
        components.add(PackagePattern.getPattern(it.next().asText()));
    }

    return components;
}
 
源代码7 项目: activiti6-boot2   文件: JsonConverterUtil.java
protected static void internalGetBpmnProcessChildShapePropertyValues(JsonNode editorJsonNode, String propertyName, 
    List<String> allowedStencilTypes, List<JsonLookupResult> result) {
  
  JsonNode childShapesNode = editorJsonNode.get("childShapes");
  if (childShapesNode != null && childShapesNode.isArray()) {
    ArrayNode childShapesArrayNode = (ArrayNode) childShapesNode;
    Iterator<JsonNode> childShapeNodeIterator = childShapesArrayNode.iterator();
    while (childShapeNodeIterator.hasNext()) {
      JsonNode childShapeNode = childShapeNodeIterator.next();
      
      String childShapeNodeStencilId = BpmnJsonConverterUtil.getStencilId(childShapeNode);
      boolean readPropertiesNode = allowedStencilTypes.contains(childShapeNodeStencilId);

      if (readPropertiesNode) {
        // Properties
        JsonNode properties = childShapeNode.get("properties");
        if (properties != null && properties.has(propertyName)) {
          JsonNode nameNode = properties.get("name");
          JsonNode propertyNode = properties.get(propertyName);
          result.add(new JsonLookupResult(BpmnJsonConverterUtil.getElementId(childShapeNode), 
                  nameNode != null ? nameNode.asText() : null, propertyNode));
        }
      }

      // Potential nested child shapes
      if (childShapeNode.has("childShapes")) {
        internalGetBpmnProcessChildShapePropertyValues(childShapeNode, propertyName, allowedStencilTypes, result);
      }

    }
  }
}
 
源代码8 项目: activiti6-boot2   文件: JsonConverterUtil.java
public static List<JsonNode> getAppModelReferencedProcessModels(JsonNode appModelJson) {
  List<JsonNode> result = new ArrayList<JsonNode>();
  if (appModelJson.has("models")) {
    ArrayNode modelsArrayNode = (ArrayNode) appModelJson.get("models");
    Iterator<JsonNode> modelArrayIterator = modelsArrayNode.iterator();
    while (modelArrayIterator.hasNext()) {
      result.add(modelArrayIterator.next());
    }
  }
  return result;
}
 
源代码9 项目: deptective   文件: ConfigParser.java
private List<String> parseReads(ArrayNode arrayNode) {
    if (arrayNode == null) {
        return Collections.emptyList();
    }

    Iterator<JsonNode> it = arrayNode.iterator();
    List<String> packages = new ArrayList<>();

    while (it.hasNext()) {
        packages.add(it.next().asText());
    }

    return packages;
}
 
源代码10 项目: deptective   文件: ConfigParser.java
private List<PackagePattern> parseContains(ArrayNode arrayNode) {
    if (arrayNode == null) {
        return Collections.emptyList();
    }

    Iterator<JsonNode> it = arrayNode.iterator();
    List<PackagePattern> components = new ArrayList<>();

    while (it.hasNext()) {
        components.add(PackagePattern.getPattern(it.next().asText()));
    }

    return components;
}
 
源代码11 项目: intellij-swagger   文件: JsonBuilderService.java
private void handleArrayNode(
    final ArrayNode root, final VirtualFile containingFile, final VirtualFile specFile) {
  final Iterator<JsonNode> iterator = root.iterator();
  int index = 0;

  while (iterator.hasNext()) {
    final JsonNode current = iterator.next();
    final JsonNode ref = current.get(SwaggerConstants.REF_KEY);

    if (ref != null && ref.isTextual()) {
      consumeRef((TextNode) ref, containingFile, new ArrayNodeConsumer(root, index), specFile);
    }
    index++;
  }
}
 
protected static void internalGetCmmnChildShapePropertyValues(JsonNode editorJsonNode, String propertyName,
        List<String> allowedStencilTypes, List<JsonLookupResult> result) {

    JsonNode childShapesNode = editorJsonNode.get("childShapes");
    if (childShapesNode != null && childShapesNode.isArray()) {
        ArrayNode childShapesArrayNode = (ArrayNode) childShapesNode;
        Iterator<JsonNode> childShapeNodeIterator = childShapesArrayNode.iterator();
        while (childShapeNodeIterator.hasNext()) {
            JsonNode childShapeNode = childShapeNodeIterator.next();

            String childShapeNodeStencilId = CmmnJsonConverterUtil.getStencilId(childShapeNode);
            boolean readPropertiesNode = allowedStencilTypes.contains(childShapeNodeStencilId);

            if (readPropertiesNode) {
                // Properties
                JsonNode properties = childShapeNode.get("properties");
                if (properties != null && properties.has(propertyName)) {
                    JsonNode nameNode = properties.get("name");
                    JsonNode propertyNode = properties.get(propertyName);
                    result.add(new JsonLookupResult(CmmnJsonConverterUtil.getElementId(childShapeNode),
                            nameNode != null ? nameNode.asText() : null, propertyNode));
                }
            }

            // Potential nested child shapes
            if (childShapeNode.has("childShapes")) {
                internalGetCmmnChildShapePropertyValues(childShapeNode, propertyName, allowedStencilTypes, result);
            }

        }
    }
}
 
源代码13 项目: flowable-engine   文件: DmnJsonConverterUtil.java
protected static void internalGetDmnChildShapePropertyValues(JsonNode editorJsonNode, String propertyName,
    List<String> allowedStencilTypes, List<JsonLookupResult> result) {

    JsonNode childShapesNode = editorJsonNode.get("childShapes");
    if (childShapesNode != null && childShapesNode.isArray()) {
        ArrayNode childShapesArrayNode = (ArrayNode) childShapesNode;
        Iterator<JsonNode> childShapeNodeIterator = childShapesArrayNode.iterator();
        while (childShapeNodeIterator.hasNext()) {
            JsonNode childShapeNode = childShapeNodeIterator.next();

            String childShapeNodeStencilId = DmnJsonConverterUtil.getStencilId(childShapeNode);
            boolean readPropertiesNode = allowedStencilTypes.contains(childShapeNodeStencilId);

            if (readPropertiesNode) {
                // Properties
                JsonNode properties = childShapeNode.get("properties");
                if (properties != null && properties.has(propertyName)) {
                    JsonNode nameNode = properties.get("name");
                    JsonNode propertyNode = properties.get(propertyName);
                    result.add(new JsonLookupResult(DmnJsonConverterUtil.getElementId(childShapeNode),
                        nameNode != null ? nameNode.asText() : null, propertyNode));
                }
            }

            // Potential nested child shapes
            if (childShapeNode.has("childShapes")) {
                internalGetDmnChildShapePropertyValues(childShapeNode, propertyName, allowedStencilTypes, result);
            }

        }
    }
}
 
源代码14 项目: flowable-engine   文件: JsonConverterUtil.java
protected static void internalGetBpmnProcessChildShapePropertyValues(JsonNode editorJsonNode, String propertyName,
        List<String> allowedStencilTypes, List<JsonLookupResult> result) {

    JsonNode childShapesNode = editorJsonNode.get("childShapes");
    if (childShapesNode != null && childShapesNode.isArray()) {
        ArrayNode childShapesArrayNode = (ArrayNode) childShapesNode;
        Iterator<JsonNode> childShapeNodeIterator = childShapesArrayNode.iterator();
        while (childShapeNodeIterator.hasNext()) {
            JsonNode childShapeNode = childShapeNodeIterator.next();

            String childShapeNodeStencilId = BpmnJsonConverterUtil.getStencilId(childShapeNode);
            boolean readPropertiesNode = allowedStencilTypes.contains(childShapeNodeStencilId);

            if (readPropertiesNode) {
                // Properties
                JsonNode properties = childShapeNode.get("properties");
                if (properties != null && properties.has(propertyName)) {
                    JsonNode nameNode = properties.get("name");
                    JsonNode propertyNode = properties.get(propertyName);
                    result.add(new JsonLookupResult(BpmnJsonConverterUtil.getElementId(childShapeNode),
                            nameNode != null ? nameNode.asText() : null, propertyNode));
                }
            }

            // Potential nested child shapes
            if (childShapeNode.has("childShapes")) {
                internalGetBpmnProcessChildShapePropertyValues(childShapeNode, propertyName, allowedStencilTypes, result);
            }

        }
    }
}
 
源代码15 项目: flowable-engine   文件: JsonConverterUtil.java
public static List<JsonNode> getAppModelReferencedProcessModels(JsonNode appModelJson) {
    List<JsonNode> result = new ArrayList<>();
    if (appModelJson.has("models")) {
        ArrayNode modelsArrayNode = (ArrayNode) appModelJson.get("models");
        Iterator<JsonNode> modelArrayIterator = modelsArrayNode.iterator();
        while (modelArrayIterator.hasNext()) {
            result.add(modelArrayIterator.next());
        }
    }
    return result;
}
 
源代码16 项目: walkmod-core   文件: RemoveModulesYMLAction.java
@Override
public void doAction(JsonNode node) throws Exception {
	if (node.has("modules")) {
		JsonNode aux = node.get("modules");
		ObjectMapper mapper = provider.getObjectMapper();
		if (aux.isArray()) {
			ArrayNode modulesList = (ArrayNode) node.get("modules");
			Iterator<JsonNode> it = modulesList.iterator();
			ArrayNode newModulesList = new ArrayNode(mapper.getNodeFactory());
			while (it.hasNext()) {
				JsonNode next = it.next();
				if (next.isTextual()) {
					String text = next.asText();
					if (!modules.contains(text)) {
						newModulesList.add(text);
					}
				}
			}
			ObjectNode oNode = (ObjectNode) node;
			if (newModulesList.size() > 0) {
				oNode.set("modules", newModulesList);
			} else {
				oNode.remove("modules");
			}
			provider.write(node);
		}
	}
}
 
源代码17 项目: scava   文件: MetricVisualisation.java
public byte[] getSparky(DB db, BasicDBObject query) throws IOException, ParseException, UnsparkableVisualisationException {
	
	if (vis.get("timeSeries") == null || !vis.get("timeSeries").asBoolean()) {
		throw new UnsparkableVisualisationException();
	}
	
	if (vis.get("series") != null) {
		throw new UnsparkableVisualisationException();
	}
	
	if (vis.get("y").getNodeType().equals(JsonNodeType.ARRAY)) {
		throw new UnsparkableVisualisationException();
	}
	
	ObjectMapper mapper = new ObjectMapper();
	ObjectNode visualisation = mapper.createObjectNode();
	chart.completeFields(visualisation, vis);
	
	String xColName = vis.get("x").asText();
	String yColName = vis.get("y").asText();
	yColName = yColName.replace("\"", "");
	
	DBCollection collection = getCollection(db); 
	
	ArrayNode datatable = chart.createDatatable(vis.get("datatable"), collection, query);
	Iterator<JsonNode> it = datatable.iterator();
	
	List<Date> xdata = new ArrayList<>();
	List<Double> ydata = new ArrayList<>(); // FIXME: This is hardcoded to Doubles
	
	SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
	
	while (it.hasNext()) {
		JsonNode obj = it.next();
		
		Date x = format.parse(obj.get(xColName).asText());
		xdata.add(x);

		Double y = obj.path(yColName).asDouble();
		ydata.add(y);
	}
	
	if (xdata.isEmpty()) {
		sparkData = mapper.createObjectNode();
		sparkData.put("id", vis.path("id").textValue());
		sparkData.put("name", vis.path("name").textValue());
		sparkData.put("description", vis.path("description").textValue());
		sparkData.put("status", "error");
		sparkData.put("msg", "No data for metric.");
		return null;
	}
		
	// Spark config
	int height = 60;
	int width = 300;
	int padding = 12;
	
	// FIXME: Actually, for SCAVA sparklines, they HAVE to have 
	// Date as the X-axis! 
	DateDimension xdim = new DateDimension(xdata, width-padding, padding);
	LinearDimension ydim = new LinearDimension(ydata, height-padding, padding);
	
	Sparkle sparkle = new Sparkle(height, width, padding);
	sparkle.setHeadless(true);

	byte[] bytes = sparkle.renderToByteArray(xdim, ydim);
	
	DateFormat outputDateFormat = new SimpleDateFormat("dd/MM/yy");
	
	// Set the spark data
	sparkData = mapper.createObjectNode();
	sparkData.put("status", "ok");
	sparkData.put("id", vis.path("id").textValue());
	sparkData.put("name", vis.path("name").textValue());
	sparkData.put("description", vis.path("description").textValue());
	sparkData.put("low", ydim.getMinValue());
	sparkData.put("high", ydim.getMaxValue());
	sparkData.put("first", ydata.get(0));
	sparkData.put("last", ydata.get(ydata.size()-1));
	sparkData.put("firstDate", outputDateFormat.format(xdata.get(0)));
	sparkData.put("lastDate", outputDateFormat.format(xdata.get(xdata.size()-1)));
	sparkData.put("months", (int)((xdata.get(xdata.size()-1).getTime() - xdata.get(0).getTime())/(365.24 * 24 * 60 * 60 * 1000 / 12)));
	
	return bytes;
}
 
源代码18 项目: walkmod-core   文件: RemoveProvidersYMLAction.java
@Override
public void doAction(JsonNode node) throws Exception {
	HashSet<String> providerSet = new HashSet<String>();
	for (String elem : providers) {
		String[] partsType = elem.split(":");
		if (partsType.length == 1) {
			elem = "org.walkmod:walkmod-" + elem + "-plugin:" + elem;
		}
		if (partsType.length != 3 && partsType.length != 1) {
			throw new TransformerException("Invalid conf-provider");
		}
		providerSet.add(elem);
	}
	if (node.has("conf-providers")) {
		JsonNode aux = node.get("conf-providers");
		if (aux.isArray()) {
			ArrayNode providersList = (ArrayNode) node.get("conf-providers");
			Iterator<JsonNode> it = providersList.iterator();
			ArrayNode newProvidersList = new ArrayNode(provider.getObjectMapper().getNodeFactory());
			while (it.hasNext()) {
				JsonNode next = it.next();
				if (next.isObject()) {
					String type = next.get("type").asText();
					String[] parts = type.split(":");
					if (parts.length == 1) {
						type = "org.walkmod:walkmod-" + type + "-plugin:" + type;
					} else if (parts.length != 3) {
						throw new TransformerException("Invalid conf-provider");
					}
					if (!providerSet.contains(type)) {
						newProvidersList.add(next);
					}
				}
			}
			ObjectNode oNode = (ObjectNode) node;
			if (newProvidersList.size() > 0) {
				oNode.set("conf-providers", newProvidersList);
			} else {
				oNode.remove("conf-providers");
			}
			provider.write(node);
		}
	}

}
 
源代码19 项目: walkmod-core   文件: RemoveProvidersYMLAction.java
@Override
public void doAction(JsonNode node) throws Exception {
	HashSet<String> providerSet = new HashSet<String>();
	for (String elem : providers) {
		String[] partsType = elem.split(":");
		if (partsType.length == 1) {
			elem = "org.walkmod:walkmod-" + elem + "-plugin:" + elem;
		}
		if (partsType.length != 3 && partsType.length != 1) {
			throw new TransformerException("Invalid conf-provider");
		}
		providerSet.add(elem);
	}
	if (node.has("conf-providers")) {
		JsonNode aux = node.get("conf-providers");
		if (aux.isArray()) {
			ArrayNode providersList = (ArrayNode) node.get("conf-providers");
			Iterator<JsonNode> it = providersList.iterator();
			ArrayNode newProvidersList = new ArrayNode(provider.getObjectMapper().getNodeFactory());
			while (it.hasNext()) {
				JsonNode next = it.next();
				if (next.isObject()) {
					String type = next.get("type").asText();
					String[] parts = type.split(":");
					if (parts.length == 1) {
						type = "org.walkmod:walkmod-" + type + "-plugin:" + type;
					} else if (parts.length != 3) {
						throw new TransformerException("Invalid conf-provider");
					}
					if (!providerSet.contains(type)) {
						newProvidersList.add(next);
					}
				}
			}
			ObjectNode oNode = (ObjectNode) node;
			if (newProvidersList.size() > 0) {
				oNode.set("conf-providers", newProvidersList);
			} else {
				oNode.remove("conf-providers");
			}
			provider.write(node);
		}
	}

}
 
源代码20 项目: kieker   文件: JsonArrayValueDeserializer.java
/**
 * Constructor for a serializer.
 *
 * @param array
 *            input array node
 */
protected JsonArrayValueDeserializer(final ArrayNode array) {
	this.values = array.iterator();
}