List of usage examples for com.fasterxml.jackson.databind JsonNode elements
public Iterator<JsonNode> elements()
From source file:com.enitalk.configs.DateCache.java
public NavigableSet<DateTime> days(JsonNode tree, String tz, JsonNode teacherNode) { ConcurrentSkipListSet<DateTime> dates = new ConcurrentSkipListSet<>(); Iterator<JsonNode> els = tree.elements(); DateTimeZone dz = DateTimeZone.forID(tz); DateTimeFormatter hour = DateTimeFormat.forPattern("HH:mm").withZone(dz); DateTime today = DateTime.now().millisOfDay().setCopy(0); while (els.hasNext()) { JsonNode el = els.next();// w w w. ja va 2 s . co m String day = el.path("day").asText(); boolean plus = today.getDayOfWeek() > days.get(day); if (el.has("start") && el.has("end")) { DateTime start = hour.parseDateTime(el.path("start").asText()).dayOfMonth() .setCopy(today.getDayOfMonth()).monthOfYear().setCopy(today.getMonthOfYear()).year() .setCopy(today.getYear()).withDayOfWeek(days.get(day)).plusWeeks(plus ? 1 : 0); DateTime end = hour.parseDateTime(el.path("end").asText()).dayOfMonth() .setCopy(today.getDayOfMonth()).monthOfYear().setCopy(today.getMonthOfYear()).year() .setCopy(today.getYear()).withDayOfWeek(days.get(day)).plusWeeks(plus ? 1 : 0); Hours hours = Hours.hoursBetween(start, end); int hh = hours.getHours() + 1; while (hh-- > 0) { dates.add(start.plusHours(hh).toDateTime(DateTimeZone.UTC)); } } else { List<String> datesAv = jackson.convertValue(el.path("times"), List.class); logger.info("Array of dates {} {}", datesAv, day); datesAv.forEach((String dd) -> { DateTime date = hour.parseDateTime(dd).dayOfMonth().setCopy(today.getDayOfMonth()).monthOfYear() .setCopy(today.getMonthOfYear()).year().setCopy(today.getYear()) .withDayOfWeek(days.get(day)).plusWeeks(plus ? 1 : 0); dates.add(date.toDateTime(DateTimeZone.UTC)); }); } } final TreeSet<DateTime> addWeek = new TreeSet<>(); for (int i = 1; i < 2; i++) { for (DateTime e : dates) { addWeek.add(e.plusWeeks(i)); } } dates.addAll(addWeek); DateTime nowUtc = DateTime.now().toDateTime(DateTimeZone.UTC); nowUtc = nowUtc.plusHours(teacherNode.path("notice").asInt(2)); NavigableSet<DateTime> ss = dates.tailSet(nowUtc, true); return ss; }
From source file:com.spankingrpgs.scarletmoon.characters.CrimsonGameCharacter.java
private void loadAttackRanges(JsonNode attackRangesNode) { List<CombatRange> attackRanges = new ArrayList<>(); Iterator<JsonNode> attackRangeElements = attackRangesNode.elements(); while (attackRangeElements.hasNext()) { attackRanges.add(CombatRange.valueOf(attackRangeElements.next().asText().trim())); }/*w w w.j a va 2 s . c o m*/ setAttackRanges(attackRanges); }
From source file:com.sitewhere.server.asset.scim.Wso2ScimAssetModule.java
/** * Parse email fields.// w w w. j a v a 2 s .c o m * * @param resource * @param asset */ protected void parseEmail(JsonNode resource, PersonAsset asset) { JsonNode emails = resource.get(IScimFields.EMAILS); if (emails != null) { int index = 1; Iterator<JsonNode> it = emails.elements(); while (it.hasNext()) { String email = it.next().textValue(); asset.setProperty("emailAddress" + index, email); } } }
From source file:com.spotify.ffwd.json.JsonObjectMapperDecoder.java
private Set<String> decodeTags(JsonNode tree, String name) { final JsonNode n = tree.get(name); if (n == null) return EMPTY_TAGS; if (n.getNodeType() != JsonNodeType.ARRAY) return EMPTY_TAGS; final List<String> tags = Lists.newArrayList(); final Iterator<JsonNode> iter = n.elements(); while (iter.hasNext()) tags.add(iter.next().asText());//from w w w. ja va 2 s.com return Sets.newHashSet(tags); }
From source file:com.unboundid.scim2.common.utils.FilterEvaluator.java
/** * Return true if the node is either {@code null} or an empty array. * @param node node to examine// w w w .j a va 2 s .c om * @return boolean */ private boolean isEmpty(final JsonNode node) { if (node.isArray()) { Iterator<JsonNode> iterator = node.elements(); while (iterator.hasNext()) { if (!isEmpty(iterator.next())) { return false; } } return true; } else { return node.isNull(); } }
From source file:com.unboundid.scim2.server.utils.ResourceComparator.java
/** * Retrieve the value of a complex multi-valued attribute that is marked as * primary or the first value in the list. If the provided node is not an * array node, then just return the provided node. * * @param node The JsonNode to retrieve from. * @return The primary or first value or {@code null} if the provided array * node is empty.//from w w w . jav a 2s.c o m */ private JsonNode getPrimaryOrFirst(final JsonNode node) { // if it's a multi-valued attribute (see Section 2.4 // [I-D.ietf - scim - core - schema]), if any, or else the first value in // the list, if any. if (!node.isArray()) { return node; } if (node.size() == 0) { return null; } Iterator<JsonNode> i = node.elements(); while (i.hasNext()) { JsonNode value = i.next(); JsonNode primary = value.get("primary"); if (primary != null && primary.booleanValue()) { return value; } } return node.get(0); }
From source file:kz.nurlan.kaspandr.KaspandrWindow.java
private HashMap<String, ArrayNode> groupByLessonsByGroup(String lessons) { HashMap<String, ArrayNode> groupMap = new HashMap<String, ArrayNode>(); try {/*w ww. j a v a 2 s . co m*/ ObjectNode rootNode1 = mapper.readValue("{\"lessons\":[" + lessons + "]}", ObjectNode.class); JsonNode lessonsNode1 = rootNode1.get("lessons"); if (lessonsNode1 != null && lessonsNode1.isArray()) { Iterator<JsonNode> it = lessonsNode1.elements(); while (it.hasNext()) { JsonNode lesson = it.next(); if (lesson.get("id") != null && !lesson.get("status").textValue().equalsIgnoreCase("deleted") && lesson.get("group") != null && !lesson.get("group").textValue().isEmpty()) { if (groupMap.containsKey(lesson.get("group").textValue())) groupMap.put(lesson.get("group").textValue(), groupMap.get(lesson.get("group").textValue()).add(lesson)); else { groupMap.put(lesson.get("group").textValue(), mapper.createArrayNode().add(lesson)); } } } } } catch (Exception e) { e.printStackTrace(); } return groupMap; }
From source file:utils.Dataset.java
public static JsonNode addDatasetIDtoImpactAnalysisResult(JsonNode impacts) { if (impacts == null || (!impacts.isArray())) { return impacts; }// ww w . ja v a2s .c om try { Map<String, Integer> urnIDMap = new HashMap<String, Integer>(); if (getChacheInstance().get("URNIDMAPKey") != null) { urnIDMap = (Map<String, Integer>) getChacheInstance().get("URNIDMAPKey"); } else { FileReader fr = new FileReader("/var/tmp/wherehows/resource/dataset_urn_list.txt"); BufferedReader br = new BufferedReader(fr); String line; while ((line = br.readLine()) != null) { String record = line.substring(0, line.length()); String[] values = record.split("\t"); if (values != null && values.length == 2) { String urn = values[0]; Integer id = Integer.parseInt(values[1]); if (StringUtils.isNotBlank(urn) && id != null && id != 0) { urnIDMap.put(urn, id); } } } if (urnIDMap != null && urnIDMap.size() > 0) { getChacheInstance().set(URNIDMAPKey, urnIDMap); } } if (urnIDMap != null && urnIDMap.size() > 0) { Iterator<JsonNode> arrayIterator = impacts.elements(); if (arrayIterator != null) { while (arrayIterator.hasNext()) { JsonNode node = arrayIterator.next(); if (node.isContainerNode() && node.has("urn")) { String urn = node.get("urn").asText(); ObjectNode objectNode = (ObjectNode) node; int index = urn.lastIndexOf("/"); String name = urn.substring(index + 1); objectNode.put("name", name); if (urnIDMap.containsKey(urn)) { Integer id = urnIDMap.get(urn); objectNode.put("id", id); } } } } } } catch (Exception e) { Logger.error(e.getMessage()); } return impacts; }
From source file:com.jaspersoft.studio.data.querydesigner.json.JsonDataManager.java
public List<JsonSupportNode> getSelectableNodes(String query) { List<JsonSupportNode> selectedList = new ArrayList<JsonSupportNode>(); JsonQueryHelper jsonQueryHelper = new JsonQueryHelper(mapper); try {/*w w w. j a va 2 s . com*/ JsonNode jsonData = jsonQueryHelper.getJsonData(jsonRoot, query); if (jsonData != null) { List<JsonNode> elementsList = new ArrayList<JsonNode>(); if (jsonData.isArray()) { Iterator<JsonNode> elements = jsonData.elements(); while (elements.hasNext()) { elementsList.add(elements.next()); } } else if (jsonData.isObject()) { elementsList.add(jsonData); } for (JsonSupportNode sn : getJsonNodesMap().keySet()) { if (elementsList.contains(getJsonNodesMap().get(sn))) { selectedList.add(sn); } } } } catch (JRException e) { // Do not care about error in node selection } return selectedList; }