1
This commit is contained in:
parent
b1d698efca
commit
54788a288d
57
CsvReader.java
Normal file
57
CsvReader.java
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
package a6;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CsvReader {
|
||||||
|
|
||||||
|
private HashMap<String, Integer> columns = new HashMap<String, Integer>();
|
||||||
|
private ArrayList<String> values = new ArrayList<String>();
|
||||||
|
private ArrayList<String> strings = new ArrayList<String>();
|
||||||
|
private int curr_line = 0;
|
||||||
|
|
||||||
|
public boolean load(String filename) {
|
||||||
|
boolean ret = SysUtils.readStrings(filename, strings);
|
||||||
|
if (ret) {
|
||||||
|
if (nextLine()) {
|
||||||
|
for (int i = 0; i < values.size(); ++i) {
|
||||||
|
columns.put(values.get(i), i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean nextLine() {
|
||||||
|
if (curr_line >= strings.size()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
values.clear();
|
||||||
|
for (String val : strings.get(curr_line).split(",")) {
|
||||||
|
values.add(val);
|
||||||
|
}
|
||||||
|
++curr_line;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public XValue getValue(String key) {
|
||||||
|
if (!keyExists(key)) {
|
||||||
|
return new XValue();
|
||||||
|
}
|
||||||
|
String val = values.get(columns.get(key));
|
||||||
|
return new XValue(val
|
||||||
|
.replaceAll("\\n", "\n")
|
||||||
|
.replaceAll(",", ",")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean keyExists(String key) {
|
||||||
|
return columns.containsKey(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
9
MutableXObject.java
Normal file
9
MutableXObject.java
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package a6;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class MutableXObject extends XObject {
|
||||||
|
|
||||||
|
}
|
@ -1,5 +1,13 @@
|
|||||||
package a6;
|
package a6;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import java.lang.reflect.Array;
|
import java.lang.reflect.Array;
|
||||||
|
|
||||||
public class SysUtils {
|
public class SysUtils {
|
||||||
@ -29,4 +37,25 @@ public class SysUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean readStrings(String filename, ArrayList<String> strings) {
|
||||||
|
File csvfile = new File(filename);
|
||||||
|
csvfile.setReadable(true);
|
||||||
|
BufferedReader br = null;
|
||||||
|
try {
|
||||||
|
br = new BufferedReader(new FileReader(csvfile));
|
||||||
|
String line;
|
||||||
|
try {
|
||||||
|
while ((line = br.readLine()) != null) {
|
||||||
|
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
56
XObject.java
56
XObject.java
@ -1,5 +1,61 @@
|
|||||||
package a6;
|
package a6;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class XObject {
|
public class XObject {
|
||||||
|
|
||||||
|
private XValue xValue;
|
||||||
|
private ArrayList arrayValue;
|
||||||
|
private HashMap objectValue;
|
||||||
|
|
||||||
|
public XValue asXValue() {
|
||||||
|
return xValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public XObject get(int index) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public XObject get(String key) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasKey(int index) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasKey(String key) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean readFromJsonFile(String filename) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean readFromJsonString(String data) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean readFromXmlFile(String filename) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean readFromXmlString(String data) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void readFromUrlQueryString(String query_string) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toJsonStr() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toUrlEncodeStr() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user