Mercurial > hg > Members > tatsuki > JungleXMLReader
changeset 19:da872647cbe4
add deepChildOrganizationIdsPlusTest and Method
author | one |
---|---|
date | Mon, 27 Oct 2014 08:18:42 +0900 |
parents | 0fce1292ab38 |
children | ae739e8d86a2 |
files | src/main/java/jp/ac/u_ryukyu/cr/ie/tatsuki/bbs/JuGrix.java src/test/java/jp/ac/u_ryukyu/cr/ie/tatsuki/functionTest/childOrganizationIds.java src/test/java/jp/ac/u_ryukyu/cr/ie/tatsuki/functionTest/deepChildOrganizationIdsPlusTest.java |
diffstat | 3 files changed, 61 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/cr/ie/tatsuki/bbs/JuGrix.java Mon Oct 27 06:49:08 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/cr/ie/tatsuki/bbs/JuGrix.java Mon Oct 27 08:18:42 2014 +0900 @@ -438,7 +438,7 @@ return new NullIterator(); LinkedList<String> childrenPersonList = new LinkedList<String>(); - childrenPersonList.addAll(personIdLink(orgId, filterIds)); + //childrenPersonList.addAll(personIdLink(orgId, filterIds)); for (;childrensIterator.hasNext();) { String id = childrensIterator.next(); childrenPersonList.addAll(personIdLink(id, filterIds)); @@ -447,13 +447,21 @@ return childrenPersonList.iterator(); } + public Iterator<String> deepChildOrganizationIdsPlus(String orgId, LinkedList<String> filterIds) { + LinkedList<String> orgList = new LinkedList<String>(); + if (filter(orgId, filterIds)) + orgList.add(orgId); + orgList.addAll(_deepChildOrganizationIds(orgId,filterIds)); + return orgList.iterator(); + } + public Iterator<String> deepChildOrganizationIds(String orgId, LinkedList<String> filterIds) { return _deepChildOrganizationIds(orgId,filterIds).iterator(); } public LinkedList<String> _deepChildOrganizationIds(String orgId, LinkedList<String> filterIds) { - Iterator<String> childrensIterator = childOrganizationIds(orgId); + Iterator<String> childrensIterator = childOrganizationIds(orgId,new LinkedList<String>()); if (!childrensIterator.hasNext()) return new LinkedList<String>(); @@ -469,15 +477,32 @@ } - public Iterator<String> childOrganizationIds(String orgId) { - InterfaceTraverser ifTraverser = organizationTree.getTraverser(); - Iterator<Pair<TreeNode, NodePath>> pairPersonIterator = searchOrganization(orgId, ifTraverser); + public Iterator<String> childOrganizationIds(String orgId, LinkedList<String> filterIds) { + if(!filter(orgId,filterIds)) + return new NullIterator(); + InterfaceTraverser orgTraverser = organizationTree.getTraverser(); + Iterator<Pair<TreeNode, NodePath>> pairPersonIterator = orgTraverser.find( + (TreeNode node) -> { + String nodeElement = node.getAttributes().getString("element"); + if (nodeElement == null) + return false; + if (!nodeElement.equals("Organization")) + return false; + String nodeId = node.getAttributes().getString("id"); + if (nodeId == null) + return false; + if (nodeId.equals(orgId)) + return true; + return false; + } + ,"element","Organization"); if (!pairPersonIterator.hasNext()) return new NullIterator(); TreeNode person = pairPersonIterator.next().left(); - Iterator<Pair<TreeNode,NodePath>> chilrenOrgIdsIterator = ifTraverser.find( + + Iterator<Pair<TreeNode,NodePath>> chilrenOrgIdsIterator = orgTraverser.find( (TreeNode node) -> { String nodeElement = node.getAttributes().getString("element"); if (nodeElement == null) @@ -493,7 +518,7 @@ TreeNode chilerenOrgIds = chilrenOrgIdsIterator.next().left(); - Iterator<Pair<TreeNode,NodePath>> chilrenOrgIdIterator = ifTraverser.find( + Iterator<Pair<TreeNode,NodePath>> chilrenOrgIdIterator = orgTraverser.find( (TreeNode node) -> { String nodeElement = node.getAttributes().getString("element"); if (nodeElement == null) @@ -517,25 +542,6 @@ } - private Iterator<Pair<TreeNode, NodePath>> searchOrganization(String orgId, - InterfaceTraverser ifTraverser) { - Iterator<Pair<TreeNode,NodePath>> pairPersonIterator = ifTraverser.find( - (TreeNode node) -> { - String nodeElement = node.getAttributes().getString("element"); - if (nodeElement == null) - return false; - if (!nodeElement.equals("Organization")) - return false; - String nodeId = node.getAttributes().getString("id"); - if (nodeId == null) - return false; - if (nodeId.equals(orgId)) - return true; - return false; - } - ,"element","Organization"); - return pairPersonIterator; - } public TreeNode getTarget(TreeNode node , NodePath path){ TreeNode target;
--- a/src/test/java/jp/ac/u_ryukyu/cr/ie/tatsuki/functionTest/childOrganizationIds.java Mon Oct 27 06:49:08 2014 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/cr/ie/tatsuki/functionTest/childOrganizationIds.java Mon Oct 27 08:18:42 2014 +0900 @@ -12,7 +12,7 @@ @Test public void childOrganizationIdsTest(){ JuGrix jugrix = new JuGrix(); - Iterator<String> ids = jugrix.childOrganizationIds("o:2"); + Iterator<String> ids = jugrix.childOrganizationIds("o:2", null); Assert.assertTrue(ids.hasNext()); Assert.assertEquals(ids.next(),"o:3");
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/cr/ie/tatsuki/functionTest/deepChildOrganizationIdsPlusTest.java Mon Oct 27 08:18:42 2014 +0900 @@ -0,0 +1,28 @@ +package jp.ac.u_ryukyu.cr.ie.tatsuki.functionTest; + +import java.util.Iterator; +import java.util.LinkedList; + +import jp.ac.u_ryukyu.cr.ie.tatsuki.bbs.JuGrix; + +import org.junit.Assert; +import org.junit.Test; + +public class deepChildOrganizationIdsPlusTest { + + @Test + public void deepChildOrganizationIdsPlusTest(){ + JuGrix jugrix = new JuGrix(); + LinkedList<String> filterIds = new LinkedList<String>(); + filterIds.add("r:9"); + Iterator<String> childrenIds = jugrix.deepChildOrganizationIdsPlus("o:2", filterIds); + Assert.assertTrue(childrenIds.hasNext()); + Assert.assertEquals(childrenIds.next(),"o:2"); + + filterIds = new LinkedList<String>(); + filterIds.add("r:5"); + childrenIds = jugrix.deepChildOrganizationIdsPlus("o:2", filterIds); + Assert.assertTrue(childrenIds.hasNext()); + Assert.assertEquals(childrenIds.next(),"o:4"); + } +}