From 6c8cb4bd2196500e249bd87f370f97d9fe428bc3 Mon Sep 17 00:00:00 2001 From: snoop Date: Tue, 25 Apr 2017 16:36:53 +0900 Subject: [PATCH] changed resultset row / col --- .../overflow/crawler/result/OFResultSet.java | 59 +++---------------- .../crawler/result/OFResultSetCol.java | 39 ++++++++++++ .../crawler/result/OFResultSetRow.java | 51 ++++++++++++++++ 3 files changed, 97 insertions(+), 52 deletions(-) create mode 100644 src/main/java/com/loafle/overflow/crawler/result/OFResultSetCol.java create mode 100644 src/main/java/com/loafle/overflow/crawler/result/OFResultSetRow.java diff --git a/src/main/java/com/loafle/overflow/crawler/result/OFResultSet.java b/src/main/java/com/loafle/overflow/crawler/result/OFResultSet.java index 3ebc56e..6d01264 100644 --- a/src/main/java/com/loafle/overflow/crawler/result/OFResultSet.java +++ b/src/main/java/com/loafle/overflow/crawler/result/OFResultSet.java @@ -10,11 +10,11 @@ import java.util.Map; /** * Created by root on 17. 4. 25. */ -public class OFResultSet { +public abstract class OFResultSet { - private Item item; - private List> rows; - private Map meta = null; + protected Item item; + protected List> rows; + protected Map meta = null; public Map getMeta() { return meta; @@ -41,40 +41,8 @@ public class OFResultSet { } - public void setMeta() { - String type = (String) this.item.getQuery().getQueryInfo().get("parseDirection"); - List meta = new ArrayList<>(); - if (type.equals("row")) { - - List arrayColumns = (List) this.item.getQuery().getQueryInfo().get("arrayColumns"); - List keyColumns = (List) this.item.getQuery().getQueryInfo().get("keyColumns"); - String valueColumn = (String) this.item.getQuery().getQueryInfo().get("valueColumn"); - - for (String c : arrayColumns) { - meta.add(c); - } - for (String c: keyColumns) { - meta.add(c); - } - meta.add(valueColumn); - - } else { - - } - - - if(this.meta == null) { - this.meta = new HashMap<>(); - } - - for(int indexI = 0; indexI < meta.size(); ++indexI) { - this.meta.put(meta.get(indexI), indexI); - } - - } - public OFResultSet(Item item) { this.item = item; this.rows = new ArrayList<>(); @@ -87,25 +55,12 @@ public class OFResultSet { public Map getData() { - String type = (String) this.item.getQuery().getQueryInfo().get("parseType"); - if (type.equals("row")) { - return parseRow(); - } else { - return parseCol(); - } + return parse(); } - public Map parseCol() { + public abstract void setMeta(); + public abstract Map parse(); - - - return null; - } - - public Map parseRow() { - return null; - } - } diff --git a/src/main/java/com/loafle/overflow/crawler/result/OFResultSetCol.java b/src/main/java/com/loafle/overflow/crawler/result/OFResultSetCol.java new file mode 100644 index 0000000..aeed290 --- /dev/null +++ b/src/main/java/com/loafle/overflow/crawler/result/OFResultSetCol.java @@ -0,0 +1,39 @@ +package com.loafle.overflow.crawler.result; + +import com.loafle.overflow.crawler.config.Item; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Created by root on 17. 4. 25. + */ +public class OFResultSetCol extends OFResultSet{ + + + public OFResultSetCol(Item item) { + super(item); + } + + public void setMeta() { + + List meta = this.item.getQuery().getKeys(); + + if(this.meta == null) { + this.meta = new HashMap<>(); + } + + for(int indexI = 0; indexI < meta.size(); ++indexI) { + this.meta.put(meta.get(indexI), indexI); + } + + } + + public Map parse() { + + return null; + + } +} diff --git a/src/main/java/com/loafle/overflow/crawler/result/OFResultSetRow.java b/src/main/java/com/loafle/overflow/crawler/result/OFResultSetRow.java new file mode 100644 index 0000000..cd558ba --- /dev/null +++ b/src/main/java/com/loafle/overflow/crawler/result/OFResultSetRow.java @@ -0,0 +1,51 @@ +package com.loafle.overflow.crawler.result; + +import com.loafle.overflow.crawler.config.Item; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Created by root on 17. 4. 25. + */ +public class OFResultSetRow extends OFResultSet{ + + + public OFResultSetRow(Item item) { + super(item); + } + + public void setMeta() { + + List meta = new ArrayList<>(); + + List arrayColumns = (List) this.item.getQuery().getQueryInfo().get("arrayColumns"); + List keyColumns = (List) this.item.getQuery().getQueryInfo().get("keyColumns"); + String valueColumn = (String) this.item.getQuery().getQueryInfo().get("valueColumn"); + + for (String c : arrayColumns) { + meta.add(c); + } + for (String c: keyColumns) { + meta.add(c); + } + meta.add(valueColumn); + + if(this.meta == null) { + this.meta = new HashMap<>(); + } + + for(int indexI = 0; indexI < meta.size(); ++indexI) { + this.meta.put(meta.get(indexI), indexI); + } + + } + + public Map parse() { + + return null; + + } +}