Mercurial > hg > Members > tatsuki > JungleXMLReader
changeset 9:28f383f677ff
add competentRoledTest and method
author | one |
---|---|
date | Sat, 25 Oct 2014 10:43:20 +0900 |
parents | 378bfec11a8d |
children | ccb74917f06a |
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/competentRoleIdTest.java |
diffstat | 2 files changed, 85 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/cr/ie/tatsuki/bbs/JuGrix.java Sat Oct 25 09:55:00 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/cr/ie/tatsuki/bbs/JuGrix.java Sat Oct 25 10:43:20 2014 +0900 @@ -10,6 +10,8 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.InterfaceTraverser; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; public class JuGrix { @@ -131,6 +133,7 @@ ,"id",id); List<String> ids = List.nil(); + for (;searchTargetIterator.hasNext();) { Pair<TreeNode, NodePath> searchTargetPair = searchTargetIterator.next(); @@ -188,8 +191,70 @@ } ,"element","Person"); - return null; + 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(); + int num = pathNode.left(); + NodePath newPath = pathNode.right(); + if (num == -1 && newPath.size() != 0) + return getTarget(node, newPath); + + Either<Error, TreeNode> either = node.getChildren().at(num); + if (either.isA()) + return node; + + TreeNode child = either.b(); + if (pathNode.right().size() == 0) + return child; + + target = getTarget(child,pathNode.right()); + return target; + } + class NullIterator implements Iterator<String>{ + @Override + public boolean hasNext() { + return false; + } + + @Override + public String next() { + return null; + } + + } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/cr/ie/tatsuki/functionTest/competentRoleIdTest.java Sat Oct 25 10:43:20 2014 +0900 @@ -0,0 +1,19 @@ +package jp.ac.u_ryukyu.cr.ie.tatsuki.functionTest; + +import java.util.Iterator; + +import jp.ac.u_ryukyu.cr.ie.tatsuki.bbs.JuGrix; +import junit.framework.Assert; + +import org.junit.Test; + +public class competentRoleIdTest { + + @Test + public void competentRoleIdTest(){ + JuGrix jugrix = new JuGrix(); + Iterator<String> roleIds = jugrix.competentRoleId("p:1"); + Assert.assertTrue(roleIds.hasNext()); + Assert.assertEquals(roleIds.next(), "r:10"); + } +}