Mercurial > hg > Members > tatsuki > JungleXMLReader
changeset 11:67305f53aad0
change fj List to LinkedList
author | one |
---|---|
date | Sat, 25 Oct 2014 17:10:03 +0900 |
parents | ccb74917f06a |
children | f93d15042315 2ecced397007 |
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/PersonIdsTest.java |
diffstat | 2 files changed, 109 insertions(+), 47 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/cr/ie/tatsuki/bbs/JuGrix.java Sat Oct 25 10:52:50 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/cr/ie/tatsuki/bbs/JuGrix.java Sat Oct 25 17:10:03 2014 +0900 @@ -1,10 +1,10 @@ package jp.ac.u_ryukyu.cr.ie.tatsuki.bbs; import java.util.Iterator; +import java.util.LinkedList; import java.util.regex.Matcher; import java.util.regex.Pattern; -import fj.data.List; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.Jungle; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; @@ -49,21 +49,21 @@ public Iterator<String> personIds(String id){ - List<String> names = personIdsSearch(id); + LinkedList<String> names = personIdsSearch(id); return names.iterator(); } - public Iterator<String> personIds(List<String> ids){ + public Iterator<String> personIds(LinkedList<String> ids){ - List<String> personIds = List.nil(); - + LinkedList<String> personIds = new LinkedList(); + for (String id : ids) { - personIds = personIds.append(personIdsSearch(id)); + personIds.addAll(personIdsSearch(id)); } return personIds.iterator(); } - private List<String> personIdsSearch(String id) { + private LinkedList<String> personIdsSearch(String id) { InterfaceTraverser ifTraverser = personTree.getTraverser(); Iterator<Pair<TreeNode,NodePath>> pairPersonIterator = ifTraverser.find( (TreeNode node) -> { @@ -76,7 +76,7 @@ } ,"element","Person"); - List<String> names = List.nil(); + LinkedList<String> names = new LinkedList<String>(); for (;pairPersonIterator.hasNext();) { Pair<TreeNode, NodePath> pairPerson = pairPersonIterator.next(); @@ -91,7 +91,7 @@ } ,pairPerson.left(),"text",id); if (pairIdIterator.hasNext()) - names = names.cons(pairPerson.left().getAttributes().getString("id")); + names.add(pairPerson.left().getAttributes().getString("id")); } return names; @@ -132,7 +132,7 @@ } ,"id",id); - List<String> ids = List.nil(); + LinkedList<String> ids = new LinkedList<String>(); for (;searchTargetIterator.hasNext();) { @@ -163,7 +163,7 @@ } if (attribute != null) { - ids = ids.cons(attribute); + ids.add(attribute); System.out.println("-------------------------" + attribute + "-------------------------"); } } @@ -175,21 +175,7 @@ public Iterator<String> competentRoleId(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"); + Iterator<Pair<TreeNode, NodePath>> pairPersonIterator = searchPerson(personId, ifTraverser); if (!pairPersonIterator.hasNext()) return new NullIterator(); @@ -212,14 +198,14 @@ ,person); - List<String> idList = List.nil(); + 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(person, targetPath); String id = targetNode.getAttributes().getString("text"); - idList = idList.cons(id); + idList.add(id); } return idList.iterator(); @@ -229,21 +215,8 @@ 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"); + Iterator<Pair<TreeNode, NodePath>> pairPersonIterator = searchPerson( + personId, ifTraverser); if (!pairPersonIterator.hasNext()) return new NullIterator(); @@ -266,18 +239,106 @@ ,person); - List<String> idList = List.nil(); + 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(person, targetPath); String id = targetNode.getAttributes().getString("text"); - idList = idList.cons(id); + idList.add(id); } return idList.iterator(); } + private Iterator<Pair<TreeNode, NodePath>> searchPerson(String personId, + 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("Person")) + return false; + String nodeId = node.getAttributes().getString("id"); + if (nodeId == null) + return false; + if (nodeId.equals(personId)) + return true; + return false; + } + ,"element","Person"); + return pairPersonIterator; + } + + + public Iterator<String> childOrganizationIds(String orgId) { + InterfaceTraverser ifTraverser = organizationTree.getTraverser(); + Iterator<Pair<TreeNode, NodePath>> pairPersonIterator = searchOrganization(orgId, ifTraverser); + + if (!pairPersonIterator.hasNext()) + return new NullIterator(); + TreeNode person = pairPersonIterator.next().left(); + + Iterator<Pair<TreeNode,NodePath>> chilrenOrgIdsIterator = ifTraverser.find( + (TreeNode node) -> { + String nodeElement = node.getAttributes().getString("element"); + if (nodeElement == null) + return false; + if (nodeElement.equals("childOrganizations")) + return true; + return false; + } + ,person); + + if (!chilrenOrgIdsIterator.hasNext()) + return new NullIterator(); + + TreeNode chilerenOrgIds = chilrenOrgIdsIterator.next().left(); + + Iterator<Pair<TreeNode,NodePath>> chilrenOrgIdIterator = ifTraverser.find( + (TreeNode node) -> { + String nodeElement = node.getAttributes().getString("element"); + if (nodeElement == null) + return false; + if (!nodeElement.equals("organizationRefIds")) + return false; + nodeElement = node.getAttributes().getString("text"); + if (nodeElement != null) + return true; + return false; + } + ,person); + + LinkedList<String> ids = new LinkedList<String>(); + + for (;chilrenOrgIdIterator.hasNext();) { + ids.add(chilrenOrgIdIterator.next().left().getAttributes().getString("text")); + } + + return ids.iterator(); + } + + + 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; @@ -313,4 +374,5 @@ } + }
--- a/src/test/java/jp/ac/u_ryukyu/cr/ie/tatsuki/functionTest/PersonIdsTest.java Sat Oct 25 10:52:50 2014 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/cr/ie/tatsuki/functionTest/PersonIdsTest.java Sat Oct 25 17:10:03 2014 +0900 @@ -18,9 +18,9 @@ Iterator<String> ids = jugrix.personIds("o:2"); ids.hasNext(); - Assert.assertEquals(ids.next(),"p:45"); + Assert.assertEquals(ids.next(),"p:1"); ids.hasNext(); - Assert.assertEquals(ids.next(),"p:1"); + Assert.assertEquals(ids.next(),"p:45"); } }