Mercurial > hg > Members > tatsuki > JungleXMLReader
changeset 21:daf0c3c810f9
add deepParentOrganizationIdsTest and Method
author | one |
---|---|
date | Mon, 27 Oct 2014 09:16:22 +0900 |
parents | ae739e8d86a2 |
children | b6b5e3f48988 |
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/deepParentOrganizationIdsTest.java |
diffstat | 2 files changed, 55 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/cr/ie/tatsuki/bbs/JuGrix.java Mon Oct 27 08:50:16 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/cr/ie/tatsuki/bbs/JuGrix.java Mon Oct 27 09:16:22 2014 +0900 @@ -627,6 +627,9 @@ } public Iterator<String> parentOrganizationIds(String orgId, LinkedList<String> filterIds) { + return _parentOrganizationIds(orgId, filterIds).iterator(); + } + public LinkedList<String> _parentOrganizationIds(String orgId, LinkedList<String> filterIds) { InterfaceTraverser orgTraverser = organizationTree.getTraverser(); Iterator<Pair<TreeNode,NodePath>> orgIterator = orgTraverser.find( @@ -645,7 +648,7 @@ }); if (!orgIterator.hasNext()) - return new NullIterator(); + return new LinkedList<String>(); TreeNode orgNode = orgIterator.next().left(); @@ -686,7 +689,28 @@ } - return parentIds.iterator(); + return parentIds; + } + + public Iterator<String> deepParentOrganizationIds(String orgId, LinkedList<String> filterIds) { + return _deepParentOrganizationIds(orgId, filterIds).iterator(); + } + public LinkedList<String> _deepParentOrganizationIds(String orgId, LinkedList<String> filterIds) { + + + Iterator<String> parentIds = parentOrganizationIds(orgId, filterIds); + if (!parentIds.hasNext()) + return new LinkedList<String>(); + + LinkedList<String> parentIdList = new LinkedList<String>(); + + for (;parentIds.hasNext();) { + String parentId = parentIds.next(); + if (filter(parentId, filterIds)) + parentIdList.add(parentId); + parentIdList.addAll(_deepParentOrganizationIds(parentId, filterIds)); + } + return parentIdList; }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/cr/ie/tatsuki/functionTest/deepParentOrganizationIdsTest.java Mon Oct 27 09:16:22 2014 +0900 @@ -0,0 +1,29 @@ +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 junit.framework.Assert; + +import org.junit.Test; + +public class deepParentOrganizationIdsTest { + + @Test + public void deepParentOrganizationIds(){ + JuGrix jugrix = new JuGrix(); + LinkedList<String> filterIds = new LinkedList<String>(); + //filterIds.add("r:2"); + Iterator<String> childrenIds = jugrix.deepParentOrganizationIds("o:2", filterIds); + + Assert.assertEquals(childrenIds.next(),"o:23"); + Assert.assertEquals(childrenIds.next(),"o:22"); + + filterIds.add("r:2"); + childrenIds = jugrix.deepParentOrganizationIds("o:2", filterIds); + + Assert.assertEquals(childrenIds.next(),"o:23"); + + } +}