CSV Update
parent
367816f400
commit
6d980ac411
|
@ -29,13 +29,24 @@ public class CSV {
|
|||
private char separator;
|
||||
private char enclosedBy;
|
||||
|
||||
private boolean ignoreDoubleSeparator;
|
||||
|
||||
public CSV()
|
||||
{
|
||||
this.records = new LinkedList<CSVRecord>();
|
||||
this.setSeparator(';');
|
||||
this.setEnclosedBy('\"');
|
||||
this.setEnclosedBy('\"');
|
||||
this.ignoreDoubleSeparator = false;
|
||||
}
|
||||
|
||||
public boolean isIgnoreDoubleSeparator() {
|
||||
return ignoreDoubleSeparator;
|
||||
}
|
||||
public void setIgnoreDoubleSeparator(boolean ignoreDoubleSeparator) {
|
||||
this.ignoreDoubleSeparator = ignoreDoubleSeparator;
|
||||
}
|
||||
|
||||
|
||||
public void readFromFile(String filename)
|
||||
{
|
||||
try {
|
||||
|
@ -99,7 +110,6 @@ public class CSV {
|
|||
record.appendValue(textToObject(celltext));
|
||||
}
|
||||
cell = new ArrayList<Character>();
|
||||
|
||||
} else if (this.enclosedBy == ch){
|
||||
if (enclosed){
|
||||
if (reader.peek() == ch){
|
||||
|
@ -124,6 +134,10 @@ public class CSV {
|
|||
cell.add(ch);
|
||||
}
|
||||
}
|
||||
if (cell != null){
|
||||
String celltext = StringHelper.fromCharacters(cell.toArray(new Character[0]));
|
||||
record.appendValue(celltext);
|
||||
}
|
||||
return record;
|
||||
}
|
||||
|
||||
|
@ -232,10 +246,6 @@ public class CSV {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public List<CSVRecord> getRecords()
|
||||
{
|
||||
|
@ -246,6 +256,16 @@ public class CSV {
|
|||
return records.get(row);
|
||||
}
|
||||
|
||||
public List<Object[]> getRecordsAsArray(){
|
||||
List<Object[]> list = new ArrayList<Object[]>();
|
||||
|
||||
for (CSVRecord record: getRecords()){
|
||||
list.add(record.getValuesAsArray());
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public char getSeparator() {
|
||||
return separator;
|
||||
}
|
||||
|
|
|
@ -46,6 +46,9 @@ public class CSVRecord {
|
|||
return null;
|
||||
}
|
||||
|
||||
public Object[] getValuesAsArray(){
|
||||
return columns.toArray();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue