Repository: incubator-pirk Updated Branches: refs/heads/master d992fa293 -> bc740a79b
Remove unused Var and Tidy-up, this closes apache/incubator-pirk#67 Project: http://git-wip-us.apache.org/repos/asf/incubator-pirk/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-pirk/commit/bc740a79 Tree: http://git-wip-us.apache.org/repos/asf/incubator-pirk/tree/bc740a79 Diff: http://git-wip-us.apache.org/repos/asf/incubator-pirk/diff/bc740a79 Branch: refs/heads/master Commit: bc740a79b8b4f64be0e53526468856e1b8b91768 Parents: d992fa2 Author: Tim Ellison <t.p.elli...@gmail.com> Authored: Thu Aug 18 09:37:52 2016 -0400 Committer: smarthi <smar...@apache.org> Committed: Thu Aug 18 09:37:52 2016 -0400 ---------------------------------------------------------------------- .../wideskies/decrypt/DecryptResponse.java | 43 +++++++++----------- .../decrypt/DecryptResponseRunnable.java | 34 ++++++---------- 2 files changed, 32 insertions(+), 45 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-pirk/blob/bc740a79/src/main/java/org/apache/pirk/querier/wideskies/decrypt/DecryptResponse.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/pirk/querier/wideskies/decrypt/DecryptResponse.java b/src/main/java/org/apache/pirk/querier/wideskies/decrypt/DecryptResponse.java index 928c852..2231160 100644 --- a/src/main/java/org/apache/pirk/querier/wideskies/decrypt/DecryptResponse.java +++ b/src/main/java/org/apache/pirk/querier/wideskies/decrypt/DecryptResponse.java @@ -20,13 +20,13 @@ package org.apache.pirk.querier.wideskies.decrypt; import java.io.BufferedWriter; import java.io.File; -import java.io.FileOutputStream; +import java.io.FileWriter; import java.io.IOException; -import java.io.OutputStreamWriter; import java.math.BigInteger; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Map.Entry; import java.util.TreeMap; import java.util.concurrent.ExecutorService; @@ -49,18 +49,16 @@ public class DecryptResponse { private static final Logger logger = LoggerFactory.getLogger(DecryptResponse.class); - private Response response = null; + private final Response response; - private Querier querier = null; + private final Querier querier; - private HashMap<String,ArrayList<QueryResponseJSON>> resultMap = null; // selector -> ArrayList of hits + private final Map<String,List<QueryResponseJSON>> resultMap = new HashMap<>(); // selector -> ArrayList of hits public DecryptResponse(Response responseInput, Querier querierInput) { response = responseInput; querier = querierInput; - - resultMap = new HashMap<>(); } /** @@ -157,8 +155,7 @@ public class DecryptResponse // Pull all decrypted elements and add to resultMap for (DecryptResponseRunnable runner : runnables) { - HashMap<String,ArrayList<QueryResponseJSON>> decValues = runner.getResultMap(); - resultMap.putAll(decValues); + resultMap.putAll(runner.getResultMap()); } } @@ -182,17 +179,17 @@ public class DecryptResponse */ public void writeResultFile(String filename) throws IOException { - FileOutputStream fout = new FileOutputStream(new File(filename)); - BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fout)); - for (Entry<String,ArrayList<QueryResponseJSON>> entry : resultMap.entrySet()) + try (BufferedWriter bw = new BufferedWriter(new FileWriter(new File(filename)))) { - for (QueryResponseJSON hitJSON : entry.getValue()) + for (Entry<String,List<QueryResponseJSON>> entry : resultMap.entrySet()) { - bw.write(hitJSON.getJSONString()); - bw.newLine(); + for (QueryResponseJSON hitJSON : entry.getValue()) + { + bw.write(hitJSON.getJSONString()); + bw.newLine(); + } } } - bw.close(); } /** @@ -201,16 +198,16 @@ public class DecryptResponse */ public void writeResultFile(File file) throws IOException { - FileOutputStream fout = new FileOutputStream(file); - BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fout)); - for (Entry<String,ArrayList<QueryResponseJSON>> entry : resultMap.entrySet()) + try (BufferedWriter bw = new BufferedWriter(new FileWriter(file))) { - for (QueryResponseJSON hitJSON : entry.getValue()) + for (Entry<String,List<QueryResponseJSON>> entry : resultMap.entrySet()) { - bw.write(hitJSON.getJSONString()); - bw.newLine(); + for (QueryResponseJSON hitJSON : entry.getValue()) + { + bw.write(hitJSON.getJSONString()); + bw.newLine(); + } } } - bw.close(); } } http://git-wip-us.apache.org/repos/asf/incubator-pirk/blob/bc740a79/src/main/java/org/apache/pirk/querier/wideskies/decrypt/DecryptResponseRunnable.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/pirk/querier/wideskies/decrypt/DecryptResponseRunnable.java b/src/main/java/org/apache/pirk/querier/wideskies/decrypt/DecryptResponseRunnable.java index 02f51b8..531ec6a 100644 --- a/src/main/java/org/apache/pirk/querier/wideskies/decrypt/DecryptResponseRunnable.java +++ b/src/main/java/org/apache/pirk/querier/wideskies/decrypt/DecryptResponseRunnable.java @@ -21,6 +21,8 @@ package org.apache.pirk.querier.wideskies.decrypt; import java.math.BigInteger; import java.util.ArrayList; import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.TreeMap; import org.apache.pirk.query.wideskies.QueryInfo; @@ -28,7 +30,6 @@ import org.apache.pirk.query.wideskies.QueryUtils; import org.apache.pirk.schema.query.QuerySchema; import org.apache.pirk.schema.query.QuerySchemaRegistry; import org.apache.pirk.schema.response.QueryResponseJSON; -import org.apache.pirk.utils.SystemConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -42,36 +43,25 @@ public class DecryptResponseRunnable implements Runnable { private static final Logger logger = LoggerFactory.getLogger(DecryptResponseRunnable.class); - private HashMap<String,ArrayList<QueryResponseJSON>> resultMap = null; // selector -> ArrayList of hits + private final Map<String,List<QueryResponseJSON>> resultMap = new HashMap<>(); // selector -> ArrayList of hits + private final List<BigInteger> rElements; + private final TreeMap<Integer,String> selectors; + private final Map<String,BigInteger> selectorMaskMap; + private final QueryInfo queryInfo; - private ArrayList<BigInteger> rElements = null; - private TreeMap<Integer,String> selectors = null; - private HashMap<String,BigInteger> selectorMaskMap = null; - private QueryInfo queryInfo = null; - private QuerySchema qSchema = null; + private final Map<Integer,String> embedSelectorMap; - private HashMap<Integer,String> embedSelectorMap = null; - - public DecryptResponseRunnable(ArrayList<BigInteger> rElementsInput, TreeMap<Integer,String> selectorsInput, HashMap<String,BigInteger> selectorMaskMapInput, - QueryInfo queryInfoInput, HashMap<Integer,String> embedSelectorMapInput) + public DecryptResponseRunnable(List<BigInteger> rElementsInput, TreeMap<Integer,String> selectorsInput, Map<String,BigInteger> selectorMaskMapInput, + QueryInfo queryInfoInput, Map<Integer,String> embedSelectorMapInput) { rElements = rElementsInput; selectors = selectorsInput; selectorMaskMap = selectorMaskMapInput; queryInfo = queryInfoInput; embedSelectorMap = embedSelectorMapInput; - - if (SystemConfiguration.getBooleanProperty("pir.allowAdHocQuerySchemas", false)) - { - if ((qSchema = queryInfo.getQuerySchema()) == null) - { - qSchema = QuerySchemaRegistry.get(queryInfo.getQueryType()); - } - } - resultMap = new HashMap<>(); } - public HashMap<String,ArrayList<QueryResponseJSON>> getResultMap() + public Map<String,List<QueryResponseJSON>> getResultMap() { return resultMap; } @@ -165,7 +155,7 @@ public class DecryptResponseRunnable implements Runnable } if (addHit) { - ArrayList<QueryResponseJSON> selectorHitList = resultMap.get(selector); + List<QueryResponseJSON> selectorHitList = resultMap.get(selector); selectorHitList.add(qrJOSN); resultMap.put(selector, selectorHitList);