throw new IllegalArgumentException("Sub tag param was null. Super tag: " + superTag); if (superTag.getName().equals(subTag.getName())) return true; for (TagModel currentTag : currentSet) for (TagModel parent : currentTag.getDesignatedByTags()) { if (superTag.equals(parent)) return true;
private void getDescendantTags(TagModel tag, Set<TagModel> putResultsHere) { for (TagModel childTag : tag.getDesignatedTags()) { if (!putResultsHere.add(childTag)) continue; // Already visited. getDescendantTags(childTag, putResultsHere); } }
/** * Creates and returns the TagModel in a graph as per given Tag; * recursively creates the designated ("contained") tags. * <p> * If the Tag was already processed exists, returns the corresponding TagModel. * Doesn't check if the TagModel for given tag name already exists, assuming this method is only called once. */ private TagModel feedTagStructureToGraph(Tag tag, Set<Tag> visited, int level) { if (visited.contains(tag)) return this.getUniqueByProperty(TagModel.PROP_NAME, tag.getName(), true); visited.add(tag); LOG.fine(String.format("Creating TagModel for Tag: %s%s(%d) '%s' traits: %s", StringUtils.repeat(' ', level*2), tag.getName(), tag.getContainedTags().size(), tag.getTitle(), tag.getTraits())); TagModel tagModel = this.create(); tagModel.setName(tag.getName()); tagModel.setTitle(tag.getTitle()); tagModel.setColor(tag.getColor()); tagModel.setRoot(tag.isPrime()); tagModel.setPseudo(tag.isPseudo()); if (null != tag.getTraits()) tagModel.putAllTraits(tag.getTraits()); tag.getContainedTags().forEach(tag2 -> { TagModel tag2model = feedTagStructureToGraph(tag2, visited, level+1); tagModel.addDesignatedTag(tag2model); }); return tagModel; }
final Map<String, Integer> totals = new HashMap<>(); for (TagModel sectorTag : sectorsHolderTag.getDesignatedTags()) for (TagModel techTag : sectorTag.getDesignatedTags()) String tagName = techTag.getName();
/** * Translates the placement tags (labels) to their normalized real tag counterparts. Returns a 2-item array; index 0 has the normal names, index 1 * the placement names. * * Due to bad design, the rules contain column and row titles for the graph, rather than technology tags. To make them fit into the tag system, * this translation is needed. See also the "place:..." tags in the report hierarchy definition. */ private static Set<String> getPlacementTags(GraphContext graphContext, Set<String> potentialPlaceTags) { final TagGraphService tagService = new TagGraphService(graphContext); Set<String> placeNames = new HashSet<>(); potentialPlaceTags.forEach(name -> { final TagModel placeTag = tagService.getTagByName("place:" + Tag.normalizeName(name)); if (null != placeTag) placeNames.add(placeTag.getName()); }); return placeNames; }
/** * Returns a single parent of the given tag. If there are multiple parents, throws a WindupException. */ public static TagModel getSingleParent(TagModel tag) { final Iterator<TagModel> parents = tag.getDesignatedByTags().iterator(); if (!parents.hasNext()) throw new WindupException("Tag is not designated by any tags: " + tag); final TagModel maybeOnlyParent = parents.next(); if (parents.hasNext()) { StringBuilder sb = new StringBuilder(); tag.getDesignatedByTags().iterator().forEachRemaining(x -> sb.append(x).append(", ")); throw new WindupException(String.format("Tag %s is designated by multiple tags: %s", tag, sb.toString())); } return maybeOnlyParent; } }
/** * Creates and returns the TagModel in a graph as per given Tag; * recursively creates the designated ("contained") tags. * <p> * If the Tag was already processed exists, returns the corresponding TagModel. * Doesn't check if the TagModel for given tag name already exists, assuming this method is only called once. */ private TagModel feedTagStructureToGraph(Tag tag, Set<Tag> visited, int level) { if (visited.contains(tag)) return this.getUniqueByProperty(TagModel.PROP_NAME, tag.getName(), true); visited.add(tag); LOG.fine(String.format("Creating TagModel for Tag: %s%s(%d) '%s' traits: %s", StringUtils.repeat(' ', level*2), tag.getName(), tag.getContainedTags().size(), tag.getTitle(), tag.getTraits())); TagModel tagModel = this.create(); tagModel.setName(tag.getName()); tagModel.setTitle(tag.getTitle()); tagModel.setColor(tag.getColor()); tagModel.setRoot(tag.isPrime()); tagModel.setPseudo(tag.isPseudo()); if (null != tag.getTraits()) tagModel.putAllTraits(tag.getTraits()); tag.getContainedTags().forEach(tag2 -> { TagModel tag2model = feedTagStructureToGraph(tag2, visited, level+1); tagModel.addDesignatedTag(tag2model); }); return tagModel; }
final Map<String, Integer> totals = new HashMap<>(); for (TagModel sectorTag : sectorsHolderTag.getDesignatedTags()) for (TagModel techTag : sectorTag.getDesignatedTags()) String tagName = techTag.getName();
/** * Translates the placement tags (labels) to their normalized real tag counterparts. Returns a 2-item array; index 0 has the normal names, index 1 * the placement names. * * Due to bad design, the rules contain column and row titles for the graph, rather than technology tags. To make them fit into the tag system, * this translation is needed. See also the "place:..." tags in the report hierarchy definition. */ private static Set<String> getPlacementTags(GraphContext graphContext, Set<String> potentialPlaceTags) { final TagGraphService tagService = new TagGraphService(graphContext); Set<String> placeNames = new HashSet<>(); potentialPlaceTags.forEach(name -> { final TagModel placeTag = tagService.getTagByName("place:" + Tag.normalizeName(name)); if (null != placeTag) placeNames.add(placeTag.getName()); }); return placeNames; }
/** * Returns a single parent of the given tag. If there are multiple parents, throws a WindupException. */ public static TagModel getSingleParent(TagModel tag) { final Iterator<TagModel> parents = tag.getDesignatedByTags().iterator(); if (!parents.hasNext()) throw new WindupException("Tag is not designated by any tags: " + tag); final TagModel maybeOnlyParent = parents.next(); if (parents.hasNext()) { StringBuilder sb = new StringBuilder(); tag.getDesignatedByTags().iterator().forEachRemaining(x -> sb.append(x).append(", ")); throw new WindupException(String.format("Tag %s is designated by multiple tags: %s", tag, sb.toString())); } return maybeOnlyParent; } }
throw new IllegalArgumentException("Sub tag param was null. Super tag: " + superTag); if (superTag.getName().equals(subTag.getName())) return true; for (TagModel currentTag : currentSet) for (TagModel parent : currentTag.getDesignatedByTags()) { if (superTag.equals(parent)) return true;
mergeToTheRightCell(map, placement.row.getName(), placement.box.getName(), 0L, stat.getName(), stat, false); mergeToTheRightCell(map, "", placement.box.getName(), 0L, "", stat, true); mergeToTheRightCell(map, placement.row.getName(), placement.box.getName(), appToCountTowards, stat.getName(), stat, false); mergeToTheRightCell(map, "", placement.box.getName(), appToCountTowards, "", stat, false);
private void getDescendantTags(TagModel tag, Set<TagModel> putResultsHere) { for (TagModel childTag : tag.getDesignatedTags()) { if (!putResultsHere.add(childTag)) continue; // Already visited. getDescendantTags(childTag, putResultsHere); } }
private static TagModel getNonPlaceParent(TagGraphService tagService, TagModel tag) { if (tag == null) return null; final TagModel placeRoot = tagService.getTagByName(MAPPING_OF_PLACEMENT_NAMES); final Iterator<TagModel> parents = tag.getDesignatedByTags().iterator(); if (!parents.hasNext()) throw new WindupException("Tag is not designated by any tags: " + tag); TagModel nonPlaceParent = null; while (parents.hasNext()) { TagModel parentTag = parents.next(); if (TagGraphService.isTagUnderTagOrSame(parentTag, placeRoot)) continue; if (nonPlaceParent != null) throw new WindupException( String.format("Tag %s has more than one non-placement parent: %s, %s", tag.getName(), nonPlaceParent, parentTag)); nonPlaceParent = parentTag; } return nonPlaceParent; }
mergeToTheRightCell(map, placement.row.getName(), placement.box.getName(), 0L, stat.getName(), stat, false); mergeToTheRightCell(map, "", placement.box.getName(), 0L, "", stat, true); mergeToTheRightCell(map, placement.row.getName(), placement.box.getName(), appToCountTowards, stat.getName(), stat, false); mergeToTheRightCell(map, "", placement.box.getName(), appToCountTowards, "", stat, false);
private static TagModel getNonPlaceParent(TagGraphService tagService, TagModel tag) { if (tag == null) return null; final TagModel placeRoot = tagService.getTagByName(MAPPING_OF_PLACEMENT_NAMES); final Iterator<TagModel> parents = tag.getDesignatedByTags().iterator(); if (!parents.hasNext()) throw new WindupException("Tag is not designated by any tags: " + tag); TagModel nonPlaceParent = null; while (parents.hasNext()) { TagModel parentTag = parents.next(); if (TagGraphService.isTagUnderTagOrSame(parentTag, placeRoot)) continue; if (nonPlaceParent != null) throw new WindupException( String.format("Tag %s has more than one non-placement parent: %s, %s", tag.getName(), nonPlaceParent, parentTag)); nonPlaceParent = parentTag; } return nonPlaceParent; }