# HG changeset patch # User one # Date 1416217630 -32400 # Node ID 037731e99d6e876ecc1ef2d921d2ce5f71974376 # Parent 59a7d2cffc86acf39552732c70f51745c63f853e fit JungleCore 144 diff -r 59a7d2cffc86 -r 037731e99d6e src/main/java/ac/jp/u_ryukyu/cr/ie/tatsuki/xmlReader/ReadXmlHandler.java --- a/src/main/java/ac/jp/u_ryukyu/cr/ie/tatsuki/xmlReader/ReadXmlHandler.java Thu Nov 13 23:34:41 2014 +0900 +++ b/src/main/java/ac/jp/u_ryukyu/cr/ie/tatsuki/xmlReader/ReadXmlHandler.java Mon Nov 17 18:47:10 2014 +0900 @@ -15,118 +15,124 @@ import org.xml.sax.*; import org.xml.sax.helpers.*; - public class ReadXmlHandler extends DefaultHandler { - private JungleTree tree; - private JungleTreeEditor editor; - private NodePath path; + private JungleTree tree; + private JungleTreeEditor editor; + private NodePath path; private String elementName; - - public ReadXmlHandler(JungleTree tree){ - this.tree = tree; - this.editor = tree.getTreeEditor(); - this.path = new DefaultNodePath().add(-1); - } - - @Override - public void startElement(String uri, String localName,String qName, Attributes attributes) { - Pair nodePair = path.last(); - path = nodePair.right(); - int num = nodePair.left() + 1; - - Either either = editor.addNewChildAt(path, num); - if (either.isA()) { - //error - } - this.editor = either.b(); - - path = path.add(num); - //System.out.println(path.toString()); + + public ReadXmlHandler(JungleTree tree) { + this.tree = tree; + this.editor = tree.getTreeEditor(); + this.path = new DefaultNodePath().add(-1); + } + + @Override + public void startElement(String uri, String localName, String qName, Attributes attributes) { + Pair nodePair = path.last(); + path = nodePair.right(); + int num = nodePair.left() + 1; - - if (uri != "") { - // System.out.println("namespaceURI= " + uri); - } + Either either = editor.addNewChildAt(path, num); + if (either.isA()) { + // error + } + this.editor = either.b(); - if (localName != "") { - // System.out.println("localName= " + localName); - } + path = path.add(num); + // System.out.println(path.toString()); + + if (uri != "") { + // System.out.println("namespaceURI= " + uri); + } + + if (localName != "") { + // System.out.println("localName= " + localName); + } if (qName != "") { - // System.out.println("qName= " + qName); + // System.out.println("qName= " + qName); elementName = qName; - Either newEither = editor.putAttribute(path, "element", ByteBuffer.wrap(qName.getBytes())); + Either newEither = editor.putAttribute(path, "element", + ByteBuffer.wrap(qName.getBytes())); if (newEither.isA()) { - //error + // error } this.editor = newEither.b(); } if (attributes.getLength() != 0) { - for (int count = 0 ;attributes.getLength() > count; count++) { - // System.out.println(attributes.getLocalName(count) + " = " + attributes.getValue(count)); + for (int count = 0; attributes.getLength() > count; count++) { + // System.out.println(attributes.getLocalName(count) + " = " + + // attributes.getValue(count)); String key = elementName + "-" + attributes.getLocalName(count); String value = attributes.getValue(count); ByteBuffer bValue = ByteBuffer.wrap(value.getBytes()); - Either newEither = editor.putAttribute(path,key , bValue); + Either newEither = editor.putAttribute(path, key, bValue); if (newEither.isA()) { - //error + // error } this.editor = newEither.b(); } } - path = path.add(-1); - } + path = path.add(-1); + } - @Override - public void characters(char[] ch, int start, int length) { - String str = new String(ch, start, length); - Pattern pattern = Pattern.compile("\n"); - Matcher macher = pattern.matcher(str); - - if (!macher.find()) { + @Override + public void characters(char[] ch, int start, int length) { + String str = new String(ch, start, length); + Pattern pattern = Pattern.compile("\n"); + Matcher macher = pattern.matcher(str); + + if (!macher.find()) { + + String[] splitStrs = str.split(" "); + for (String splitStr : splitStrs) { + Pair nodePair = path.last(); NodePath onePath = nodePair.right(); - //System.out.println(str); - Either newEither = editor.putAttribute(onePath, "text-" + elementName, ByteBuffer.wrap(str.getBytes())); + Either newEither = editor.putAttribute(onePath, "text-" + elementName, + ByteBuffer.wrap(splitStr.getBytes())); if (newEither.isA()) { - //error + // error } this.editor = newEither.b(); + + } } - } + } - @Override - public void endElement(String namespaceURI, String localName, String qName) { - path = path.tail(); - if (namespaceURI != "") { - // System.out.println("namespaceURI= " + namespaceURI); - } - if (localName != "") { - // System.out.println("localName= " + localName); - } - - if (qName != "") { - // System.out.println("qName= " + qName); - } - } + @Override + public void endElement(String namespaceURI, String localName, String qName) { + path = path.tail(); + if (namespaceURI != "") { + // System.out.println("namespaceURI= " + namespaceURI); + } + if (localName != "") { + // System.out.println("localName= " + localName); + } - @Override - public void startDocument() { - // System.out.println("start"); - } + if (qName != "") { + // System.out.println("qName= " + qName); + } + } + + @Override + public void startDocument() { + // System.out.println("start"); + } - @Override - public void endDocument() { - Either either = editor.success(); - if (either.isA()) { - //error - } - // System.out.println("end"); - } + @Override + public void endDocument() { + Either either = editor.success(); + if (either.isA()) { + // error + } + // System.out.println("end"); + } - public JungleTree getTree(){ - return tree; - } + public JungleTree getTree() { + return tree; + } } diff -r 59a7d2cffc86 -r 037731e99d6e src/main/java/jp/ac/u_ryukyu/cr/ie/tatsuki/bbs/GetAttributeImp.java --- a/src/main/java/jp/ac/u_ryukyu/cr/ie/tatsuki/bbs/GetAttributeImp.java Thu Nov 13 23:34:41 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/cr/ie/tatsuki/bbs/GetAttributeImp.java Mon Nov 17 18:47:10 2014 +0900 @@ -1,5 +1,7 @@ package jp.ac.u_ryukyu.cr.ie.tatsuki.bbs; +import java.util.Iterator; + import fj.data.List; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; @@ -10,7 +12,7 @@ node = _node; } - public String getMessage(String key) { + public Iterator getMessage(String key) { return node.getAttributes().getString(key); } diff -r 59a7d2cffc86 -r 037731e99d6e src/main/java/jp/ac/u_ryukyu/cr/ie/tatsuki/bbs/JuGrix.java --- a/src/main/java/jp/ac/u_ryukyu/cr/ie/tatsuki/bbs/JuGrix.java Thu Nov 13 23:34:41 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/cr/ie/tatsuki/bbs/JuGrix.java Mon Nov 17 18:47:10 2014 +0900 @@ -5,6 +5,8 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import javax.lang.model.element.Element; + import ac.jp.u_ryukyu.cr.ie.tatsuki.xmlReader.LoadXml; import fj.Ord; import fj.P2; @@ -45,15 +47,16 @@ e.printStackTrace(); } } + public boolean isActive(String id) { InterfaceTraverser personTraverser = personTree.getTraverser(); Iterator> personIdpairIterator = personTraverser.find((TreeNode node) -> { - String personId = node.getAttributes().getString("Person-id"); - if (personId == null) - return false; - if (personId.equals(id)) - return true; + Iterator personIdIterator = node.getAttributes().getString("Person-id"); + if (personIdIterator.hasNext()) { + if (personIdIterator.next().equals(id)) + return true; + } return false; }, "Person-id", id); @@ -62,13 +65,12 @@ return false; } - public Iterator personIds(String orgId, LinkedList roleIds) { Iterator parentOrgIdIterator = parentOrganizationIds(orgId, roleIds); TreeMap personIdsTreeMap = TreeMap.empty(Ord.stringOrd); - + if (filter(orgId, roleIds)) personIdsTreeMap = personIdsSearch(orgId, personIdsTreeMap); @@ -97,7 +99,6 @@ }; } - public Iterator personIds(LinkedList orgIds, LinkedList roleIds) { TreeMap personIds = TreeMap.empty(Ord.stringOrd); @@ -130,17 +131,17 @@ }; } - + private TreeMap personIdsSearch(String orgId, TreeMap orgIdsTreeMap) { InterfaceTraverser personTraverser = personTree.getTraverser(); Iterator> personIdPairIterator = personTraverser.findAll((TreeNode node) -> { - String personId = node.getAttributes().getString("element"); - if (personId == null) - return false; - if (personId.equals("Person")) - return true; + Iterator personIdIterator = node.getAttributes().getString("element"); + for (; personIdIterator.hasNext();) { + if (personIdIterator.next().equals("Person")) + return true; + } return false; }, "Person-id"); @@ -149,28 +150,27 @@ Pair personIdPair = personIdPairIterator.next(); Iterator> orgIdPairIterator = personTraverser.findInSubTree((TreeNode node) -> { - String personId = node.getAttributes().getString("text-organizationRefId"); - if (personId == null) - return false; - if (personId.equals(orgId)) - return true; + Iterator personIdIterator = node.getAttributes().getString("text-organizationRefId"); + for (; personIdIterator.hasNext();) { + if (personIdIterator.next().equals(orgId)) + return true; + } return false; }, personIdPair, "text-organizationRefId", orgId); if (orgIdPairIterator.hasNext()) { - String personId = personIdPair.left().getAttributes().getString("Person-id"); - if (personId != null) + Iterator personIdIterator = personIdPair.left().getAttributes().getString("Person-id"); + if (personIdIterator.hasNext()) { + String personId = personIdIterator.next(); orgIdsTreeMap = orgIdsTreeMap.set(personId, personId); + } } } return orgIdsTreeMap; } - - + public boolean filter(String orgId, LinkedList roleIds) { - public boolean filter(String orgId, LinkedList roleIds) { - if (roleIds == null) return true; @@ -180,16 +180,16 @@ InterfaceTraverser orgTraverser = organizationTree.getTraverser(); Iterator> orgIdPairIterator = orgTraverser.find((TreeNode node) -> { - String personId = node.getAttributes().getString("element"); - if (personId == null) - return false; - if (!personId.equals("Organization")) - return false; - String compareOrgId = node.getAttributes().getString("Organization-id"); - if (compareOrgId == null) - return false; - if (compareOrgId.equals(orgId)) - return true; + Iterator personIdIterator = node.getAttributes().getString("element"); + for (; personIdIterator.hasNext();) { + if (!personIdIterator.next().equals("Organization")) + continue; + Iterator compareOrgIdIterator = node.getAttributes().getString("Organization-id"); + for (; compareOrgIdIterator.hasNext();) { + if (compareOrgIdIterator.next().equals(orgId)) + return true; + } + } return false; }, "Organization-id", orgId); @@ -215,28 +215,31 @@ } return true; } - + private boolean rdeFilter(String filterRdeId, Pair searchNodePair) { InterfaceTraverser orgTraverser = organizationTree.getTraverser(); - + Iterator> orgRoleIdPairIterator = orgTraverser.findInSubTreeAllValue((TreeNode node) -> { - String element = node.getAttributes().getString("element"); - if (element == null) + Iterator element = node.getAttributes().getString("element"); + if (!element.hasNext()) return false; - if (!element.equals("roleRefId")) + if (!element.next().equals("roleRefId")) return false; - String roleId = node.getAttributes().getString("text-roleRefId"); - if (roleId != null) + Iterator roleId = node.getAttributes().getString("text-roleRefId"); + if (roleId.hasNext()) return true; return false; }, searchNodePair, "text-roleRefId"); TreeMap orgRoleIdMap = TreeMap.empty(Ord.stringOrd); - + for (; orgRoleIdPairIterator.hasNext();) { - String roleId = orgRoleIdPairIterator.next().left().getAttributes().getString("text-roleRefId"); - orgRoleIdMap = orgRoleIdMap.set(roleId, roleId); + Iterator roleIdIterator = orgRoleIdPairIterator.next().left().getAttributes().getString("text-roleRefId"); + for (; roleIdIterator.hasNext();) { + String roleId = roleIdIterator.next(); + orgRoleIdMap = orgRoleIdMap.set(roleId, roleId); + } } Iterator> orgRoleIdP2Iterator = orgRoleIdMap.iterator(); @@ -244,35 +247,35 @@ for (; orgRoleIdP2Iterator.hasNext();) { String orgRoleId = orgRoleIdP2Iterator.next()._1(); - + Iterator> roleIdPairIterator = roleTraverser.find((TreeNode node) -> { - String element = node.getAttributes().getString("element"); - if (element == null) + Iterator element = node.getAttributes().getString("element"); + if (!element.hasNext()) return false; - if (!element.equals("Role")) + if (!element.next().equals("Role")) return false; - String compareRoleId = node.getAttributes().getString("Role-id"); - if (compareRoleId == null) - return false; - if (compareRoleId.equals(orgRoleId)) - return true; + Iterator compareRoleIdIterator = node.getAttributes().getString("Role-id"); + for (; compareRoleIdIterator.hasNext();) { + if (compareRoleIdIterator.next().equals(orgRoleId)) + return true; + } return false; }, "Role-id", orgRoleId); for (; roleIdPairIterator.hasNext();) { - + Pair rolePair = roleIdPairIterator.next(); Iterator> rdeIdPairIterator = roleTraverser.findInSubTree((TreeNode node) -> { - String elementName = node.getAttributes().getString("element"); - if (elementName == null) + Iterator element = node.getAttributes().getString("element"); + if (!element.hasNext()) return false; - if (!elementName.equals("roleDescriptionElementRefIds")) + if (!element.next().equals("roleDescriptionElementRefIds")) return false; - String rdeId = node.getAttributes().getString("text-roleDescriptionElementRefIds"); - if (rdeId == null) - return false; - if (rdeId.equals(filterRdeId)) - return true; + Iterator rdeIdIterator = node.getAttributes().getString("text-roleDescriptionElementRefIds"); + for (; rdeIdIterator.hasNext();) { + if (rdeIdIterator.next().equals(filterRdeId)) + return true; + } return false; }, rolePair, "text-roleDescriptionElementRefIds", filterRdeId); @@ -283,22 +286,22 @@ } return true; } - + public boolean roleFilter(String id, Pair searchNodePair) { // System.out.println(searchNodePair.getAttributes().getString("id")); InterfaceTraverser orgTraverser = organizationTree.getTraverser(); Iterator> roleIdPairIterator = orgTraverser.findInSubTree((TreeNode node) -> { - String elementName = node.getAttributes().getString("element"); - if (elementName == null) + Iterator elementName = node.getAttributes().getString("element"); + if (!elementName.hasNext()) return false; - if (!elementName.equals("roleRefIds")) + if (!elementName.next().equals("roleRefIds")) return false; - String roleId = node.getAttributes().getString("text-roleRefIds"); - if (roleId == null) - return false; - if (roleId.equals(id)) - return true; + Iterator roleId = node.getAttributes().getString("text-roleRefIds"); + for (; roleId.hasNext();) { + if (roleId.next().equals(id)) + return true; + } return false; }, searchNodePair, "text-roleRefIds", id); @@ -307,7 +310,7 @@ } return true; } - + public Iterator roleIds(String id) { Pattern personPattern = Pattern.compile("p:"); Matcher personMacher = personPattern.matcher(id); @@ -323,49 +326,50 @@ return new NullIterator(); } - public Iterator searchRoleIds(JungleTree tree, String id, String element) { InterfaceTraverser traverser = tree.getTraverser(); Iterator> idPairIterator = traverser.find((TreeNode node) -> { - String nodeElement = node.getAttributes().getString("element"); - if (nodeElement == null) + Iterator nodeElement = node.getAttributes().getString("element"); + if (!nodeElement.hasNext()) return false; - if (!nodeElement.equals(element)) + if (!nodeElement.next().equals(element)) return false; - String nodeId = node.getAttributes().getString(element + "-id"); - if (nodeId == null) - return false; - if (nodeId.equals(id)) - return true; + Iterator nodeIdIterator = node.getAttributes().getString(element + "-id"); + for (; nodeIdIterator.hasNext();) { + if (nodeIdIterator.next().equals(id)) + return true; + } return false; }, element + "-id", id); TreeMap idsTreeMap = TreeMap.empty(Ord.stringOrd); - ; for (; idPairIterator.hasNext();) { Pair targetPair = idPairIterator.next(); Iterator> roleIdPairIterator = traverser.findInSubTreeAllValue((TreeNode node) -> { - String nodeElement = node.getAttributes().getString("element"); - if (nodeElement == null) + Iterator nodeElement = node.getAttributes().getString("element"); + if (!nodeElement.hasNext()) return false; - if (!nodeElement.equals("roleRefId")) + if (!nodeElement.next().equals("roleRefId")) return false; - String nodeId = node.getAttributes().getString("text-roleRefId"); - if (nodeId != null) + Iterator nodeIdIterator = node.getAttributes().getString("text-roleRefId"); + if (nodeIdIterator.hasNext()) return true; return false; }, targetPair, "text-roleRefId"); for (; roleIdPairIterator.hasNext();) { Pair roleIdPair = roleIdPairIterator.next(); - String roleId = roleIdPair.left().getAttributes().getString("text-roleRefId"); - idsTreeMap = idsTreeMap.set(roleId, roleId); + Iterator roleIdIterator = roleIdPair.left().getAttributes().getString("text-roleRefId"); + for (; roleIdIterator.hasNext();) { + String roleId = roleIdIterator.next(); + idsTreeMap = idsTreeMap.set(roleId, roleId); + } } } @@ -390,20 +394,19 @@ }; } - public Iterator competentRoleId(String personId) { InterfaceTraverser personTraverser = personTree.getTraverser(); Iterator> personIdPairIterator = personTraverser.find((TreeNode node) -> { - String nodeElement = node.getAttributes().getString("element"); - if (nodeElement == null) + Iterator nodeElement = node.getAttributes().getString("element"); + if (!nodeElement.hasNext()) return false; - if (!nodeElement.equals("Person")) + if (!nodeElement.next().equals("Person")) return false; - String nodeId = node.getAttributes().getString("Person-id"); - if (nodeId == null) + Iterator nodeIdIterator = node.getAttributes().getString("Person-id"); + if (!nodeIdIterator.hasNext()) return false; - if (nodeId.equals(personId)) + if (nodeIdIterator.next().equals(personId)) return true; return false; }, "Person-id", personId); @@ -414,16 +417,16 @@ Pair personIdPair = personIdPairIterator.next(); Iterator> priorityPairIterator = personTraverser.findInSubTree((TreeNode node) -> { - String nodeElement = node.getAttributes().getString("element"); - if (nodeElement == null) + Iterator nodeElement = node.getAttributes().getString("element"); + if (!nodeElement.hasNext()) return false; - if (!nodeElement.equals("priority")) + if (!nodeElement.next().equals("priority")) return false; - String priority = node.getAttributes().getString("text-priority"); - if (priority == null) - return false; - if (priority.equals("0")) - return true; + Iterator priorityIterator = node.getAttributes().getString("text-priority"); + for (; priorityIterator.hasNext();) { + if (priorityIterator.next().equals("0")) + return true; + } return false; }, personIdPair, "text-priority", "0"); @@ -436,74 +439,9 @@ Pair removeLastPair = priorityPath.last(); NodePath roleIdNodePath = removeLastPair.right().add(removeLastPair.left() + 1); TreeNode roleIdNode = getTarget(personTree.getRootNode(), roleIdNodePath); - String roleId = roleIdNode.getAttributes().getString("text-roleRefId"); - roleIdTreeMap = roleIdTreeMap.set(roleId, roleId); - } - Iterator> roleIdP2Iterator = roleIdTreeMap.iterator(); - return new Iterator() { - - @Override - public boolean hasNext() { - if (roleIdP2Iterator.hasNext()) - return true; - return false; - } - - @Override - public String next() { - return roleIdP2Iterator.next()._1(); - } - }; - } - - public Iterator concurrentRoleIds(String personId) { - - InterfaceTraverser personTraverser = personTree.getTraverser(); - Iterator> personIdPairIterator = personTraverser.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("Person-id"); - if (nodeId == null) - return false; - if (nodeId.equals(personId)) - return true; - return false; - }, "Person-id", personId); - - if (!personIdPairIterator.hasNext()) - return new NullIterator(); - - Pair personidPair = personIdPairIterator.next(); - - Iterator> priorityPairIterator = personTraverser.findInSubTreeAllValue( - (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-priority"); - if (priority != null) - return true; - return false; - }, personidPair, "text-priority"); - - TreeMap roleIdTreeMap = TreeMap.empty(Ord.stringOrd); - - for (; priorityPairIterator.hasNext();) { - - Pair priorityPair = priorityPairIterator.next(); - TreeNode priorityNode = priorityPair.left(); - int priority = Integer.parseInt(priorityNode.getAttributes().getString("text-priority")); - if (priority > 0) { - NodePath priorityPath = priorityPair.right(); - Pair removeLastPair = priorityPath.last(); - NodePath roleIdNodePath = removeLastPair.right().add(removeLastPair.left() + 1); - TreeNode roleIdNode = getTarget(personTree.getRootNode(), roleIdNodePath); - String roleId = roleIdNode.getAttributes().getString("text-roleRefId"); + Iterator roleIdIterator = roleIdNode.getAttributes().getString("text-roleRefId"); + for (; roleIdIterator.hasNext();) { + String roleId = roleIdIterator.next(); roleIdTreeMap = roleIdTreeMap.set(roleId, roleId); } } @@ -523,13 +461,87 @@ } }; } - + + public Iterator concurrentRoleIds(String personId) { + + InterfaceTraverser personTraverser = personTree.getTraverser(); + Iterator> personIdPairIterator = personTraverser.find((TreeNode node) -> { + Iterator nodeElement = node.getAttributes().getString("element"); + if (!nodeElement.hasNext()) + return false; + if (!nodeElement.next().equals("Person")) + return false; + Iterator nodeId = node.getAttributes().getString("Person-id"); + for (; nodeId.hasNext();) { + if (nodeId.next().equals(personId)) + return true; + } + return false; + }, "Person-id", personId); + + if (!personIdPairIterator.hasNext()) + return new NullIterator(); + + Pair personidPair = personIdPairIterator.next(); + + Iterator> priorityPairIterator = personTraverser.findInSubTreeAllValue( + (TreeNode node) -> { + Iterator nodeElement = node.getAttributes().getString("element"); + if (!nodeElement.hasNext()) + return false; + if (!nodeElement.next().equals("priority")) + return false; + Iterator priorityIterator = node.getAttributes().getString("text-priority"); + if (priorityIterator.hasNext()) + return true; + return false; + }, personidPair, "text-priority"); + + TreeMap roleIdTreeMap = TreeMap.empty(Ord.stringOrd); + + for (; priorityPairIterator.hasNext();) { + + Pair priorityPair = priorityPairIterator.next(); + TreeNode priorityNode = priorityPair.left(); + Iterator priorityIterator = priorityNode.getAttributes().getString("text-priority"); + for (; priorityIterator.hasNext();) { + int priority = Integer.parseInt(priorityIterator.next()); + if (priority > 0) { + NodePath priorityPath = priorityPair.right(); + Pair removeLastPair = priorityPath.last(); + NodePath roleIdNodePath = removeLastPair.right().add(removeLastPair.left() + 1); + TreeNode roleIdNode = getTarget(personTree.getRootNode(), roleIdNodePath); + Iterator roleIdIterator = roleIdNode.getAttributes().getString("text-roleRefId"); + for (; roleIdIterator.hasNext();) { + String roleId = roleIdIterator.next(); + roleIdTreeMap = roleIdTreeMap.set(roleId, roleId); + } + } + } + } + + Iterator> roleIdP2Iterator = roleIdTreeMap.iterator(); + return new Iterator() { + + @Override + public boolean hasNext() { + if (roleIdP2Iterator.hasNext()) + return true; + return false; + } + + @Override + public String next() { + return roleIdP2Iterator.next()._1(); + } + }; + } + public Iterator deepPersonIds(String orgId, LinkedList filterIds) { - + TreeMap personIdsTreeMap = TreeMap.empty(Ord.stringOrd); Iterator childrensIterator = deepChildOrganizationIdsPlus(orgId, filterIds); - - + if (!childrensIterator.hasNext()) return new NullIterator(); @@ -557,7 +569,6 @@ } }; } - public Iterator deepChildOrganizationIdsPlus(String orgId, LinkedList filterIds) { TreeMap orgIdsTreeMap = TreeMap.empty(Ord.stringOrd); @@ -589,7 +600,7 @@ } }; } - + public Iterator deepChildOrganizationIds(String orgId, LinkedList filterIds) { TreeMap orgIdsTreeMap = TreeMap.empty(Ord.stringOrd); @@ -618,7 +629,7 @@ } }; } - + public TreeMap _deepChildOrganizationIds(String orgId, TreeMap orgIdsTreeMap) { TreeMap childrenIdTreeMap = _childOrganizationIds(orgId, TreeMap.empty(Ord.stringOrd)); @@ -673,16 +684,16 @@ InterfaceTraverser orgTraverser = organizationTree.getTraverser(); Iterator> orgIdPairIterator = orgTraverser.find((TreeNode node) -> { - String nodeElement = node.getAttributes().getString("element"); - if (nodeElement == null) + Iterator nodeElement = node.getAttributes().getString("element"); + if (!nodeElement.hasNext()) return false; - if (!nodeElement.equals("Organization")) + if (!nodeElement.next().equals("Organization")) return false; - String nodeId = node.getAttributes().getString("Organization-id"); - if (nodeId == null) - return false; - if (nodeId.equals(orgId)) - return true; + Iterator nodeIdIterator = node.getAttributes().getString("Organization-id"); + for (; nodeIdIterator.hasNext();) { + if (nodeIdIterator.next().equals(orgId)) + return true; + } return false; }, "Organization-id", orgId); @@ -692,10 +703,10 @@ Pair orgIdPair = orgIdPairIterator.next(); Iterator> chilrenOrgPairIterator = orgTraverser.findInSubTree((TreeNode node) -> { - String nodeElement = node.getAttributes().getString("element"); - if (nodeElement == null) + Iterator nodeElement = node.getAttributes().getString("element"); + if (!nodeElement.hasNext()) return false; - if (nodeElement.equals("childOrganizations")) + if (nodeElement.next().equals("childOrganizations")) return true; return false; }, orgIdPair, "element", "childOrganizations"); @@ -707,22 +718,24 @@ Iterator> chilrenOrgIdPairIterator = orgTraverser.findInSubTreeAllValue( (TreeNode node) -> { - String nodeElement = node.getAttributes().getString("element"); - if (nodeElement == null) + Iterator nodeElement = node.getAttributes().getString("element"); + if (!nodeElement.hasNext()) return false; - if (!nodeElement.equals("organizationRefIds")) + if (!nodeElement.next().equals("organizationRefIds")) return false; - nodeElement = node.getAttributes().getString("text-organizationRefIds"); - if (nodeElement != null) + Iterator nodeText = node.getAttributes().getString("text-organizationRefIds"); + if (nodeText.hasNext()) return true; return false; }, chilerenOrg, "text-organizationRefIds"); for (; chilrenOrgIdPairIterator.hasNext();) { - String childrenOrgId = chilrenOrgIdPairIterator.next().left().getAttributes() + Iterator childrenOrgIdIterator = chilrenOrgIdPairIterator.next().left().getAttributes() .getString("text-organizationRefIds"); - childOrgIdsTreeMap = childOrgIdsTreeMap.set(childrenOrgId, childrenOrgId); - + for (; childrenOrgIdIterator.hasNext();) { + String childrenOrgId = childrenOrgIdIterator.next(); + childOrgIdsTreeMap = childOrgIdsTreeMap.set(childrenOrgId, childrenOrgId); + } } return childOrgIdsTreeMap; @@ -747,16 +760,16 @@ InterfaceTraverser personTraverser = personTree.getTraverser(); Iterator> personIdPairIterator = personTraverser.find((TreeNode node) -> { - String element = node.getAttributes().getString("element"); - if (element == null) + Iterator element = node.getAttributes().getString("element"); + if (!element.hasNext()) return false; - if (!element.equals("Person")) + if (!element.next().equals("Person")) return false; - String nodePersonId = node.getAttributes().getString("Person-id"); - if (nodePersonId == null) - return false; - if (nodePersonId.equals(personId)) - return true; + Iterator nodePersonId = node.getAttributes().getString("Person-id"); + for (; nodePersonId.hasNext();) { + if (nodePersonId.next().equals(personId)) + return true; + } return false; }, "Person-id", personId); @@ -766,16 +779,16 @@ Pair targetPersonIdPair = personIdPairIterator.next(); Iterator> roleIdPairIterator = personTraverser.findInSubTree((TreeNode node) -> { - String element = node.getAttributes().getString("element"); - if (element == null) + Iterator element = node.getAttributes().getString("element"); + if (!element.hasNext()) return false; - if (!element.equals("roleRefId")) + if (!element.next().equals("roleRefId")) return false; - String compareRoleId = node.getAttributes().getString("text-roleRefId"); - if (compareRoleId == null) - return false; - if (compareRoleId.equals(roleId)) - return true; + Iterator compareRoleId = node.getAttributes().getString("text-roleRefId"); + for (; compareRoleId.hasNext();) { + if (compareRoleId.next().equals(roleId)) + return true; + } return false; }, targetPersonIdPair, "text-roleRefId", roleId); @@ -785,8 +798,14 @@ Pair removeLastPath = roleIdNodePath.last(); NodePath priorityNodePath = removeLastPath.right().add(removeLastPath.left() - 1); TreeNode priorityNode = getTarget(personTree.getRootNode(), priorityNodePath); - if (priorityNode.getAttributes().getString("element").equals("priority")) - return priorityNode.getAttributes().getString("text-priority"); + Iterator element = priorityNode.getAttributes().getString("element"); + if (element.hasNext()) { + if (element.next().equals("priority")) { + Iterator priority = priorityNode.getAttributes().getString("text-priority"); + if (priority.hasNext()) + return priority.next(); + } + } } return ""; } @@ -823,16 +842,16 @@ InterfaceTraverser orgTraverser = organizationTree.getTraverser(); Iterator> orgIdPairIterator = orgTraverser.find((TreeNode node) -> { - String element = node.getAttributes().getString("element"); - if (element == null) + Iterator element = node.getAttributes().getString("element"); + if (!element.hasNext()) return false; - if (!element.equals("Organization")) + if (!element.next().equals("Organization")) return false; - String nodeId = node.getAttributes().getString("Organization-id"); - if (nodeId == null) - return false; - if (nodeId.equals(orgId)) - return true; + Iterator nodeIdIterator = node.getAttributes().getString("Organization-id"); + for (; nodeIdIterator.hasNext();) { + if (nodeIdIterator.next().equals(orgId)) + return true; + } return false; }, "Organization-id", orgId); @@ -842,10 +861,10 @@ Pair orgNode = orgIdPairIterator.next(); Iterator> parentOrgPairIterator = orgTraverser.findInSubTree((TreeNode node) -> { - String element = node.getAttributes().getString("element"); - if (element == null) + Iterator element = node.getAttributes().getString("element"); + if (!element.hasNext()) return false; - if (element.equals("parentOrganizations")) + if (element.next().equals("parentOrganizations")) return true; return false; }, orgNode, "element", "parentOrganizations"); @@ -857,20 +876,24 @@ Iterator> parentOrgIdPairIterator = orgTraverser.findInSubTreeAllValue( (TreeNode node) -> { - String element = node.getAttributes().getString("element"); - if (element == null) + Iterator element = node.getAttributes().getString("element"); + if (!element.hasNext()) return false; - if (!element.equals("organizationRefId")) + if (!element.next().equals("organizationRefId")) return false; - String parentId = node.getAttributes().getString("text-organizationRefId"); - if (parentId != null) + Iterator parentIdIterator = node.getAttributes().getString("text-organizationRefId"); + if (parentIdIterator.hasNext()) return true; return false; }, parentOrgNode, "text-organizationRefId"); for (; parentOrgIdPairIterator.hasNext();) { - String parentId = parentOrgIdPairIterator.next().left().getAttributes().getString("text-organizationRefId"); - parentIdsTreeMap = parentIdsTreeMap.set(parentId, parentId); + Iterator parentIdIterator = parentOrgIdPairIterator.next().left().getAttributes() + .getString("text-organizationRefId"); + for (; parentIdIterator.hasNext();) { + String parentId = parentIdIterator.next(); + parentIdsTreeMap = parentIdsTreeMap.set(parentId, parentId); + } } } @@ -982,16 +1005,16 @@ } Iterator> PathNameIterator = traverser.find((TreeNode node) -> { - String element = node.getAttributes().getString("element"); - if (element == null) + Iterator element = node.getAttributes().getString("element"); + if (!element.hasNext()) return false; - if (!element.equals("path")) + if (!element.next().equals("path")) return false; - String pathString = node.getAttributes().getString("text-path"); - if (pathString == null) - return false; - if (pathString.equals(StrPath)) - return true; + Iterator pathStringIterator = node.getAttributes().getString("text-path"); + for (; pathStringIterator.hasNext();) { + if (pathStringIterator.next().equals(StrPath)) + return true; + } return false; }, "text-path", StrPath); @@ -1003,8 +1026,10 @@ NodePath pathNameIdPath = pathNamePath.last().right(); TreeNode pathNameIdNode = getTarget(root, pathNameIdPath); - String pathNameId = pathNameIdNode.getAttributes().getString(elementName + "-id"); - return pathNameId; + Iterator pathNameIdIterator = pathNameIdNode.getAttributes().getString(elementName + "-id"); + if (pathNameIdIterator.hasNext()) + return pathNameIdIterator.next(); + return ""; } public Iterator roleDescriptionElementIds(String id, LinkedList filterIds) { @@ -1050,16 +1075,16 @@ InterfaceTraverser traverser = roleTree.getTraverser(); Iterator> roleIdPairIterator = traverser.find((TreeNode node) -> { - String element = node.getAttributes().getString("element"); - if (element == null) + Iterator element = node.getAttributes().getString("element"); + if (!element.hasNext()) return false; - if (!element.equals("Role")) + if (!element.next().equals("Role")) return false; - String id = node.getAttributes().getString("Role-id"); - if (id == null) - return false; - if (id.equals(roleId)) - return true; + Iterator idIterator = node.getAttributes().getString("Role-id"); + for (; idIterator.hasNext();) { + if (idIterator.next().equals(roleId)) + return true; + } return false; }, "Role-id", roleId); @@ -1069,13 +1094,13 @@ Pair roleIdPair = roleIdPairIterator.next(); Iterator> rdeIdPairIterator = traverser.findInSubTreeAllValue((TreeNode node) -> { - String element = node.getAttributes().getString("element"); - if (element == null) + Iterator element = node.getAttributes().getString("element"); + if (!element.hasNext()) return false; - if (!element.equals("roleDescriptionElementRefIds")) + if (!element.next().equals("roleDescriptionElementRefIds")) return false; - String rde = node.getAttributes().getString("text-roleDescriptionElementRefIds"); - if (rde != null) + Iterator rdeIterator = node.getAttributes().getString("text-roleDescriptionElementRefIds"); + if (rdeIterator.hasNext()) return true; return false; }, roleIdPair, "text-roleDescriptionElementRefIds"); @@ -1083,23 +1108,27 @@ if (!rdeIdPairIterator.hasNext()) return new NullIterator(); + Iterator rdeIdIterator = rdeIdPairIterator.next().left().getAttributes().getString("text-roleDescriptionElementRefIds"); + return new Iterator() { + String rdeId = ""; @Override public boolean hasNext() { - if (rdeIdPairIterator.hasNext()) + if (rdeIdIterator.hasNext()) { + rdeId = rdeIdIterator.next(); return true; + } return false; } @Override public String next() { - return rdeIdPairIterator.next().left().getAttributes().getString("text-roleDescriptionElementRefIds"); + return rdeId; } }; } - public TreeNode getTarget(TreeNode node, NodePath path) { TreeNode target; @@ -1121,5 +1150,4 @@ return target; } - } diff -r 59a7d2cffc86 -r 037731e99d6e src/main/java/jp/ac/u_ryukyu/cr/ie/tatsuki/bbs/JungleBulletinBoard.java --- a/src/main/java/jp/ac/u_ryukyu/cr/ie/tatsuki/bbs/JungleBulletinBoard.java Thu Nov 13 23:34:41 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/cr/ie/tatsuki/bbs/JungleBulletinBoard.java Mon Nov 17 18:47:10 2014 +0900 @@ -2,11 +2,13 @@ import java.io.FileInputStream; import java.nio.ByteBuffer; +import java.util.Iterator; import java.util.concurrent.atomic.AtomicInteger; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; +import fj.data.List; import ac.jp.u_ryukyu.cr.ie.tatsuki.xmlReader.ReadXmlHandler; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.DefaultJungle; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.Jungle; @@ -32,564 +34,552 @@ public class JungleBulletinBoard implements XmlBulletinBoard { - private final Jungle jungle; - + private final Jungle jungle; - public JungleBulletinBoard() { - jungle = new DefaultJungle(null, "hoge", new DefaultTreeEditor(new DefaultTraverser())); - jungle.createNewTree("boards"); - } + public JungleBulletinBoard() { + jungle = new DefaultJungle(null, "hoge", new DefaultTreeEditor(new DefaultTraverser())); + jungle.createNewTree("boards"); + } - + public IterableConverter getBoards() { + JungleTree tree = jungle.getTreeByName("boards"); + TreeNode node = tree.getRootNode(); + Children chs = node.getChildren(); - public Iterable getBoards() { - JungleTree tree = jungle.getTreeByName("boards"); - TreeNode node = tree.getRootNode(); - Children chs = node.getChildren(); + IterableConverter.Converter converter = new IterableConverter.Converter() { - IterableConverter.Converter converter = new IterableConverter.Converter() { - public String conv(TreeNode _b) { - ByteBuffer e = _b.getAttributes().get("name"); - System.out.println(new String(e.array())); - return new String(e.array()); - } - }; + public String conv(TreeNode _b) { + List byteBufferList = _b.getAttributes().get("name"); + if (byteBufferList.isNotEmpty()) + return byteBufferList.head().toString(); + return ""; + } + }; - return new IterableConverter(chs, converter); - } - + return new IterableConverter(chs, converter); + } - public void createBoards(final String _name) { - if (null == jungle.createNewTree(_name)) { - throw new IllegalStateException(); - } + public void createBoards(final String _name) { + if (null == jungle.createNewTree(_name)) { + throw new IllegalStateException(); + } - JungleTree tree = jungle.getTreeByName("boards"); - JungleTreeEditor editor = tree.getTreeEditor(); - DefaultNodePath root = new DefaultNodePath(); - Either either = editor.addNewChildAt(root, 0); - if (either.isA()) { - throw new IllegalStateException(); - } - editor = either.b(); + JungleTree tree = jungle.getTreeByName("boards"); + JungleTreeEditor editor = tree.getTreeEditor(); + DefaultNodePath root = new DefaultNodePath(); + Either either = editor.addNewChildAt(root, 0); + if (either.isA()) { + throw new IllegalStateException(); + } + editor = either.b(); - either = editor.putAttribute(root.add(0), "name",ByteBuffer.wrap(_name.getBytes())); - if (either.isA()) { - throw new IllegalStateException(); - } - editor = either.b(); - either = either.b().success(); - if (either.isA()) { - throw new IllegalStateException(); - } + either = editor.putAttribute(root.add(0), "name", ByteBuffer.wrap(_name.getBytes())); + if (either.isA()) { + throw new IllegalStateException(); + } + editor = either.b(); + either = either.b().success(); + if (either.isA()) { + throw new IllegalStateException(); + } - } + } - public void createFolder(final String _board, final String _author, final String _message, final String _editKey, String _nodeNum) { - JungleTree tree = jungle.getTreeByName(_board); - if (tree == null) { - throw new IllegalStateException(); - } + public void createFolder(final String _board, final String _author, final String _message, final String _editKey, + String _nodeNum) { + JungleTree tree = jungle.getTreeByName(_board); + if (tree == null) { + throw new IllegalStateException(); + } - DefaultNodePath path = new DefaultNodePath(); - try { - for (int count = 0; _nodeNum.substring(count, count + 1) != null; count++) { - if (!_nodeNum.substring(count, count + 1).equals("/")) - path = path.add(Integer.parseInt(_nodeNum.substring(count, - count + 1))); - } - } catch (Exception _e) { - } - Either either; - final long timestamp = System.currentTimeMillis(); - final ByteBuffer tBuffer = ByteBuffer.allocate(16); - tBuffer.putLong(timestamp); + DefaultNodePath path = new DefaultNodePath(); + try { + for (int count = 0; _nodeNum.substring(count, count + 1) != null; count++) { + if (!_nodeNum.substring(count, count + 1).equals("/")) + path = path.add(Integer.parseInt(_nodeNum.substring(count, count + 1))); + } + } catch (Exception _e) { + } + Either either; + final long timestamp = System.currentTimeMillis(); + final ByteBuffer tBuffer = ByteBuffer.allocate(16); + tBuffer.putLong(timestamp); - do { - TreeNode node = tree.getRootNode(); - DefaultTraverser traverser = new DefaultTraverser(); - // TraversableNodeWrapper traversable = new - // TraversableNodeWrapper(node); - DefaultEvaluator evaluator = new DefaultEvaluator(path); - Either ret = traverser.traverse(node, - evaluator); - if (ret.isA()) { - Assert.fail(); - } + do { + TreeNode node = tree.getRootNode(); + DefaultTraverser traverser = new DefaultTraverser(); + // TraversableNodeWrapper traversable = new + // TraversableNodeWrapper(node); + DefaultEvaluator evaluator = new DefaultEvaluator(path); + Either ret = traverser.traverse(node, evaluator); + if (ret.isA()) { + Assert.fail(); + } - Traversal traversal = ret.b(); - TreeNode target = traversal.destination(); - int size = target.getChildren().size(); - JungleTreeEditor editor = tree.getTreeEditor(); - either = editor.addNewChildAt(path, size); - if (either.isA()) { - throw new IllegalStateException(); - } - editor = either.b(); + Traversal traversal = ret.b(); + TreeNode target = traversal.destination(); + int size = target.getChildren().size(); + JungleTreeEditor editor = tree.getTreeEditor(); + either = editor.addNewChildAt(path, size); + if (either.isA()) { + throw new IllegalStateException(); + } + editor = either.b(); - NodeEditor e = new NodeEditor() { + NodeEditor e = new NodeEditor() { - public Either edit(TreeNode node) { - LoggingNode logNode = wrap(node , new DefaultOperationLog()); - logNode = logNode.getAttributes().put("mes", ByteBuffer.wrap(_message.getBytes())).b(); - logNode = logNode.getAttributes().put("timestamp", tBuffer).b(); - return DefaultEither.newB(logNode); - } + public Either edit(TreeNode node) { + LoggingNode logNode = wrap(node, new DefaultOperationLog()); + logNode = logNode.getAttributes().put("mes", ByteBuffer.wrap(_message.getBytes())).b(); + logNode = logNode.getAttributes().put("timestamp", tBuffer).b(); + return DefaultEither.newB(logNode); + } - @Override - public LoggingNode wrap(TreeNode node, OperationLog op) { - return new LoggingNode(node, op); - } - }; - path = path.add(size); - either = editor.edit(path, e); - if (either.isA()) { - throw new IllegalStateException(); - } - editor = either.b(); - either = editor.success(); - } while (either.isA()); + @Override + public LoggingNode wrap(TreeNode node, OperationLog op) { + return new LoggingNode(node, op); + } + }; + path = path.add(size); + either = editor.edit(path, e); + if (either.isA()) { + throw new IllegalStateException(); + } + editor = either.b(); + either = editor.success(); + } while (either.isA()); - } + } - public void createBoardMessage(final String _board, final String _author, final String _message, final String _editKey) { - JungleTree tree = jungle.getTreeByName(_board); - if (tree == null) { - throw new IllegalStateException(); - } + public void createBoardMessage(final String _board, final String _author, final String _message, final String _editKey) { + JungleTree tree = jungle.getTreeByName(_board); + if (tree == null) { + throw new IllegalStateException(); + } - Either either; - final long timestamp = System.currentTimeMillis(); - final ByteBuffer tBuffer = ByteBuffer.allocate(16); - tBuffer.putLong(timestamp); - do { + Either either; + final long timestamp = System.currentTimeMillis(); + final ByteBuffer tBuffer = ByteBuffer.allocate(16); + tBuffer.putLong(timestamp); + do { - TreeNode node = tree.getRootNode(); - int size = node.getChildren().size(); - DefaultNodePath path = new DefaultNodePath(); + TreeNode node = tree.getRootNode(); + int size = node.getChildren().size(); + DefaultNodePath path = new DefaultNodePath(); - JungleTreeEditor editor = tree.getTreeEditor(); - either = editor.addNewChildAt(path, size); - if (either.isA()) { - throw new IllegalStateException(); - } - editor = either.b(); - - NodeEditor e = new NodeEditor() { - public Either edit(TreeNode node) { - LoggingNode logNode = wrap(node , new DefaultOperationLog()); - logNode = logNode.getAttributes().put("author", ByteBuffer.wrap(_author.getBytes())).b(); - logNode = logNode.getAttributes().put("mes", ByteBuffer.wrap(_message.getBytes())).b(); - logNode = logNode.getAttributes().put("key", ByteBuffer.wrap(_editKey.getBytes())).b(); - logNode = logNode.getAttributes().put("timestamp", tBuffer).b(); - return DefaultEither.newB(logNode); - } + JungleTreeEditor editor = tree.getTreeEditor(); + either = editor.addNewChildAt(path, size); + if (either.isA()) { + throw new IllegalStateException(); + } + editor = either.b(); - @Override - public LoggingNode wrap(TreeNode node, OperationLog op) { - return new LoggingNode(node, op); - } + NodeEditor e = new NodeEditor() { + public Either edit(TreeNode node) { + LoggingNode logNode = wrap(node, new DefaultOperationLog()); + logNode = logNode.getAttributes().put("author", ByteBuffer.wrap(_author.getBytes())).b(); + logNode = logNode.getAttributes().put("mes", ByteBuffer.wrap(_message.getBytes())).b(); + logNode = logNode.getAttributes().put("key", ByteBuffer.wrap(_editKey.getBytes())).b(); + logNode = logNode.getAttributes().put("timestamp", tBuffer).b(); + return DefaultEither.newB(logNode); + } - }; - path = path.add(size); - either = editor.edit(path, e); - if (either.isA()) { - throw new IllegalStateException(); - } - editor = either.b(); - either = editor.success(); - } while (either.isA()); + @Override + public LoggingNode wrap(TreeNode node, OperationLog op) { + return new LoggingNode(node, op); + } - } + }; + path = path.add(size); + either = editor.edit(path, e); + if (either.isA()) { + throw new IllegalStateException(); + } + editor = either.b(); + either = editor.success(); + } while (either.isA()); - public void editMessage(String _board, String _nodeNum,final String _author, final String _message, final String _editKey) { - final long timestamp = System.currentTimeMillis(); - final ByteBuffer tBuffer = ByteBuffer.allocate(16); - tBuffer.putLong(timestamp); - JungleTree tree = jungle.getTreeByName(_board); - Either either = null; + } + + public void editMessage(String _board, String _nodeNum, final String _author, final String _message, + final String _editKey) { + final long timestamp = System.currentTimeMillis(); + final ByteBuffer tBuffer = ByteBuffer.allocate(16); + tBuffer.putLong(timestamp); + JungleTree tree = jungle.getTreeByName(_board); + Either either = null; - do { - DefaultNodePath path = new DefaultNodePath(); - try { - for (int count = 0; _nodeNum.substring(count, count + 1) != null; count++) { - if (!_nodeNum.substring(count, count + 1).equals("/")) - path = path.add(Integer.parseInt(_nodeNum.substring(count, count + 1))); - } - } catch (Exception _e) { - } - JungleTreeEditor editor = tree.getTreeEditor(); - NodeEditor e = new NodeEditor() { - public Either edit(TreeNode node) { - LoggingNode logNode = wrap(node , new DefaultOperationLog()); - System.out.println(new String(node.getAttributes().get("mes").array())); - logNode = logNode.getAttributes().put("author", ByteBuffer.wrap(_author.getBytes())).b(); - logNode = logNode.getAttributes().put("mes", ByteBuffer.wrap(_message.getBytes())).b(); - logNode = logNode.getAttributes().put("key", ByteBuffer.wrap(_editKey.getBytes())).b(); - logNode = logNode.getAttributes().put("timestamp", tBuffer).b(); - System.out.println(new String(node.getAttributes().get("mes").array())); - return DefaultEither.newB(logNode); - } + do { + DefaultNodePath path = new DefaultNodePath(); + try { + for (int count = 0; _nodeNum.substring(count, count + 1) != null; count++) { + if (!_nodeNum.substring(count, count + 1).equals("/")) + path = path.add(Integer.parseInt(_nodeNum.substring(count, count + 1))); + } + } catch (Exception _e) { + } + JungleTreeEditor editor = tree.getTreeEditor(); + NodeEditor e = new NodeEditor() { + public Either edit(TreeNode node) { + LoggingNode logNode = wrap(node, new DefaultOperationLog()); + logNode = logNode.getAttributes().put("author", ByteBuffer.wrap(_author.getBytes())).b(); + logNode = logNode.getAttributes().put("mes", ByteBuffer.wrap(_message.getBytes())).b(); + logNode = logNode.getAttributes().put("key", ByteBuffer.wrap(_editKey.getBytes())).b(); + logNode = logNode.getAttributes().put("timestamp", tBuffer).b(); + return DefaultEither.newB(logNode); + } - @Override - public LoggingNode wrap(TreeNode node, OperationLog op) { - return new LoggingNode(node, op); - } + @Override + public LoggingNode wrap(TreeNode node, OperationLog op) { + return new LoggingNode(node, op); + } - }; - either = editor.edit(path, e); - if (either.isA()) { - throw new IllegalStateException(); - } - editor = either.b(); - either = editor.success(); - } while (either.isA()); - } + }; + either = editor.edit(path, e); + if (either.isA()) { + throw new IllegalStateException(); + } + editor = either.b(); + either = editor.success(); + } while (either.isA()); + } - public void createAttribute(String _board, String _uuid, final String _author, final String _message, final String _editKey) { - final long timestamp = System.currentTimeMillis(); - final ByteBuffer tBuffer = ByteBuffer.allocate(16); - tBuffer.putLong(timestamp); - JungleTree tree = jungle.getTreeByName(_board); - Either either = null; - DefaultNodePath path = new DefaultNodePath(); - do { - try { - for (int count = 0; _uuid.substring(count, count + 1) != null; count++) { - if (!_uuid.substring(count, count + 1).equals("/")) - path = path.add(Integer.parseInt(_uuid.substring(count, - count + 1))); - } - } catch (Exception _e) { - } + public void createAttribute(String _board, String _uuid, final String _author, final String _message, + final String _editKey) { + final long timestamp = System.currentTimeMillis(); + final ByteBuffer tBuffer = ByteBuffer.allocate(16); + tBuffer.putLong(timestamp); + JungleTree tree = jungle.getTreeByName(_board); + Either either = null; + DefaultNodePath path = new DefaultNodePath(); + do { + try { + for (int count = 0; _uuid.substring(count, count + 1) != null; count++) { + if (!_uuid.substring(count, count + 1).equals("/")) + path = path.add(Integer.parseInt(_uuid.substring(count, count + 1))); + } + } catch (Exception _e) { + } - JungleTreeEditor editor = tree.getTreeEditor(); - NodeEditor e = new NodeEditor() { - String str; + JungleTreeEditor editor = tree.getTreeEditor(); + NodeEditor e = new NodeEditor() { + String str; - public Either edit(TreeNode node) { - LoggingNode logNode = wrap(node , new DefaultOperationLog()); - str = "0"; - int count = 0; - for (; logNode.getAttributes().get("mes" + String.valueOf(count)) != null; count++) { - } - str = String.valueOf(count); - logNode = logNode.getAttributes().put("mes" + str,ByteBuffer.wrap(_message.getBytes())).b(); - logNode = logNode.getAttributes().put("timestamp" + str, tBuffer).b(); - return DefaultEither.newB(logNode); - } + public Either edit(TreeNode node) { + LoggingNode logNode = wrap(node, new DefaultOperationLog()); + str = "0"; + int count = 0; + for (; logNode.getAttributes().get("mes" + String.valueOf(count)) != null; count++) { + } + str = String.valueOf(count); + logNode = logNode.getAttributes().put("mes" + str, ByteBuffer.wrap(_message.getBytes())).b(); + logNode = logNode.getAttributes().put("timestamp" + str, tBuffer).b(); + return DefaultEither.newB(logNode); + } - @Override - public LoggingNode wrap(TreeNode node, OperationLog op) { - return new LoggingNode(node, op); - } - }; - either = editor.edit(path, e); - if (either.isA()) { - throw new IllegalStateException(); - } - editor = either.b(); - either = editor.success(); - } while (either.isA()); - } + @Override + public LoggingNode wrap(TreeNode node, OperationLog op) { + return new LoggingNode(node, op); + } + }; + either = editor.edit(path, e); + if (either.isA()) { + throw new IllegalStateException(); + } + editor = either.b(); + either = editor.success(); + } while (either.isA()); + } - public void editAttribute(String boardName, String _path, final String id, final String _message) { - final long timestamp = System.currentTimeMillis(); - final ByteBuffer tBuffer = ByteBuffer.allocate(16); - tBuffer.putLong(timestamp); - JungleTree tree = jungle.getTreeByName(boardName); - Either either = null; - DefaultNodePath path = new DefaultNodePath(); - do { - try { - for (int count = 0; _path.substring(count, count + 1) != null; count++) { - if (!_path.substring(count, count + 1).equals("/")) - path = path.add(Integer.parseInt(_path.substring(count, - count + 1))); - } - } catch (Exception _e) { - } + public void editAttribute(String boardName, String _path, final String id, final String _message) { + final long timestamp = System.currentTimeMillis(); + final ByteBuffer tBuffer = ByteBuffer.allocate(16); + tBuffer.putLong(timestamp); + JungleTree tree = jungle.getTreeByName(boardName); + Either either = null; + DefaultNodePath path = new DefaultNodePath(); + do { + try { + for (int count = 0; _path.substring(count, count + 1) != null; count++) { + if (!_path.substring(count, count + 1).equals("/")) + path = path.add(Integer.parseInt(_path.substring(count, count + 1))); + } + } catch (Exception _e) { + } - JungleTreeEditor editor = tree.getTreeEditor(); - NodeEditor e = new NodeEditor() { - public Either edit(TreeNode node) { - LoggingNode logNode = wrap(node , new DefaultOperationLog()); - // EnableNodeWrapper node = _e.getWrap(); - logNode = logNode.getAttributes().put("mes" + id,ByteBuffer.wrap(_message.getBytes())).b(); - logNode = logNode.getAttributes().put("timestamp" + id, tBuffer).b(); - return DefaultEither.newB(logNode); - } + JungleTreeEditor editor = tree.getTreeEditor(); + NodeEditor e = new NodeEditor() { + public Either edit(TreeNode node) { + LoggingNode logNode = wrap(node, new DefaultOperationLog()); + // EnableNodeWrapper node = _e.getWrap(); + logNode = logNode.getAttributes().put("mes" + id, ByteBuffer.wrap(_message.getBytes())).b(); + logNode = logNode.getAttributes().put("timestamp" + id, tBuffer).b(); + return DefaultEither.newB(logNode); + } - @Override - public LoggingNode wrap(TreeNode node, OperationLog op) { - return new LoggingNode(node, op); - } + @Override + public LoggingNode wrap(TreeNode node, OperationLog op) { + return new LoggingNode(node, op); + } - }; - either = editor.edit(path, e); - if (either.isA()) { - throw new IllegalStateException(); - } - editor = either.b(); - either = editor.success(); - } while (either.isA()); - } + }; + either = editor.edit(path, e); + if (either.isA()) { + throw new IllegalStateException(); + } + editor = either.b(); + either = editor.success(); + } while (either.isA()); + } - public void deleteNode(String _board, String _path, String _id) { - int id = Integer.parseInt(_id); - final long timestamp = System.currentTimeMillis(); - final ByteBuffer tBuffer = ByteBuffer.allocate(16); - tBuffer.putLong(timestamp); - JungleTree tree = jungle.getTreeByName(_board); - Either either = null; - DefaultNodePath path = new DefaultNodePath(); - do { - try { - for (int count = 0; _path.substring(count, count + 1) != null; count++) { - if (!_path.substring(count, count + 1).equals("/")) - path = path.add(Integer.parseInt(_path.substring(count,count + 1))); - } - } catch (Exception _e) { - } + public void deleteNode(String _board, String _path, String _id) { + int id = Integer.parseInt(_id); + final long timestamp = System.currentTimeMillis(); + final ByteBuffer tBuffer = ByteBuffer.allocate(16); + tBuffer.putLong(timestamp); + JungleTree tree = jungle.getTreeByName(_board); + Either either = null; + DefaultNodePath path = new DefaultNodePath(); + do { + try { + for (int count = 0; _path.substring(count, count + 1) != null; count++) { + if (!_path.substring(count, count + 1).equals("/")) + path = path.add(Integer.parseInt(_path.substring(count, count + 1))); + } + } catch (Exception _e) { + } - JungleTreeEditor editor = tree.getTreeEditor(); + JungleTreeEditor editor = tree.getTreeEditor(); - either = editor.deleteChildAt(path, id); - if (either.isA()) { - throw new IllegalStateException(); - } - editor = either.b(); - either = editor.success(); - } while (either.isA()); + either = editor.deleteChildAt(path, id); + if (either.isA()) { + throw new IllegalStateException(); + } + editor = either.b(); + either = editor.success(); + } while (either.isA()); - } + } - public void deleteAttribute(String _board, String _path, final String id) { - final long timestamp = System.currentTimeMillis(); - final ByteBuffer tBuffer = ByteBuffer.allocate(16); - tBuffer.putLong(timestamp); - JungleTree tree = jungle.getTreeByName(_board); - Either either = null; - DefaultNodePath path = new DefaultNodePath(); - do { - try { - for (int count = 0; _path.substring(count, count + 1) != null; count++) { - if (!_path.substring(count, count + 1).equals("/")) - path = path.add(Integer.parseInt(_path.substring(count, - count + 1))); - } - } catch (Exception _e) { - System.out.println("屑"); - } + public void deleteAttribute(String _board, String _path, final String id) { + final long timestamp = System.currentTimeMillis(); + final ByteBuffer tBuffer = ByteBuffer.allocate(16); + tBuffer.putLong(timestamp); + JungleTree tree = jungle.getTreeByName(_board); + Either either = null; + DefaultNodePath path = new DefaultNodePath(); + do { + try { + for (int count = 0; _path.substring(count, count + 1) != null; count++) { + if (!_path.substring(count, count + 1).equals("/")) + path = path.add(Integer.parseInt(_path.substring(count, count + 1))); + } + } catch (Exception _e) { + System.out.println("屑"); + } - JungleTreeEditor editor = tree.getTreeEditor(); - NodeEditor e = new NodeEditor() { - public Either edit(TreeNode node) { - LoggingNode logNode = wrap(node , new DefaultOperationLog()); - logNode = logNode.getAttributes().delete("mes" + id).b(); - logNode = logNode.getAttributes().delete("timestamp" + id).b(); - int count = Integer.parseInt(id); - for (; logNode.getAttributes().get("mes" + String.valueOf(count + 1)) != null;) { - logNode = logNode.getAttributes().put("mes" + count,node.getAttributes().get("mes"+ String.valueOf(count + 1))).b(); - logNode = logNode.getAttributes().put("timestamp" + count, tBuffer).b(); - count++; - } - if (count != Integer.parseInt(id)) { - logNode = logNode.getAttributes().delete("timestamp" + count).b(); - logNode = logNode.getAttributes().delete("mes" + count).b(); - } + JungleTreeEditor editor = tree.getTreeEditor(); + NodeEditor e = new NodeEditor() { + public Either edit(TreeNode node) { + LoggingNode logNode = wrap(node, new DefaultOperationLog()); + logNode = logNode.getAttributes().delete("mes" + id).b(); + logNode = logNode.getAttributes().delete("timestamp" + id).b(); + int count = Integer.parseInt(id); + for (; logNode.getAttributes().get("mes" + String.valueOf(count + 1)) != null;) { + logNode = logNode.getAttributes() + .put("mes" + count, node.getAttributes().get("mes" + String.valueOf(count + 1)).head()).b(); + logNode = logNode.getAttributes().put("timestamp" + count, tBuffer).b(); + count++; + } + if (count != Integer.parseInt(id)) { + logNode = logNode.getAttributes().delete("timestamp" + count).b(); + logNode = logNode.getAttributes().delete("mes" + count).b(); + } - return DefaultEither.newB(logNode); - } + return DefaultEither.newB(logNode); + } - @Override - public LoggingNode wrap(TreeNode node, OperationLog op) { - return new LoggingNode(node, op); - } - }; - either = editor.edit(path, e); - if (either.isA()) { - throw new IllegalStateException(); - } - editor = either.b(); - either = editor.success(); - } while (either.isA()); - } + @Override + public LoggingNode wrap(TreeNode node, OperationLog op) { + return new LoggingNode(node, op); + } + }; + either = editor.edit(path, e); + if (either.isA()) { + throw new IllegalStateException(); + } + editor = either.b(); + either = editor.success(); + } while (either.isA()); + } - public void editMatrixMessage(String _board, String _uuid, - final String _author, final String _message, final String _editKey) { - final long timestamp = System.currentTimeMillis(); - final ByteBuffer tBuffer = ByteBuffer.allocate(16); - tBuffer.putLong(timestamp); - JungleTree tree = jungle.getTreeByName(_board); - Either either = null; - do { - DefaultNodePath path = new DefaultNodePath(); - path = path.add(Integer.parseInt(_uuid)); + public void editMatrixMessage(String _board, String _uuid, final String _author, final String _message, + final String _editKey) { + final long timestamp = System.currentTimeMillis(); + final ByteBuffer tBuffer = ByteBuffer.allocate(16); + tBuffer.putLong(timestamp); + JungleTree tree = jungle.getTreeByName(_board); + Either either = null; + do { + DefaultNodePath path = new DefaultNodePath(); + path = path.add(Integer.parseInt(_uuid)); - JungleTreeEditor editor = tree.getTreeEditor(); - NodeEditor e = new NodeEditor() { - public Either edit(TreeNode node) { - LoggingNode logNode = wrap(node , new DefaultOperationLog()); - logNode = logNode.getAttributes().put("author", ByteBuffer.wrap(_author.getBytes())).b(); - logNode = logNode.getAttributes().put("mes", ByteBuffer.wrap(_message.getBytes())).b(); - logNode = logNode.getAttributes().put("key", ByteBuffer.wrap(_editKey.getBytes())).b(); - logNode = logNode.getAttributes().put("timestamp", tBuffer).b(); - return DefaultEither.newB(logNode); - } + JungleTreeEditor editor = tree.getTreeEditor(); + NodeEditor e = new NodeEditor() { + public Either edit(TreeNode node) { + LoggingNode logNode = wrap(node, new DefaultOperationLog()); + logNode = logNode.getAttributes().put("author", ByteBuffer.wrap(_author.getBytes())).b(); + logNode = logNode.getAttributes().put("mes", ByteBuffer.wrap(_message.getBytes())).b(); + logNode = logNode.getAttributes().put("key", ByteBuffer.wrap(_editKey.getBytes())).b(); + logNode = logNode.getAttributes().put("timestamp", tBuffer).b(); + return DefaultEither.newB(logNode); + } - @Override - public LoggingNode wrap(TreeNode node, OperationLog op) { - return new LoggingNode(node, op); - } - + @Override + public LoggingNode wrap(TreeNode node, OperationLog op) { + return new LoggingNode(node, op); + } - }; - either = editor.edit(path, e); - if (either.isA()) { - throw new IllegalStateException(); - } - editor = either.b(); - either = editor.success(); - } while (either.isA()); - } + }; + either = editor.edit(path, e); + if (either.isA()) { + throw new IllegalStateException(); + } + editor = either.b(); + either = editor.success(); + } while (either.isA()); + } - public Iterable getMessages(String _boardName) { - JungleTree tree = jungle.getTreeByName(_boardName); - TreeNode node = tree.getRootNode(); - Children chs = node.getChildren(); - final AtomicInteger counter = new AtomicInteger(0); - IterableConverter.Converter converter = new IterableConverter.Converter() { - public BoardMessage conv(TreeNode _b) { - String uuid = Integer.toString(counter.get()); - String author = new String(_b.getAttributes().get("author").array()); - String message = new String(_b.getAttributes().get("mes").array()); - counter.incrementAndGet(); - return new BoardMessageImpl(author, message, uuid); - } - }; - return new IterableConverter(chs, converter); - } + public Iterable getMessages(String _boardName) { + JungleTree tree = jungle.getTreeByName(_boardName); + TreeNode node = tree.getRootNode(); + Children chs = node.getChildren(); + final AtomicInteger counter = new AtomicInteger(0); + IterableConverter.Converter converter = new IterableConverter.Converter() { + public BoardMessage conv(TreeNode _b) { + String uuid = Integer.toString(counter.get()); + String author = new String(_b.getAttributes().get("author").head().array()); + String message = new String(_b.getAttributes().get("mes").head().array()); + counter.incrementAndGet(); + return new BoardMessageImpl(author, message, uuid); + } + }; + return new IterableConverter(chs, converter); + } - public Iterable getFolder(String _boardName, String _nodeNum) { + public Iterable getFolder(String _boardName, String _nodeNum) { - DefaultNodePath path = new DefaultNodePath(); - try { - for (int count = 0; _nodeNum.substring(count, count + 1) != null; count++) { - if (!_nodeNum.substring(count, count + 1).equals("/")) - path = path.add(Integer.parseInt(_nodeNum.substring(count,count + 1))); - } - } catch (Exception _e) { - } - JungleTree tree = jungle.getTreeByName(_boardName); - TreeNode node = tree.getRootNode(); + DefaultNodePath path = new DefaultNodePath(); + try { + for (int count = 0; _nodeNum.substring(count, count + 1) != null; count++) { + if (!_nodeNum.substring(count, count + 1).equals("/")) + path = path.add(Integer.parseInt(_nodeNum.substring(count, count + 1))); + } + } catch (Exception _e) { + } + JungleTree tree = jungle.getTreeByName(_boardName); + TreeNode node = tree.getRootNode(); - DefaultTraverser traverser = new DefaultTraverser(); - DefaultEvaluator evaluator = new DefaultEvaluator(path); - Either ret = traverser.traverse(node,evaluator); - if (ret.isA()) { - Assert.fail(); - } + DefaultTraverser traverser = new DefaultTraverser(); + DefaultEvaluator evaluator = new DefaultEvaluator(path); + Either ret = traverser.traverse(node, evaluator); + if (ret.isA()) { + Assert.fail(); + } - Traversal traversal = ret.b(); - TreeNode target = traversal.destination(); - Children chs = target.getChildren(); + Traversal traversal = ret.b(); + TreeNode target = traversal.destination(); + Children chs = target.getChildren(); - final AtomicInteger counter = new AtomicInteger(0); - IterableConverter.Converter converter = new IterableConverter.Converter() { - public BoardMessage conv(TreeNode _b) { - String uuid = Integer.toString(counter.get()); - String message = new String(_b.getAttributes().get("element").array()); - counter.incrementAndGet(); - return new BoardMessageImpl(null, message, uuid); - } - }; - return new IterableConverter(chs, converter); - } + final AtomicInteger counter = new AtomicInteger(0); + IterableConverter.Converter converter = new IterableConverter.Converter() { + public BoardMessage conv(TreeNode _b) { + String uuid = Integer.toString(counter.get()); + String message = new String(_b.getAttributes().get("element").head().array()); + counter.incrementAndGet(); + return new BoardMessageImpl(null, message, uuid); + } + }; + return new IterableConverter(chs, converter); + } - public GetAttributeImp getAttribute(String _boardName, String _nodeNum) { + public GetAttributeImp getAttribute(String _boardName, String _nodeNum) { - DefaultNodePath path = new DefaultNodePath(); - try { - for (int count = 0; _nodeNum.substring(count, count + 1) != null; count++) { - if (!_nodeNum.substring(count, count + 1).equals("/")) - path = path.add(Integer.parseInt(_nodeNum.substring(count, - count + 1))); - } - } catch (Exception _e) { - } - JungleTree tree = jungle.getTreeByName(_boardName); - TreeNode node = tree.getRootNode(); + DefaultNodePath path = new DefaultNodePath(); + try { + for (int count = 0; _nodeNum.substring(count, count + 1) != null; count++) { + if (!_nodeNum.substring(count, count + 1).equals("/")) + path = path.add(Integer.parseInt(_nodeNum.substring(count, count + 1))); + } + } catch (Exception _e) { + } + JungleTree tree = jungle.getTreeByName(_boardName); + TreeNode node = tree.getRootNode(); - DefaultTraverser traverser = new DefaultTraverser(); - DefaultEvaluator evaluator = new DefaultEvaluator(path); - Either ret = traverser.traverse(node,evaluator); - if (ret.isA()) { - Assert.fail(); - } + DefaultTraverser traverser = new DefaultTraverser(); + DefaultEvaluator evaluator = new DefaultEvaluator(path); + Either ret = traverser.traverse(node, evaluator); + if (ret.isA()) { + Assert.fail(); + } - Traversal traversal = ret.b(); - TreeNode target = traversal.destination(); - return new GetAttributeImp(target); - } + Traversal traversal = ret.b(); + TreeNode target = traversal.destination(); + return new GetAttributeImp(target); + } - + private static class BoardMessageImpl implements BoardMessage { + private final String author; + private final String message; + private final String uuid; - private static class BoardMessageImpl implements BoardMessage { - private final String author; - private final String message; - private final String uuid; + public BoardMessageImpl(String _author, String _message, String _uuid) { + author = _author; + message = _message; + uuid = _uuid; + } - public BoardMessageImpl(String _author, String _message, String _uuid) { - author = _author; - message = _message; - uuid = _uuid; - } - - public String getAuthor() { - return author; - } + public String getAuthor() { + return author; + } - public String getMessage() { - return message; - } + public String getMessage() { + return message; + } - public String getUUID() { - return uuid; - } + public String getUUID() { + return uuid; + } + + } - } - - public void readXml(String xmlPath){ - try { - SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); - SAXParser saxParser = saxParserFactory.newSAXParser(); - createBoards(xmlPath); - JungleTree tree = jungle.getTreeByName(xmlPath); - ReadXmlHandler readXmlHandler = new ReadXmlHandler(tree); - saxParser.parse(new FileInputStream("xml/" + xmlPath), readXmlHandler); - } catch (Exception e) { - e.printStackTrace(); - } - } + public void readXml(String xmlPath) { + try { + SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); + SAXParser saxParser = saxParserFactory.newSAXParser(); + createBoards(xmlPath); + JungleTree tree = jungle.getTreeByName(xmlPath); + ReadXmlHandler readXmlHandler = new ReadXmlHandler(tree); + saxParser.parse(new FileInputStream("xml/" + xmlPath), readXmlHandler); + } catch (Exception e) { + e.printStackTrace(); + } + } - public String sanitize(String str) { - if (str == null) { - return str; - } - str = str.replaceAll("&", "&"); - str = str.replaceAll("<", "<"); - str = str.replaceAll(">", ">"); - str = str.replaceAll("\"", """); - str = str.replaceAll("'", "'"); - return str; - } + public String sanitize(String str) { + if (str == null) { + return str; + } + str = str.replaceAll("&", "&"); + str = str.replaceAll("<", "<"); + str = str.replaceAll(">", ">"); + str = str.replaceAll("\"", """); + str = str.replaceAll("'", "'"); + return str; + } - - - @Override - public void createBoards(String _name, String _author, String _initMessage, - String _editKey) { - } + @Override + public void createBoards(String _name, String _author, String _initMessage, String _editKey) { + } } diff -r 59a7d2cffc86 -r 037731e99d6e src/main/java/jp/ac/u_ryukyu/cr/ie/tatsuki/bbs/ShowBoardsServletMatrix.java --- a/src/main/java/jp/ac/u_ryukyu/cr/ie/tatsuki/bbs/ShowBoardsServletMatrix.java Thu Nov 13 23:34:41 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/cr/ie/tatsuki/bbs/ShowBoardsServletMatrix.java Mon Nov 17 18:47:10 2014 +0900 @@ -1,6 +1,7 @@ package jp.ac.u_ryukyu.cr.ie.tatsuki.bbs; import java.io.PrintWriter; +import java.util.Iterator; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; diff -r 59a7d2cffc86 -r 037731e99d6e src/main/java/jp/ac/u_ryukyu/cr/ie/tatsuki/bbs/ShowMatrix.java --- a/src/main/java/jp/ac/u_ryukyu/cr/ie/tatsuki/bbs/ShowMatrix.java Thu Nov 13 23:34:41 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/cr/ie/tatsuki/bbs/ShowMatrix.java Mon Nov 17 18:47:10 2014 +0900 @@ -1,6 +1,7 @@ package jp.ac.u_ryukyu.cr.ie.tatsuki.bbs; import java.io.PrintWriter; +import java.util.Iterator; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; @@ -89,7 +90,10 @@ List keys = attribute.getKeys(); for (String key : keys) { - _pw.write(key + " : " + bbs.sanitize(attribute.getMessage(key)) + "
"); + Iterator attributeIterator = attribute.getMessage(key); + for (;attributeIterator.hasNext();) { + _pw.write(key + " : " + bbs.sanitize(attributeIterator.next()) + "
"); + } } diff -r 59a7d2cffc86 -r 037731e99d6e src/test/java/jp/ac/u_ryukyu/cr/ie/tatsuki/functionTest/ChildOrganizationIdsTest.java --- a/src/test/java/jp/ac/u_ryukyu/cr/ie/tatsuki/functionTest/ChildOrganizationIdsTest.java Thu Nov 13 23:34:41 2014 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/cr/ie/tatsuki/functionTest/ChildOrganizationIdsTest.java Mon Nov 17 18:47:10 2014 +0900 @@ -15,15 +15,16 @@ JuGrix jugrix = new JuGrix(false); LinkedList list = new LinkedList(); Iterator ids = jugrix.childOrganizationIds("o:2", list); + Assert.assertTrue(ids.hasNext()); Assert.assertEquals(ids.next(),"o:9"); Assert.assertTrue(ids.hasNext()); Assert.assertEquals(ids.next(),"o:3"); - JuGrix indexJugrix = new JuGrix(true); ids = indexJugrix.childOrganizationIds("o:2", list); + Assert.assertTrue(ids.hasNext()); Assert.assertEquals(ids.next(),"o:9"); Assert.assertTrue(ids.hasNext()); diff -r 59a7d2cffc86 -r 037731e99d6e src/test/java/jp/ac/u_ryukyu/cr/ie/tatsuki/functionTest/PersonIdsTest.java --- a/src/test/java/jp/ac/u_ryukyu/cr/ie/tatsuki/functionTest/PersonIdsTest.java Thu Nov 13 23:34:41 2014 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/cr/ie/tatsuki/functionTest/PersonIdsTest.java Mon Nov 17 18:47:10 2014 +0900 @@ -26,8 +26,9 @@ filterIds.add("rde:3"); ids = jugrix.personIds("o:2", filterIds); - ids.hasNext(); + Assert.assertTrue(ids.hasNext()); Assert.assertEquals(ids.next(), "p:45"); + Assert.assertTrue(ids.hasNext()); Assert.assertEquals(ids.next(), "p:1"); filterIds.add("rde:322"); diff -r 59a7d2cffc86 -r 037731e99d6e src/test/java/jp/ac/u_ryukyu/cr/ie/tatsuki/functionTest/RoleDescriptionElementIdsTest.java --- a/src/test/java/jp/ac/u_ryukyu/cr/ie/tatsuki/functionTest/RoleDescriptionElementIdsTest.java Thu Nov 13 23:34:41 2014 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/cr/ie/tatsuki/functionTest/RoleDescriptionElementIdsTest.java Mon Nov 17 18:47:10 2014 +0900 @@ -12,11 +12,12 @@ @Test public void testRoleDescriptionElementIds(){ - JuGrix jugrix = new JuGrix(true - ); + JuGrix jugrix = new JuGrix(true); LinkedList ids = new LinkedList(); //ids.add("o:34"); Iterator rdeIds = jugrix.roleDescriptionElementIds("o:2",ids); + + Assert.assertEquals(rdeIds.next(),"rde:3"); Assert.assertEquals(rdeIds.next(),"rde:2"); Assert.assertEquals(rdeIds.next(),"rde:10"); @@ -26,6 +27,7 @@ ids = new LinkedList(); //ids.add("o:34"); rdeIds = jugrix.roleDescriptionElementIds("o:2",ids); + Assert.assertEquals(rdeIds.next(),"rde:3"); Assert.assertEquals(rdeIds.next(),"rde:2"); Assert.assertEquals(rdeIds.next(),"rde:10"); diff -r 59a7d2cffc86 -r 037731e99d6e src/test/java/jp/ac/u_ryukyu/cr/ie/tatsuki/xmlReadTest/SaxTest.java --- a/src/test/java/jp/ac/u_ryukyu/cr/ie/tatsuki/xmlReadTest/SaxTest.java Thu Nov 13 23:34:41 2014 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/cr/ie/tatsuki/xmlReadTest/SaxTest.java Mon Nov 17 18:47:10 2014 +0900 @@ -6,6 +6,7 @@ import javax.xml.parsers.*; +import fj.data.List; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.DefaultJungle; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.Jungle; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree; @@ -18,80 +19,86 @@ import junit.framework.Assert; class SaxTest { - public static void main(String args[]) { - try { - SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); - SAXParser saxParser = saxParserFactory.newSAXParser(); - Jungle jungle = new DefaultJungle(null, "hoge",new DefaultTreeEditor(new DefaultTraverser())); - JungleTree tree = jungle.createNewTree("XMLTEST"); - TestHandler testHandler = new TestHandler(tree); - saxParser.parse(new FileInputStream("xml/sample.xml"), testHandler); - JungleTree newTree = testHandler.getTree(); - InterfaceTraverser ifTraverser = newTree.getTraverser(); + public static void main(String args[]) { + try { + SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); + SAXParser saxParser = saxParserFactory.newSAXParser(); + Jungle jungle = new DefaultJungle(null, "hoge", new DefaultTreeEditor(new DefaultTraverser())); + JungleTree tree = jungle.createNewTree("XMLTEST"); + TestHandler testHandler = new TestHandler(tree); + saxParser.parse(new FileInputStream("xml/sample.xml"), testHandler); + JungleTree newTree = testHandler.getTree(); + InterfaceTraverser ifTraverser = newTree.getTraverser(); - Iterator> searchNode = ifTraverser.find(( - TreeNode node) -> { - ByteBuffer attribute = node.getAttributes().get("element"); - if (attribute != null) { - byte[] byteAttribute = attribute.array(); - String str = new String(byteAttribute); - System.out.println("attribute = " + str); - return str.equals("Person"); - } - return false; - }, "element", "Person"); - Pair nodePair = searchNode.next(); - Assert.assertEquals(nodePair.left().getAttributes().getString("element"),"Person"); - Assert.assertEquals(nodePair.right().toString(), "<-1,0>"); + Iterator> searchNode = ifTraverser.find((TreeNode node) -> { + List attribute = node.getAttributes().get("element"); + if (attribute.isNotEmpty()) { + byte[] byteAttribute = attribute.head().array(); + String str = new String(byteAttribute); + System.out.println("attribute = " + str); + return str.equals("Person"); + } + return false; + }, "element", "Person"); + Pair nodePair = searchNode.next(); + Iterator element = nodePair.left().getAttributes().getString("element"); + Assert.assertTrue(element.hasNext()); + Assert.assertEquals(element.next(), "Person"); + Assert.assertEquals(nodePair.right().toString(), "<-1,0>"); - - searchNode = ifTraverser.find((TreeNode node) -> { - ByteBuffer attribute = node.getAttributes().get("element"); - if (attribute != null) { - byte[] byteAttribute = attribute.array(); - String str = new String(byteAttribute); - System.out.println("attribute = " + str); - return str.equals("name"); - } - return false; - }, "element", "name"); - - nodePair = searchNode.next(); - Assert.assertEquals(nodePair.left().getAttributes().getString("text"),"tatsuki"); - Assert.assertEquals(nodePair.right().toString(), "<-1,0,0>"); - - searchNode = ifTraverser.find((TreeNode node) -> { - ByteBuffer attribute = node.getAttributes().get("text"); - if (attribute != null) { - byte[] byteAttribute = attribute.array(); - String str = new String(byteAttribute); - System.out.println("attribute = " + str); - return str.equals("tatsuki"); - } - return false; - }, "text", "tatsuki"); - - nodePair = searchNode.next(); - Assert.assertEquals(nodePair.left().getAttributes().getString("id"),"10"); - Assert.assertEquals(nodePair.right().toString(), "<-1,0,0>"); + searchNode = ifTraverser.find((TreeNode node) -> { + List attribute = node.getAttributes().get("element"); + if (attribute.isNotEmpty()) { + byte[] byteAttribute = attribute.head().array(); + String str = new String(byteAttribute); + System.out.println("attribute = " + str); + return str.equals("name"); + } + return false; + }, "element", "name"); + searchNode.hasNext(); + nodePair = searchNode.next(); + Iterator textIterator = nodePair.left().getAttributes().getString("text"); + Assert.assertTrue(textIterator.hasNext()); + Assert.assertEquals(textIterator.next(), "tatsuki"); + Assert.assertEquals(nodePair.right().toString(), "<-1,0,0>"); + + searchNode = ifTraverser.find((TreeNode node) -> { + List attribute = node.getAttributes().get("text"); + if (attribute.isNotEmpty()) { + byte[] byteAttribute = attribute.head().array(); + String str = new String(byteAttribute); + System.out.println("attribute = " + str); + return str.equals("tatsuki"); + } + return false; + }, "text", "tatsuki"); - searchNode = ifTraverser.find((TreeNode node) -> { - ByteBuffer attribute = node.getAttributes().get("id"); - if (attribute != null) { - byte[] byteAttribute = attribute.array(); - String str = new String(byteAttribute); - System.out.println("attribute = " + str); - return str.equals("10"); - } - return false; - }, "id", "10"); - - nodePair = searchNode.next(); - Assert.assertEquals(nodePair.left().getAttributes().getString("id"),"10"); - Assert.assertEquals(nodePair.right().toString(), "<-1,0,0>"); - - } catch (Exception e) { - e.printStackTrace(); - } - } + nodePair = searchNode.next(); + Iterator idIterator = nodePair.left().getAttributes().getString("id"); + Assert.assertTrue(idIterator.hasNext()); + Assert.assertEquals(idIterator.next(), "10"); + Assert.assertEquals(nodePair.right().toString(), "<-1,0,0>"); + + searchNode = ifTraverser.find((TreeNode node) -> { + List attribute = node.getAttributes().get("id"); + if (attribute.isNotEmpty()) { + byte[] byteAttribute = attribute.head().array(); + String str = new String(byteAttribute); + System.out.println("attribute = " + str); + return str.equals("10"); + } + return false; + }, "id", "10"); + + nodePair = searchNode.next(); + idIterator = nodePair.left().getAttributes().getString("id"); + Assert.assertTrue(idIterator.hasNext()); + Assert.assertEquals(idIterator.next(), "10"); + Assert.assertEquals(nodePair.right().toString(), "<-1,0,0>"); + + } catch (Exception e) { + e.printStackTrace(); + } + } } \ No newline at end of file