【发布时间】:2016-05-24 13:06:29
【问题描述】:
public class dosing {
public List<String> dosingColumnList(String roa){
List<String> dosingList = new ArrayList<String>();
dosingList.add("Dose");
dosingList.add("Time of Dose");
dosingList.add("Tau");
if(roa.equalsIgnoreCase("abc") ||
roa.equalsIgnoreCase("bcd")){
}
else if(roa.equalsIgnoreCase("cba")){
dosingList.add("Length of Infusion");
}
else if(roa.equalsIgnoreCase("cbd")){
dosingList.add("Length of Infusion");
}
return dosingList;
}
public boolean readFile(File filePath,int sheetNo,String roa) throws InvalidFormatException, IOException{
FileInputStream inputStream = new FileInputStream(filePath);
Workbook wb = WorkbookFactory.create(inputStream);
Sheet mySheet = wb.getSheetAt(sheetNo);
List<String> dosingColumnData =dosingColumnList(roa);
Iterator<Row> rowIter = mySheet.rowIterator();
List<String> headerData = new ArrayList<String>();
//rowIter.next();
while (rowIter.hasNext()){
Row row = rowIter.next();
Iterator<Cell> cellIterator = row.cellIterator();
while(row.getRowNum() == 0){
while (cellIterator.hasNext()){
Cell cell = cellIterator.next();
if(cell.getCellType() == Cell.CELL_TYPE_STRING){
String varData = cell.getStringCellValue();
headerData.add(varData);
}
}
break;
}
}
if (headerData == null || dosingColumnData == null){
}
if((headerData == null && dosingColumnData != null)
||( headerData != null && dosingColumnData == null)
|| (headerData.size() != dosingColumnData.size())){
}
headerData = new ArrayList<String>(headerData);
dosingColumnData = new ArrayList<String>(dosingColumnData);
Set<String> set1 = new HashSet<String>();
set1.addAll(headerData);
Set<String> set2 = new HashSet<String>();
set2.addAll(dosingColumnData);
System.out.println(set1 + " " + set2);
return set1.equals(set2);
}
}
这是我正在使用的代码...所有导入...所以 headerdata 列表包含来自 excel 表的行数据,而 dosingColumnData 包含来自用户选择的列表 ....SOP 的输出是 [Length, Time, Tau, Dose] [Length, Time, Tau, Dose]...虽然上面的两个集合有相同的类型,相同的大小,相同的元素顺序...return语句总是输出false
【问题讨论】:
-
在调用 equals 方法时,您不需要将
set2强制转换为对象 -
我的集合中的@Eran 元素是字符串
-
你能发一个minimal reproducible example吗?我无法重现。
-
@InFed 这是第三次有人要求您提供填充这些集合的代码。如果您不向我们提供足够的信息,您怎么能期望得到帮助...?
标签: java