Mercurial > hg > Members > tatsuki > JungleXMLReader
changeset 10:ccb74917f06a
add concurrentRoleIdsTest and method
author | one |
---|---|
date | Sat, 25 Oct 2014 10:52:50 +0900 |
parents | 28f383f677ff |
children | 67305f53aad0 |
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/concurrentRoleIdsTest.java |
diffstat | 2 files changed, 79 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/cr/ie/tatsuki/bbs/JuGrix.java Sat Oct 25 10:43:20 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/cr/ie/tatsuki/bbs/JuGrix.java Sat Oct 25 10:52:50 2014 +0900 @@ -225,6 +225,60 @@ return idList.iterator(); } + + public Iterator<String> concurrentRoleIds(String personId) { + + InterfaceTraverser ifTraverser = personTree.getTraverser(); + Iterator<Pair<TreeNode,NodePath>> pairPersonIterator = ifTraverser.find( + (TreeNode node) -> { + String nodeElement = node.getAttributes().getString("element"); + if (nodeElement == null) + return false; + if (!nodeElement.equals("Person")) + return false; + String nodeId = node.getAttributes().getString("id"); + if (nodeId == null) + return false; + if (nodeId.equals(personId)) + return true; + return false; + } + ,"element","Person"); + + if (!pairPersonIterator.hasNext()) + return new NullIterator(); + TreeNode person = pairPersonIterator.next().left(); + + Iterator<Pair<TreeNode,NodePath>> targetPairIterator = ifTraverser.find( + (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"); + if (priority == null) + return false; + if (!priority.equals("0")) + return true; + return false; + } + ,person); + + + List<String> idList = List.nil(); + 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(person, targetPath); + String id = targetNode.getAttributes().getString("text"); + idList = idList.cons(id); + } + + return idList.iterator(); + } + public TreeNode getTarget(TreeNode node , NodePath path){ TreeNode target; Pair<Integer, NodePath> pathNode = path.pop(); @@ -244,6 +298,7 @@ target = getTarget(child,pathNode.right()); return target; } + class NullIterator implements Iterator<String>{ @Override @@ -257,4 +312,5 @@ } } + }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/cr/ie/tatsuki/functionTest/concurrentRoleIdsTest.java Sat Oct 25 10:52:50 2014 +0900 @@ -0,0 +1,23 @@ +package jp.ac.u_ryukyu.cr.ie.tatsuki.functionTest; + +import java.util.Iterator; + +import org.junit.Test; +import org.junit.experimental.theories.suppliers.TestedOn; + +import jp.ac.u_ryukyu.cr.ie.tatsuki.bbs.JuGrix; +import junit.framework.Assert; + +public class concurrentRoleIdsTest { + + @Test + public void concurrentRoleIdsTest() { + JuGrix jugrix = new JuGrix(); + Iterator<String> roleIds = jugrix.concurrentRoleIds("p:1"); + Assert.assertTrue(roleIds.hasNext()); + Assert.assertEquals(roleIds.next(), "r:34"); + + roleIds = jugrix.concurrentRoleIds("p:48"); + Assert.assertFalse(roleIds.hasNext()); + } +}