Skip to content

Commit

Permalink
Merge pull request #102 from thiyagu-7/excel-row-order
Browse files Browse the repository at this point in the history
Changing PoijiHandler setValue method to see all fields
  • Loading branch information
ozlerhakan committed Oct 24, 2019
2 parents 2351a5a + 083f3f9 commit a98e449
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
21 changes: 8 additions & 13 deletions src/main/java/com/poiji/bind/mapping/PoijiHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,8 @@ private Object getInstance(Field field) {
return ins;
}

/***
* Modified this method so that for each time it reads a cell
* it doesn't need to check all fields even after it as found
* the matching field
*
* */
private boolean setValue(String content, Class<? super T> type, int column) {
boolean valueSet = false;
// For ExcelRow annotation
if(columnToField.containsKey(-1)) {
Field field = columnToField.get(-1);
Expand All @@ -100,12 +95,11 @@ private boolean setValue(String content, Class<? super T> type, int column) {
ins = getInstance(columnToSuperClassField.get(column));
if (setValue(field, column, content, ins)) {
setFieldData(columnToSuperClassField.get(column), ins, instance);
return true;
} else {
return false;
valueSet = true;
}
} else {
valueSet = setValue(field, column, content, instance);
}
return setValue(field, column, content, instance);
}
for (Field field : type.getDeclaredFields()) {

Expand All @@ -124,17 +118,18 @@ private boolean setValue(String content, Class<? super T> type, int column) {
setFieldData(field, ins, instance);
columnToField.put(column, f);
columnToSuperClassField.put(column, field);
return true;
valueSet = true;
break;
}
}
} else {
if(setValue(field, column, content, instance)) {
columnToField.put(column, field);
return true;
valueSet = true;
}
}
}
return false;
return valueSet;
}

private boolean setValue(Field field, int column, String content, Object ins) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
*/
public class PersonByName {

@ExcelRow
protected int row;

@ExcelCellName("Name")
protected String name;

Expand All @@ -23,6 +20,8 @@ public class PersonByName {
@ExcelCellName("Email")
protected String email;

@ExcelRow
protected int row;

public int getRow() {
return row;
Expand Down

0 comments on commit a98e449

Please sign in to comment.