Mercurial > hg > Members > tatsuki > JungleXMLReader
changeset 34:96dcbd8e2fcb
refactoring
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/cr/ie/tatsuki/bbs/JuGrix.java Sun Nov 09 17:56:49 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/cr/ie/tatsuki/bbs/JuGrix.java Sun Nov 09 22:56:53 2014 +0900 @@ -5,7 +5,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; - import ac.jp.u_ryukyu.cr.ie.tatsuki.xmlReader.LoadXml; import fj.Ord; import fj.P2; @@ -49,8 +48,8 @@ public boolean isActive(String id) { - InterfaceTraverser ifTraverser = personTree.getTraverser(); - Iterator<Pair<TreeNode, NodePath>> pairIterator = ifTraverser.find((TreeNode node) -> { + InterfaceTraverser personTraverser = personTree.getTraverser(); + Iterator<Pair<TreeNode, NodePath>> personIdpairIterator = personTraverser.find((TreeNode node) -> { String personId = node.getAttributes().getString("Person-id"); if (personId == null) return false; @@ -59,17 +58,23 @@ return false; }, "Person-id", id); - if (pairIterator.hasNext()) + if (personIdpairIterator.hasNext()) return true; return false; } - + public Iterator<String> personIds(String orgId, LinkedList<String> roleIds) { - public Iterator<String> personIds(String orgId, LinkedList<String> roleIds) { - TreeMap<String, String> personIds = TreeMap.empty(Ord.stringOrd); - TreeMap<String, String> personIdsTreeMap = personIdsSearch(orgId, roleIds, personIds); + Iterator<String> parentOrgIdIterator = parentOrganizationIds(orgId, roleIds); + TreeMap<String, String> personIdsTreeMap = TreeMap.empty(Ord.stringOrd); + + if (filter(orgId, roleIds)) + personIdsTreeMap = personIdsSearch(orgId, personIdsTreeMap); + + for (; parentOrgIdIterator.hasNext();) { + personIdsTreeMap = personIdsSearch(parentOrgIdIterator.next(), personIdsTreeMap); + } if (personIdsTreeMap.isEmpty()) return new NullIterator(); @@ -96,37 +101,40 @@ TreeMap<String, String> personIds = TreeMap.empty(Ord.stringOrd); for (String orgId : orgIds) { - personIds = personIdsSearch(orgId, roleIds, personIds); + personIds = personIdsSearch(orgId, personIds); } if (personIds.isEmpty()) return new NullIterator(); Iterator<P2<String, String>> personIdsIterator = personIds.iterator(); + return new Iterator<String>() { + String personId; @Override public boolean hasNext() { - if (personIdsIterator.hasNext()) - return true; + for (; personIdsIterator.hasNext();) { + personId = personIdsIterator.next()._1(); + if (filter(personId, roleIds)) + return true; + } return false; } @Override public String next() { - return personIdsIterator.next()._1(); + return personId; } }; } - private TreeMap<String, String> personIdsSearch(String id, LinkedList<String> roleIds, TreeMap<String, String> orgIds) { - - if (!filter(id, roleIds)) - return orgIds; + private TreeMap<String, String> personIdsSearch(String orgId, TreeMap<String, String> orgIdsTreeMap) { InterfaceTraverser personTraverser = personTree.getTraverser(); - Iterator<Pair<TreeNode, NodePath>> pairPersonIterator = personTraverser.findAll((TreeNode node) -> { + + Iterator<Pair<TreeNode, NodePath>> personIdPairIterator = personTraverser.findAll((TreeNode node) -> { String personId = node.getAttributes().getString("element"); if (personId == null) return false; @@ -135,25 +143,26 @@ return false; }, "Person-id"); - for (; pairPersonIterator.hasNext();) { + for (; personIdPairIterator.hasNext();) { - Pair<TreeNode, NodePath> pairPerson = pairPersonIterator.next(); - Iterator<Pair<TreeNode, NodePath>> pairIdIterator = personTraverser.findInSubTree((TreeNode node) -> { + Pair<TreeNode, NodePath> personIdPair = personIdPairIterator.next(); + + Iterator<Pair<TreeNode, NodePath>> orgIdPairIterator = personTraverser.findInSubTree((TreeNode node) -> { String personId = node.getAttributes().getString("text-organizationRefId"); if (personId == null) return false; - if (personId.equals(id)) + if (personId.equals(orgId)) return true; return false; - }, pairPerson, "text-organizationRefId", id); + }, personIdPair, "text-organizationRefId", orgId); - if (pairIdIterator.hasNext()) { - String name = pairPerson.left().getAttributes().getString("Person-id"); - if (name != null) - orgIds = orgIds.set(name, name); + if (orgIdPairIterator.hasNext()) { + String personId = personIdPair.left().getAttributes().getString("Person-id"); + if (personId != null) + orgIdsTreeMap = orgIdsTreeMap.set(personId, personId); } } - return orgIds; + return orgIdsTreeMap; } public boolean filter(String orgId, LinkedList<String> roleIds) { @@ -306,13 +315,14 @@ return searchRoleIds(organizationTree, id, "Organization"); } - return null; + return new NullIterator(); } public Iterator<String> searchRoleIds(JungleTree tree, String id, String element) { - InterfaceTraverser ifTraverser = tree.getTraverser(); - Iterator<Pair<TreeNode, NodePath>> searchTargetIterator = ifTraverser.find((TreeNode node) -> { + InterfaceTraverser traverser = tree.getTraverser(); + + Iterator<Pair<TreeNode, NodePath>> idPairIterator = traverser.find((TreeNode node) -> { String nodeElement = node.getAttributes().getString("element"); if (nodeElement == null) return false; @@ -329,10 +339,11 @@ TreeMap<String, String> idsTreeMap = TreeMap.empty(Ord.stringOrd); ; - for (; searchTargetIterator.hasNext();) { + for (; idPairIterator.hasNext();) { - Pair<TreeNode, NodePath> searchTargetPair = searchTargetIterator.next(); - Iterator<Pair<TreeNode, NodePath>> pairIdIterator = ifTraverser.findInSubTreeAllValue((TreeNode node) -> { + Pair<TreeNode, NodePath> targetPair = idPairIterator.next(); + + Iterator<Pair<TreeNode, NodePath>> roleIdPairIterator = traverser.findInSubTreeAllValue((TreeNode node) -> { String nodeElement = node.getAttributes().getString("element"); if (nodeElement == null) return false; @@ -342,12 +353,12 @@ if (nodeId != null) return true; return false; - }, searchTargetPair, "text-roleRefId"); + }, targetPair, "text-roleRefId"); - for (; pairIdIterator.hasNext();) { - Pair<TreeNode, NodePath> idNodePath = pairIdIterator.next(); - String attribute = idNodePath.left().getAttributes().getString("text-roleRefId"); - idsTreeMap = idsTreeMap.set(attribute, attribute); + for (; roleIdPairIterator.hasNext();) { + Pair<TreeNode, NodePath> roleIdPair = roleIdPairIterator.next(); + String roleId = roleIdPair.left().getAttributes().getString("text-roleRefId"); + idsTreeMap = idsTreeMap.set(roleId, roleId); } } @@ -374,8 +385,8 @@ public Iterator<String> competentRoleId(String personId) { - InterfaceTraverser ifTraverser = personTree.getTraverser(); - Iterator<Pair<TreeNode, NodePath>> pairPersonIterator = ifTraverser.find((TreeNode node) -> { + InterfaceTraverser personTraverser = personTree.getTraverser(); + Iterator<Pair<TreeNode, NodePath>> personIdPairIterator = personTraverser.find((TreeNode node) -> { String nodeElement = node.getAttributes().getString("element"); if (nodeElement == null) return false; @@ -389,11 +400,12 @@ return false; }, "Person-id", personId); - if (!pairPersonIterator.hasNext()) + if (!personIdPairIterator.hasNext()) return new NullIterator(); - Pair<TreeNode, NodePath> person = pairPersonIterator.next(); - Iterator<Pair<TreeNode, NodePath>> targetPairIterator = ifTraverser.findInSubTree((TreeNode node) -> { + Pair<TreeNode, NodePath> personIdPair = personIdPairIterator.next(); + + Iterator<Pair<TreeNode, NodePath>> priorityPairIterator = personTraverser.findInSubTree((TreeNode node) -> { String nodeElement = node.getAttributes().getString("element"); if (nodeElement == null) return false; @@ -405,26 +417,41 @@ if (priority.equals("0")) return true; return false; - }, person, "text-priority", "0"); + }, personIdPair, "text-priority", "0"); + + TreeMap<String, String> roleIdTreeMap = TreeMap.empty(Ord.stringOrd); + + for (; priorityPairIterator.hasNext();) { - LinkedList<String> idList = new LinkedList<String>(); - for (; targetPairIterator.hasNext();) { - NodePath searchPath = targetPairIterator.next().right(); - Pair<Integer, NodePath> searchPair = searchPath.last(); - NodePath targetPath = searchPair.right().add(searchPair.left() + 1); - TreeNode targetNode = getTarget(personTree.getRootNode(), targetPath); - // TreeNode targetNode = getTarget(person.left(), targetPath); - String id = targetNode.getAttributes().getString("text-roleRefId"); - idList.add(id); + Pair<TreeNode, NodePath> priorityPair = priorityPairIterator.next(); + NodePath priorityPath = priorityPair.right(); + Pair<Integer, NodePath> removeLastPair = priorityPath.last(); + NodePath roleIdNodePath = removeLastPair.right().add(removeLastPair.left() + 1); + TreeNode roleIdNode = getTarget(personTree.getRootNode(), roleIdNodePath); + String roleId = roleIdNode.getAttributes().getString("text-roleRefId"); + roleIdTreeMap = roleIdTreeMap.set(roleId, roleId); } + Iterator<P2<String, String>> roleIdP2Iterator = roleIdTreeMap.iterator(); + return new Iterator<String>() { - return idList.iterator(); + @Override + public boolean hasNext() { + if (roleIdP2Iterator.hasNext()) + return true; + return false; + } + + @Override + public String next() { + return roleIdP2Iterator.next()._1(); + } + }; } public Iterator<String> concurrentRoleIds(String personId) { - InterfaceTraverser ifTraverser = personTree.getTraverser(); - Iterator<Pair<TreeNode, NodePath>> pairPersonIterator = ifTraverser.find((TreeNode node) -> { + InterfaceTraverser personTraverser = personTree.getTraverser(); + Iterator<Pair<TreeNode, NodePath>> personIdPairIterator = personTraverser.find((TreeNode node) -> { String nodeElement = node.getAttributes().getString("element"); if (nodeElement == null) return false; @@ -438,55 +465,74 @@ return false; }, "Person-id", personId); - if (!pairPersonIterator.hasNext()) + if (!personIdPairIterator.hasNext()) return new NullIterator(); - Pair<TreeNode, NodePath> person = pairPersonIterator.next(); + + Pair<TreeNode, NodePath> personidPair = personIdPairIterator.next(); - Iterator<Pair<TreeNode, NodePath>> targetPairIterator = ifTraverser.findInSubTreeAllValue((TreeNode node) -> { - String nodeElement = node.getAttributes().getString("element"); - if (nodeElement == null) - return false; - if (!nodeElement.equals("priority")) - return false; - String priority = node.getAttributes().getString("text-priority"); - if (priority != null) - return true; - return false; - }, person, "text-priority"); + Iterator<Pair<TreeNode, NodePath>> priorityPairIterator = personTraverser.findInSubTreeAllValue( + (TreeNode node) -> { + String nodeElement = node.getAttributes().getString("element"); + if (nodeElement == null) + return false; + if (!nodeElement.equals("priority")) + return false; + String priority = node.getAttributes().getString("text-priority"); + if (priority != null) + return true; + return false; + }, personidPair, "text-priority"); - LinkedList<String> idList = new LinkedList<String>(); - for (; targetPairIterator.hasNext();) { - Pair<TreeNode, NodePath> targetPair = targetPairIterator.next(); - TreeNode targetNode = targetPair.left(); - int priority = Integer.parseInt(targetNode.getAttributes().getString("text-priority")); + TreeMap<String, String> roleIdTreeMap = TreeMap.empty(Ord.stringOrd); + + for (; priorityPairIterator.hasNext();) { + + Pair<TreeNode, NodePath> priorityPair = priorityPairIterator.next(); + TreeNode priorityNode = priorityPair.left(); + int priority = Integer.parseInt(priorityNode.getAttributes().getString("text-priority")); if (priority > 0) { - NodePath targetPath = targetPair.right(); - Pair<Integer, NodePath> searchPair = targetPath.last(); - NodePath roleIdNodePath = searchPair.right().add(searchPair.left() + 1); + NodePath priorityPath = priorityPair.right(); + Pair<Integer, NodePath> removeLastPair = priorityPath.last(); + NodePath roleIdNodePath = removeLastPair.right().add(removeLastPair.left() + 1); TreeNode roleIdNode = getTarget(personTree.getRootNode(), roleIdNodePath); - String id = roleIdNode.getAttributes().getString("text-roleRefId"); - idList.add(id); + String roleId = roleIdNode.getAttributes().getString("text-roleRefId"); + roleIdTreeMap = roleIdTreeMap.set(roleId, roleId); } } + Iterator<P2<String, String>> roleIdP2Iterator = roleIdTreeMap.iterator(); + return new Iterator<String>() { - return idList.iterator(); + @Override + public boolean hasNext() { + if (roleIdP2Iterator.hasNext()) + return true; + return false; + } + + @Override + public String next() { + return roleIdP2Iterator.next()._1(); + } + }; } public Iterator<String> deepPersonIds(String orgId, LinkedList<String> filterIds) { + TreeMap<String, String> personIdsTreeMap = TreeMap.empty(Ord.stringOrd); - Iterator<String> childrensIterator = deepParentOrganizationIdsPlus(orgId, filterIds); + Iterator<String> childrensIterator = deepChildOrganizationIdsPlus(orgId, filterIds); + if (!childrensIterator.hasNext()) return new NullIterator(); for (; childrensIterator.hasNext();) { String id = childrensIterator.next(); - personIdsTreeMap = personIdsSearch(id, filterIds,personIdsTreeMap); + personIdsTreeMap = personIdsSearch(id, personIdsTreeMap); } if (personIdsTreeMap.isEmpty()) return new NullIterator(); - + Iterator<P2<String, String>> personIds = personIdsTreeMap.iterator(); return new Iterator<String>() { @@ -506,26 +552,31 @@ public Iterator<String> deepChildOrganizationIdsPlus(String orgId, LinkedList<String> filterIds) { TreeMap<String, String> orgIdsTreeMap = TreeMap.empty(Ord.stringOrd); - if (filter(orgId, filterIds)) - orgIdsTreeMap = orgIdsTreeMap.set(orgId, orgId); - orgIdsTreeMap = _deepChildOrganizationIds(orgId, filterIds, orgIdsTreeMap); + + orgIdsTreeMap = orgIdsTreeMap.set(orgId, orgId); + orgIdsTreeMap = _deepChildOrganizationIds(orgId, orgIdsTreeMap); if (orgIdsTreeMap.isEmpty()) return new NullIterator(); - Iterator<P2<String, String>> orgIds = orgIdsTreeMap.iterator(); + Iterator<P2<String, String>> orgIdsP2Iterator = orgIdsTreeMap.iterator(); return new Iterator<String>() { + String childOrgId; + @Override public boolean hasNext() { - if (orgIds.hasNext()) - return true; + for (; orgIdsP2Iterator.hasNext();) { + childOrgId = orgIdsP2Iterator.next()._1(); + if (filter(childOrgId, filterIds)) + return true; + } return false; } @Override public String next() { - return orgIds.next()._1(); + return childOrgId; } }; } @@ -533,39 +584,45 @@ public Iterator<String> deepChildOrganizationIds(String orgId, LinkedList<String> filterIds) { TreeMap<String, String> orgIdsTreeMap = TreeMap.empty(Ord.stringOrd); - TreeMap<String, String> newOrgIdsTreeMap = _deepChildOrganizationIds(orgId, filterIds, orgIdsTreeMap); + TreeMap<String, String> newOrgIdsTreeMap = _deepChildOrganizationIds(orgId, orgIdsTreeMap); if (newOrgIdsTreeMap.isEmpty()) return new NullIterator(); - Iterator<P2<String, String>> orgIds = newOrgIdsTreeMap.iterator(); + Iterator<P2<String, String>> orgIdP2Iterator = newOrgIdsTreeMap.iterator(); + return new Iterator<String>() { + String childOrgId; @Override public String next() { - return orgIds.next()._1(); + return childOrgId; } @Override public boolean hasNext() { - if (orgIds.hasNext()) - return true; + for (; orgIdP2Iterator.hasNext();) { + childOrgId = orgIdP2Iterator.next()._1(); + if (filter(childOrgId, filterIds)) + return true; + } return false; } }; } - public TreeMap<String, String> _deepChildOrganizationIds(String orgId, LinkedList<String> filterIds, - TreeMap<String, String> orgIdsTreeMap) { + public TreeMap<String, String> _deepChildOrganizationIds(String orgId, TreeMap<String, String> orgIdsTreeMap) { - Iterator<String> childrensIterator = childOrganizationIds(orgId, new LinkedList<String>()); - if (!childrensIterator.hasNext()) + TreeMap<String, String> childrenIdTreeMap = _childOrganizationIds(orgId, TreeMap.empty(Ord.stringOrd)); + + if (childrenIdTreeMap.isEmpty()) return orgIdsTreeMap; - for (; childrensIterator.hasNext();) { - String childrenId = childrensIterator.next(); - if (filter(childrenId, filterIds)) - orgIdsTreeMap = orgIdsTreeMap.set(childrenId, childrenId); - orgIdsTreeMap = _deepChildOrganizationIds(childrenId, filterIds, orgIdsTreeMap); + Iterator<P2<String, String>> childrenIdIterator = childrenIdTreeMap.iterator(); + + for (; childrenIdIterator.hasNext();) { + String childrenId = childrenIdIterator.next()._1(); + orgIdsTreeMap = orgIdsTreeMap.set(childrenId, childrenId); + orgIdsTreeMap = _deepChildOrganizationIds(childrenId, orgIdsTreeMap); } return orgIdsTreeMap; @@ -573,35 +630,40 @@ public Iterator<String> childOrganizationIds(String orgId, LinkedList<String> filterIds) { TreeMap<String, String> childrenOrgIdTreeMap = TreeMap.empty(Ord.stringOrd); - TreeMap<String, String> newChildrenOrgIdTreeMap = _childOrganizationIds(orgId, filterIds, childrenOrgIdTreeMap); + TreeMap<String, String> newChildrenOrgIdTreeMap = _childOrganizationIds(orgId, childrenOrgIdTreeMap); if (newChildrenOrgIdTreeMap.isEmpty()) return new NullIterator(); Iterator<P2<String, String>> childrenOrgIdIterator = newChildrenOrgIdTreeMap.iterator(); + return new Iterator<String>() { + String childOrgId; @Override public boolean hasNext() { - if (childrenOrgIdIterator.hasNext()) - return true; + + if (childrenOrgIdIterator.hasNext()) { + childOrgId = childrenOrgIdIterator.next()._1(); + if (filter(childOrgId, filterIds)) + return true; + } return false; } @Override public String next() { - return childrenOrgIdIterator.next()._1(); + return childOrgId; } }; } - public TreeMap<String, String> _childOrganizationIds(String orgId, LinkedList<String> filterIds, - TreeMap<String, String> childOrgIdsTreeMap) { + public TreeMap<String, String> _childOrganizationIds(String orgId, TreeMap<String, String> childOrgIdsTreeMap) { InterfaceTraverser orgTraverser = organizationTree.getTraverser(); - Iterator<Pair<TreeNode, NodePath>> pairPersonIterator = orgTraverser.find((TreeNode node) -> { + Iterator<Pair<TreeNode, NodePath>> orgIdPairIterator = orgTraverser.find((TreeNode node) -> { String nodeElement = node.getAttributes().getString("element"); if (nodeElement == null) return false; @@ -615,41 +677,42 @@ return false; }, "Organization-id", orgId); - if (!pairPersonIterator.hasNext()) + if (!orgIdPairIterator.hasNext()) return childOrgIdsTreeMap; - Pair<TreeNode, NodePath> person = pairPersonIterator.next(); + Pair<TreeNode, NodePath> orgIdPair = orgIdPairIterator.next(); - Iterator<Pair<TreeNode, NodePath>> chilrenOrgIdsIterator = orgTraverser.findInSubTree((TreeNode node) -> { + Iterator<Pair<TreeNode, NodePath>> chilrenOrgPairIterator = orgTraverser.findInSubTree((TreeNode node) -> { String nodeElement = node.getAttributes().getString("element"); if (nodeElement == null) return false; if (nodeElement.equals("childOrganizations")) return true; return false; - }, person, "element", "childOrganizations"); + }, orgIdPair, "element", "childOrganizations"); - if (!chilrenOrgIdsIterator.hasNext()) + if (!chilrenOrgPairIterator.hasNext()) return childOrgIdsTreeMap; - Pair<TreeNode, NodePath> chilerenOrgIds = chilrenOrgIdsIterator.next(); + Pair<TreeNode, NodePath> chilerenOrg = chilrenOrgPairIterator.next(); - Iterator<Pair<TreeNode, NodePath>> chilrenOrgIdIterator = orgTraverser.findInSubTreeAllValue((TreeNode node) -> { - String nodeElement = node.getAttributes().getString("element"); - if (nodeElement == null) - return false; - if (!nodeElement.equals("organizationRefIds")) - return false; - nodeElement = node.getAttributes().getString("text-organizationRefIds"); - if (nodeElement != null) - return true; - return false; - }, chilerenOrgIds, "text-organizationRefIds"); + Iterator<Pair<TreeNode, NodePath>> chilrenOrgIdPairIterator = orgTraverser.findInSubTreeAllValue( + (TreeNode node) -> { + String nodeElement = node.getAttributes().getString("element"); + if (nodeElement == null) + return false; + if (!nodeElement.equals("organizationRefIds")) + return false; + nodeElement = node.getAttributes().getString("text-organizationRefIds"); + if (nodeElement != null) + return true; + return false; + }, chilerenOrg, "text-organizationRefIds"); - for (; chilrenOrgIdIterator.hasNext();) { - String childrenOrgId = chilrenOrgIdIterator.next().left().getAttributes().getString("text-organizationRefIds"); - if (filter(childrenOrgId, filterIds)) - childOrgIdsTreeMap = childOrgIdsTreeMap.set(childrenOrgId, childrenOrgId); + for (; chilrenOrgIdPairIterator.hasNext();) { + String childrenOrgId = chilrenOrgIdPairIterator.next().left().getAttributes() + .getString("text-organizationRefIds"); + childOrgIdsTreeMap = childOrgIdsTreeMap.set(childrenOrgId, childrenOrgId); } @@ -691,27 +754,29 @@ } public String rolePriority(String personId, String roleId) { + InterfaceTraverser personTraverser = personTree.getTraverser(); - Iterator<Pair<TreeNode, NodePath>> personIterator = personTraverser.find((TreeNode node) -> { + + Iterator<Pair<TreeNode, NodePath>> personIdPairIterator = personTraverser.find((TreeNode node) -> { String element = node.getAttributes().getString("element"); if (element == null) return false; if (!element.equals("Person")) return false; - String nodeId = node.getAttributes().getString("Person-id"); - if (nodeId == null) + String nodePersonId = node.getAttributes().getString("Person-id"); + if (nodePersonId == null) return false; - if (nodeId.equals(personId)) + if (nodePersonId.equals(personId)) return true; return false; }, "Person-id", personId); - if (!personIterator.hasNext()) + if (!personIdPairIterator.hasNext()) return ""; - Pair<TreeNode, NodePath> targetNode = personIterator.next(); + Pair<TreeNode, NodePath> targetPersonIdPair = personIdPairIterator.next(); - Iterator<Pair<TreeNode, NodePath>> priorityIterator = personTraverser.findInSubTree((TreeNode node) -> { + Iterator<Pair<TreeNode, NodePath>> roleIdPairIterator = personTraverser.findInSubTree((TreeNode node) -> { String element = node.getAttributes().getString("element"); if (element == null) return false; @@ -723,13 +788,13 @@ if (compareRoleId.equals(roleId)) return true; return false; - }, targetNode, "text-roleRefId",roleId); + }, targetPersonIdPair, "text-roleRefId", roleId); - for (; priorityIterator.hasNext();) { - Pair<TreeNode, NodePath> priorityPair = priorityIterator.next(); - NodePath roleNodePath = priorityPair.right(); - Pair<Integer, NodePath> last = roleNodePath.last(); - NodePath priorityNodePath = last.right().add(last.left() - 1); + for (; roleIdPairIterator.hasNext();) { + Pair<TreeNode, NodePath> roleIdPair = roleIdPairIterator.next(); + NodePath roleIdNodePath = roleIdPair.right(); + Pair<Integer, NodePath> removeLastPath = roleIdNodePath.last(); + NodePath priorityNodePath = removeLastPath.right().add(removeLastPath.left() - 1); TreeNode priorityNode = getTarget(personTree.getRootNode(), priorityNodePath); if (priorityNode.getAttributes().getString("element").equals("priority")) return priorityNode.getAttributes().getString("text-priority"); @@ -738,13 +803,37 @@ } public Iterator<String> parentOrganizationIds(String orgId, LinkedList<String> filterIds) { - return _parentOrganizationIds(orgId, filterIds); + + TreeMap<String, String> parentIdsTreeMap = _parentOrganizationIds(orgId); + if (parentIdsTreeMap.isEmpty()) + return new NullIterator(); + + Iterator<P2<String, String>> parentIdP2Iterator = parentIdsTreeMap.iterator(); + return new Iterator<String>() { + String parentId; + + @Override + public boolean hasNext() { + for (; parentIdP2Iterator.hasNext();) { + parentId = parentIdP2Iterator.next()._1(); + if (filter(parentId, filterIds)) + return true; + } + return false; + } + + @Override + public String next() { + return parentId; + } + + }; } - public Iterator<String> _parentOrganizationIds(String orgId, LinkedList<String> filterIds) { + public TreeMap<String, String> _parentOrganizationIds(String orgId) { InterfaceTraverser orgTraverser = organizationTree.getTraverser(); - Iterator<Pair<TreeNode, NodePath>> orgIterator = orgTraverser.find((TreeNode node) -> { + Iterator<Pair<TreeNode, NodePath>> orgIdPairIterator = orgTraverser.find((TreeNode node) -> { String element = node.getAttributes().getString("element"); if (element == null) return false; @@ -758,12 +847,12 @@ return false; }, "Organization-id", orgId); - if (!orgIterator.hasNext()) - return new NullIterator(); + if (!orgIdPairIterator.hasNext()) + return TreeMap.empty(Ord.stringOrd); - Pair<TreeNode, NodePath> orgNode = orgIterator.next(); + Pair<TreeNode, NodePath> orgNode = orgIdPairIterator.next(); - Iterator<Pair<TreeNode, NodePath>> parentOrgIterator = orgTraverser.findInSubTree((TreeNode node) -> { + Iterator<Pair<TreeNode, NodePath>> parentOrgPairIterator = orgTraverser.findInSubTree((TreeNode node) -> { String element = node.getAttributes().getString("element"); if (element == null) return false; @@ -774,108 +863,106 @@ TreeMap<String, String> parentIdsTreeMap = TreeMap.empty(Ord.stringOrd); - for (; parentOrgIterator.hasNext();) { - Pair<TreeNode, NodePath> parentOrgNode = parentOrgIterator.next(); + for (; parentOrgPairIterator.hasNext();) { + Pair<TreeNode, NodePath> parentOrgNode = parentOrgPairIterator.next(); - Iterator<Pair<TreeNode, NodePath>> parentNodeIterator = orgTraverser.findInSubTreeAllValue((TreeNode node) -> { - String element = node.getAttributes().getString("element"); - if (element == null) - return false; - if (!element.equals("organizationRefId")) - return false; - String parentId = node.getAttributes().getString("text-organizationRefId"); - if (parentId != null) - return true; - return false; - }, parentOrgNode, "text-organizationRefId"); + Iterator<Pair<TreeNode, NodePath>> parentOrgIdPairIterator = orgTraverser.findInSubTreeAllValue( + (TreeNode node) -> { + String element = node.getAttributes().getString("element"); + if (element == null) + return false; + if (!element.equals("organizationRefId")) + return false; + String parentId = node.getAttributes().getString("text-organizationRefId"); + if (parentId != null) + return true; + return false; + }, parentOrgNode, "text-organizationRefId"); - for (; parentNodeIterator.hasNext();) { - String parentId = parentNodeIterator.next().left().getAttributes().getString("text-organizationRefId"); - if (filter(parentId, filterIds)) - parentIdsTreeMap = parentIdsTreeMap.set(parentId, parentId); + for (; parentOrgIdPairIterator.hasNext();) { + String parentId = parentOrgIdPairIterator.next().left().getAttributes().getString("text-organizationRefId"); + parentIdsTreeMap = parentIdsTreeMap.set(parentId, parentId); } } - Iterator<P2<String, String>> parentIds = parentIdsTreeMap.iterator(); - if (parentIdsTreeMap.isEmpty()) - return new NullIterator(); - else - return new Iterator<String>() { + return parentIdsTreeMap; - @Override - public boolean hasNext() { - if (parentIds.hasNext()) - return true; - return false; - } - - @Override - public String next() { - return parentIds.next()._1(); - } - - }; } public Iterator<String> deepParentOrganizationIds(String orgId, LinkedList<String> filterIds) { TreeMap<String, String> parentIdsTreeMap = TreeMap.empty(Ord.stringOrd); - Iterator<P2<String, String>> parentIds = _deepParentOrganizationIds(orgId, filterIds, parentIdsTreeMap).iterator(); + TreeMap<String, String> newParentIdsTreeMap = _deepParentOrganizationIds(orgId, parentIdsTreeMap); + + if (newParentIdsTreeMap.isEmpty()) + return new NullIterator(); + + Iterator<P2<String, String>> parentIds = newParentIdsTreeMap.iterator(); + return new Iterator<String>() { + String parentOrgId; @Override public boolean hasNext() { - if (parentIds.hasNext()) - return true; + for (; parentIds.hasNext();) { + parentOrgId = parentIds.next()._1(); + if (filter(parentOrgId, filterIds)) + return true; + } return false; } @Override public String next() { - return parentIds.next()._1(); + return parentOrgId; } }; } - public TreeMap<String, String> _deepParentOrganizationIds(String orgId, LinkedList<String> filterIds, - TreeMap<String, String> orgIds) { + public TreeMap<String, String> _deepParentOrganizationIds(String orgId, TreeMap<String, String> orgIds) { - Iterator<String> parentIds = parentOrganizationIds(orgId, filterIds); - if (!parentIds.hasNext()) + TreeMap<String, String> parentIdsTreeMap = _parentOrganizationIds(orgId); + + if (parentIdsTreeMap.isEmpty()) return orgIds; - for (; parentIds.hasNext();) { - String parentId = parentIds.next(); - if (filter(parentId, filterIds)) - orgIds = orgIds.set(parentId, parentId); - orgIds = _deepParentOrganizationIds(parentId, filterIds, orgIds); + Iterator<P2<String, String>> parentIdsIterator = parentIdsTreeMap.iterator(); + for (; parentIdsIterator.hasNext();) { + String parentId = parentIdsIterator.next()._1(); + orgIds = orgIds.set(parentId, parentId); + orgIds = _deepParentOrganizationIds(parentId, orgIds); } return orgIds; } public Iterator<String> deepParentOrganizationIdsPlus(String id, LinkedList<String> filterIds) { + TreeMap<String, String> parentIdsTreeMap = TreeMap.empty(Ord.stringOrd); - if (filter(id, filterIds)) - parentIdsTreeMap = parentIdsTreeMap.set(id, id); - parentIdsTreeMap = _deepParentOrganizationIds(id, filterIds, parentIdsTreeMap); + + parentIdsTreeMap = parentIdsTreeMap.set(id, id); + parentIdsTreeMap = _deepParentOrganizationIds(id, parentIdsTreeMap); if (parentIdsTreeMap.isEmpty()) return new NullIterator(); Iterator<P2<String, String>> personIds = parentIdsTreeMap.iterator(); return new Iterator<String>() { + String parentOrgId; @Override public boolean hasNext() { - if (personIds.hasNext()) - return true; + for (; personIds.hasNext();) { + parentOrgId = personIds.next()._1(); + if (filter(parentOrgId, filterIds)) + return true; + } return false; } @Override public String next() { - return personIds.next()._1(); + return parentOrgId; } }; @@ -905,7 +992,7 @@ elementName = "RoleDescriptionElement"; } - Iterator<Pair<TreeNode, NodePath>> idIterator = traverser.find((TreeNode node) -> { + Iterator<Pair<TreeNode, NodePath>> PathNameIterator = traverser.find((TreeNode node) -> { String element = node.getAttributes().getString("element"); if (element == null) return false; @@ -919,39 +1006,39 @@ return false; }, "text-path", StrPath); - if (!idIterator.hasNext()) + if (!PathNameIterator.hasNext()) return ""; - Pair<TreeNode, NodePath> nodePair = idIterator.next(); - NodePath path = nodePair.right(); - NodePath targetPath = path.last().right(); + Pair<TreeNode, NodePath> pathNamePair = PathNameIterator.next(); + NodePath pathNamePath = pathNamePair.right(); + NodePath pathNameIdPath = pathNamePath.last().right(); - TreeNode targetNode = getTarget(root, targetPath); - String targetId = targetNode.getAttributes().getString(elementName + "-id"); - return targetId; + TreeNode pathNameIdNode = getTarget(root, pathNameIdPath); + String pathNameId = pathNameIdNode.getAttributes().getString(elementName + "-id"); + return pathNameId; } public Iterator<String> roleDescriptionElementIds(String id, LinkedList<String> filterIds) { - Iterator<String> orgIds = deepParentOrganizationIdsPlus(id, filterIds); + Iterator<String> orgIdsIterator = deepParentOrganizationIdsPlus(id, filterIds); - TreeMap<String,String> rdeIdsTreeMap = TreeMap.empty(Ord.stringOrd); + TreeMap<String, String> rdeIdsTreeMap = TreeMap.empty(Ord.stringOrd); - for (; orgIds.hasNext();) { - String orgId = orgIds.next(); - Iterator<String> roleIds = roleIds(orgId); - for (; roleIds.hasNext();) { - String roleId = roleIds.next(); - Iterator<String> rdeIds = getRde(roleId); - for (;rdeIds.hasNext();) { - String rdeId = rdeIds.next(); - rdeIdsTreeMap = rdeIdsTreeMap.set(rdeId,rdeId); + for (; orgIdsIterator.hasNext();) { + String orgId = orgIdsIterator.next(); + Iterator<String> roleIdIteraotr = roleIds(orgId); + for (; roleIdIteraotr.hasNext();) { + String roleId = roleIdIteraotr.next(); + Iterator<String> rdeIdIterator = getRde(roleId); + for (; rdeIdIterator.hasNext();) { + String rdeId = rdeIdIterator.next(); + rdeIdsTreeMap = rdeIdsTreeMap.set(rdeId, rdeId); } } } if (rdeIdsTreeMap.isEmpty()) return new NullIterator(); - + Iterator<P2<String, String>> rdeIds = rdeIdsTreeMap.iterator(); return new Iterator<String>() { @@ -973,7 +1060,7 @@ InterfaceTraverser traverser = roleTree.getTraverser(); - Iterator<Pair<TreeNode, NodePath>> roleIterator = traverser.find((TreeNode node) -> { + Iterator<Pair<TreeNode, NodePath>> roleIdPairIterator = traverser.find((TreeNode node) -> { String element = node.getAttributes().getString("element"); if (element == null) return false; @@ -987,12 +1074,12 @@ return false; }, "Role-id", roleId); - if (!roleIterator.hasNext()) + if (!roleIdPairIterator.hasNext()) return new NullIterator(); - Pair<TreeNode, NodePath> roleNode = roleIterator.next(); + Pair<TreeNode, NodePath> roleIdPair = roleIdPairIterator.next(); - Iterator<Pair<TreeNode, NodePath>> rdeIterator = traverser.findInSubTreeAllValue((TreeNode node) -> { + Iterator<Pair<TreeNode, NodePath>> rdeIdPairIterator = traverser.findInSubTreeAllValue((TreeNode node) -> { String element = node.getAttributes().getString("element"); if (element == null) return false; @@ -1002,26 +1089,26 @@ if (rde != null) return true; return false; - }, roleNode, "text-roleDescriptionElementRefIds"); + }, roleIdPair, "text-roleDescriptionElementRefIds"); - if (!rdeIterator.hasNext()) + if (!rdeIdPairIterator.hasNext()) return new NullIterator(); return new Iterator<String>() { @Override public boolean hasNext() { - if (rdeIterator.hasNext()) + if (rdeIdPairIterator.hasNext()) return true; return false; } @Override public String next() { - return rdeIterator.next().left().getAttributes().getString("text-roleDescriptionElementRefIds"); + return rdeIdPairIterator.next().left().getAttributes().getString("text-roleDescriptionElementRefIds"); } }; - + } }
--- a/src/test/java/jp/ac/u_ryukyu/cr/ie/tatsuki/functionTest/ChildOrganizationIdsTest.java Sun Nov 09 17:56:49 2014 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/cr/ie/tatsuki/functionTest/ChildOrganizationIdsTest.java Sun Nov 09 22:56:53 2014 +0900 @@ -17,16 +17,16 @@ Iterator<String> ids = jugrix.childOrganizationIds("o:2", list); Assert.assertTrue(ids.hasNext()); - Assert.assertEquals(ids.next(),"o:9"); + Assert.assertTrue(ids.hasNext()); Assert.assertEquals(ids.next(),"o:3"); JuGrix indexJugrix = new JuGrix(true); ids = indexJugrix.childOrganizationIds("o:2", list); Assert.assertTrue(ids.hasNext()); - Assert.assertEquals(ids.next(),"o:9"); + Assert.assertTrue(ids.hasNext()); Assert.assertEquals(ids.next(),"o:3"); } }
--- a/src/test/java/jp/ac/u_ryukyu/cr/ie/tatsuki/functionTest/DeepChildOrganizationIdsTest.java Sun Nov 09 17:56:49 2014 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/cr/ie/tatsuki/functionTest/DeepChildOrganizationIdsTest.java Sun Nov 09 22:56:53 2014 +0900 @@ -27,7 +27,7 @@ Assert.assertTrue(childrenIds.hasNext()); childrenId = childrenIds.next(); Assert.assertEquals(childrenId, "o:4"); - + Assert.assertFalse(childrenIds.hasNext()); jugrix = new JuGrix(true); filterIds = new LinkedList<String>();
--- a/src/test/java/jp/ac/u_ryukyu/cr/ie/tatsuki/functionTest/DeepParentOrganizationIdsPlusTest.java Sun Nov 09 17:56:49 2014 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/cr/ie/tatsuki/functionTest/DeepParentOrganizationIdsPlusTest.java Sun Nov 09 22:56:53 2014 +0900 @@ -15,13 +15,16 @@ LinkedList<String> filterIds = new LinkedList<String>(); //filterIds.add("r:2"); Iterator<String> childrenIds = jugrix.deepParentOrganizationIdsPlus("o:2", filterIds); + Assert.assertTrue(childrenIds.hasNext()); Assert.assertEquals(childrenIds.next(),"o:23"); + Assert.assertTrue(childrenIds.hasNext()); Assert.assertEquals(childrenIds.next(),"o:22"); + Assert.assertTrue(childrenIds.hasNext()); Assert.assertEquals(childrenIds.next(),"o:2"); filterIds.add("r:2"); childrenIds = jugrix.deepParentOrganizationIds("o:2", filterIds); - + Assert.assertTrue(childrenIds.hasNext()); Assert.assertEquals(childrenIds.next(),"o:23"); @@ -29,13 +32,16 @@ filterIds = new LinkedList<String>(); //filterIds.add("r:2"); childrenIds = jugrix.deepParentOrganizationIdsPlus("o:2", filterIds); + Assert.assertTrue(childrenIds.hasNext()); Assert.assertEquals(childrenIds.next(),"o:23"); + Assert.assertTrue(childrenIds.hasNext()); Assert.assertEquals(childrenIds.next(),"o:22"); + Assert.assertTrue(childrenIds.hasNext()); Assert.assertEquals(childrenIds.next(),"o:2"); filterIds.add("r:2"); childrenIds = jugrix.deepParentOrganizationIds("o:2", filterIds); - + Assert.assertTrue(childrenIds.hasNext()); Assert.assertEquals(childrenIds.next(),"o:23"); } }
--- a/src/test/java/jp/ac/u_ryukyu/cr/ie/tatsuki/functionTest/DeepParentOrganizationIdsTest.java Sun Nov 09 17:56:49 2014 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/cr/ie/tatsuki/functionTest/DeepParentOrganizationIdsTest.java Sun Nov 09 22:56:53 2014 +0900 @@ -15,21 +15,28 @@ JuGrix jugrix = new JuGrix(false); LinkedList<String> filterIds = new LinkedList<String>(); Iterator<String> childrenIds = jugrix.deepParentOrganizationIds("o:2", filterIds); + Assert.assertTrue(childrenIds.hasNext()); Assert.assertEquals(childrenIds.next(),"o:23"); + Assert.assertTrue(childrenIds.hasNext()); Assert.assertEquals(childrenIds.next(),"o:22"); filterIds.add("r:2"); childrenIds = jugrix.deepParentOrganizationIds("o:2", filterIds); + Assert.assertTrue(childrenIds.hasNext()); Assert.assertEquals(childrenIds.next(),"o:23"); jugrix = new JuGrix(true); filterIds = new LinkedList<String>(); childrenIds = jugrix.deepParentOrganizationIds("o:2", filterIds); + Assert.assertTrue(childrenIds.hasNext()); Assert.assertEquals(childrenIds.next(),"o:23"); + Assert.assertTrue(childrenIds.hasNext()); Assert.assertEquals(childrenIds.next(),"o:22"); + filterIds.add("r:2"); childrenIds = jugrix.deepParentOrganizationIds("o:2", filterIds); + Assert.assertTrue(childrenIds.hasNext()); Assert.assertEquals(childrenIds.next(),"o:23"); } }
--- a/src/test/java/jp/ac/u_ryukyu/cr/ie/tatsuki/functionTest/DeepPersonIdsTest.java Sun Nov 09 17:56:49 2014 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/cr/ie/tatsuki/functionTest/DeepPersonIdsTest.java Sun Nov 09 22:56:53 2014 +0900 @@ -13,7 +13,7 @@ JuGrix jugrix = new JuGrix(false); LinkedList<String> filterIds = new LinkedList<String>(); //filterIds.add("r:9"); - Iterator<String> ids = jugrix.deepPersonIds("o:3",filterIds); + Iterator<String> ids = jugrix.deepPersonIds("o:2",filterIds); System.out.println("------------------------------------------------"); for (;ids.hasNext();) { System.out.println(ids.next());
--- a/src/test/java/jp/ac/u_ryukyu/cr/ie/tatsuki/functionTest/PersonIdsTest.java Sun Nov 09 17:56:49 2014 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/cr/ie/tatsuki/functionTest/PersonIdsTest.java Sun Nov 09 22:56:53 2014 +0900 @@ -19,7 +19,7 @@ filterIds.add("r:9"); Iterator<String> ids = jugrix.personIds("o:2", filterIds); - ids.hasNext(); + Assert.assertTrue(ids.hasNext()); Assert.assertEquals(ids.next(), "p:45"); Assert.assertEquals(ids.next(), "p:1");