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; + + } +}