Mercurial > hg > Members > shoshi > jungle > jungle-core
changeset 243:fe0d5ed68caf Implementation_of_communication
add condition
author | tatsuki |
---|---|
date | Thu, 18 Feb 2016 14:08:01 +0900 |
parents | 30c0ca7d36a5 |
children | 5d033ad129b2 |
files | src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/commandline/commandline.java |
diffstat | 1 files changed, 84 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/commandline/commandline.java Mon Feb 15 14:20:09 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/commandline/commandline.java Thu Feb 18 14:08:01 2016 +0900 @@ -63,7 +63,7 @@ } private void parse(String sql) { - String[] split = sql.split("\\."); + String[] split = sql.replace(" ", "").split("\\."); Iterator<String> iterator = new Iterator<String>() { private int count = 0; @@ -92,20 +92,20 @@ if (cmd[1] != null) { switch (cmd[0]) { - case "find": //検索 treeName.find(検索するkey 例 id) 絞込はまだ treeNameは:revisionで過去のTreeにアクセス可能 - String condition = cmd[1].replace(")", "").replace(" ", ""); // )を取り除く + case "find": //検索 treeName.find(検索するkey 例 id) 絞込はまだ treeNameは:revisionで過去のTreeにアクセス可能 find(条件,{表示するkey}) + String condition = cmd[1].replace(")", ""); // )を取り除く find(treeName, condition, iterator); break; case "insert"://Nodeの追加 treeName.insert(<path>,key:value,key:value………) - String value = cmd[1].replace(")", "").replace(" ", ""); // )を取り除く + String value = cmd[1].replace(")", ""); // )を取り除く insert(treeName, value, iterator); break; case "insertAttribute"://attribute等のupdate treeName.insertAttribute(path,key:value, ………) treeName path <Path> keys key values attribute - value = cmd[1].replace(")", "").replace(" ", ""); // )を取り除く + value = cmd[1].replace(")", ""); // )を取り除く update(treeName, value, iterator); break; case "import"://attribute等のupdate treeName path <Path> keys key values attribute - String url = cmd[1].replace(")", "").replace(" ", ""); // )を取り除く + String url = cmd[1].replace(")", ""); // )を取り除く dataImport(treeName, url); //xmlをimportする treename.import(url) break; } @@ -232,9 +232,19 @@ } - private void find(String treeName, String condition, Iterator<String> iterator) { //conditionには条件が入るが今はkeyのみしか入らない。 + private void find(String treeName, String args, Iterator<String> iterator) { //conditionには条件が入るが今はkeyのみしか入らない。 //取得するkeyの取得 - String[] keys = condition.split(","); + String[] conditionAndKeys = args.split("\\{"); + String[] conditions = conditionAndKeys[0].split(","); + + String[] keys; + + if (conditionAndKeys.length >= 2) + keys = conditionAndKeys[1].replace("}", "").split(","); + else { + keys = new String[1]; + keys[0] = ""; + } String[] split = treeName.split(":"); // TreeName:idで表記されているのでTreename と Idに分割する treeName = split[0];//TreeNameの取得 JungleTree tree = jungle.getTreeByName(treeName); @@ -253,8 +263,73 @@ } InterfaceTraverser traverser = tree.getTraverser(true); + Iterator<TreeNode> nodeIterator = traverser.find((TreeNode node) -> { //この場合条件がないので探索する木のNodeを全て取得する + for (String condition : conditions) { + String[] keyConditionPair; - Iterator<TreeNode> nodeIterator = traverser.find((TreeNode node) -> { //この場合条件がないので探索する木のNodeを全て取得する + if (condition.contains(">=")) { + keyConditionPair = condition.split(">="); + String key = keyConditionPair[0]; + String valueString = node.getAttributes().getString(key); + if (valueString == null) + return false; + int value = new Integer(valueString); + int require = new Integer(keyConditionPair[1]); + if (value >= require) + continue; + return false; + } + + if (condition.contains("<=")) { + keyConditionPair = condition.split("<="); + String key = keyConditionPair[0]; + String valueString = node.getAttributes().getString(key); + if (valueString == null) + return false; + int value = new Integer(valueString); + int require = new Integer(keyConditionPair[1]); + if (value <= require) + continue; + return false; + } + + if (condition.contains("<")) { + keyConditionPair = condition.split("<"); + String key = keyConditionPair[0]; + String valueString = node.getAttributes().getString(key); + if (valueString == null) + return false; + int value = new Integer(valueString); + int require = new Integer(keyConditionPair[1]); + if (value < require) + continue; + return false; + } + + + if (condition.contains(">")) { + keyConditionPair = condition.split(">"); + String key = keyConditionPair[0]; + String valueString = node.getAttributes().getString(key); + if (valueString == null) + return false; + int value = new Integer(valueString); + int require = new Integer(keyConditionPair[1]); + if (value > require) + continue; + return false; + } + + keyConditionPair = condition.split("="); + if (keyConditionPair.length == 1) + continue; + String value = node.getAttributes().getString(keyConditionPair[0]); + String requireValue = keyConditionPair[1]; + if (value == null) + return false; + if (!value.equals(requireValue)) + return false; + } return true; }); @@ -273,7 +348,6 @@ public boolean hasNext() { return count < keys.length; } - @Override public String next() { String tmp = keys[count];