我正在尝试创建一个返回通用表达式列表的方法。
在基于某些条件的中间我创建特定类型的ExpressionList,最后我想将ExpressionList转换为通用ExpressionList。但是,不幸的是我一直坚持转换。
下面是代码snipet。
我正在尝试创建一个返回通用表达式列表的方法。
在基于某些条件的中间我创建特定类型的ExpressionList,最后我想将ExpressionList转换为通用ExpressionList。但是,不幸的是我一直坚持转换。
下面是代码snipet。
public static <T> ExpressionList<T> generateTransactionList(Map<String,String[]> params, Party party){
String filter = "";
Date startDate = new Date(params.get("startDate")[0]);
Date endDate = new Date(params.get("endDate")[0]+" 23:59:59");
//endDate.setDate(endDate.getDate() + 1);
ExpressionList<TypeOne> TypeOneExpressionList = null;
ExpressionList<TypeTwo> TypeTwoResponseExpressionList = null;
if(settleState == 3) {
TypeTwoResponseExpressionList = TypeTwo.find.select("*").where()
.between("response_date", startDate, endDate)
.eq("status", "failed");
}
else {
acquiringTransactionExpressionList = AcquiringTransaction.find.select("*").where()
.between("transactionTime", startDate, endDate)
.ne("acquiringTransactionStatusType.id", 99);
}
ExpressionList<T> returningTypeOneExpressionList = null;
Class<T> convert = null;
if(TypeOneExpressionList != null) {
TypeOneExpressionList.orderBy("id desc" );
Iterator<TypeOne> iterator = TypeOneExpressionList.findIterate();
while(iterator.hasNext()) {
returningTypeOneExpressionList.add((Expression) convert.cast(iterator.next()));
}
}
else {
TypeTwoResponseExpressionList.orderBy("id desc" );
Iterator<TypeTwo> iterator = TypeTwoResponseExpressionList.findIterate();
while(iterator.hasNext()) {
returningTypeOneExpressionList.add((Expression) convert.cast(iterator.next()));
}
}
return returningTypeOneExpressionList;
}
提前致谢。
答案 0 :(得分:0)
我找到了答案,而且我之前没有尝试过,这真的很糟糕。
我刚刚在代码中进行了以下更改。
public static <T> ExpressionList<T> generateTransactionList(Map<String,String[]> params, Party party){
String filter = "";
Date startDate = new Date(params.get("startDate")[0]);
Date endDate = new Date(params.get("endDate")[0]+" 23:59:59");
//endDate.setDate(endDate.getDate() + 1);
ExpressionList<TypeOne> TypeOneExpressionList = null;
ExpressionList<TypeTwo> TypeTwoResponseExpressionList = null;
if(settleState == 3) {
TypeTwoResponseExpressionList = TypeTwo.find.select("*").where()
.between("response_date", startDate, endDate)
.eq("status", "failed");
}
else {
acquiringTransactionExpressionList = AcquiringTransaction.find.select("*").where()
.between("transactionTime", startDate, endDate)
.ne("acquiringTransactionStatusType.id", 99);
}
ExpressionList<T> returningAcquiringTransactionExpressionList = null;
Class<T> convert = null;
if(acquiringTransactionExpressionList != null) {
acquiringTransactionExpressionList.orderBy("id desc" );
returningAcquiringTransactionExpressionList = (ExpressionList<T>) acquiringTransactionExpressionList;
}
else {
acquiringTransactionResponseExpressionList.orderBy("id desc" );
returningAcquiringTransactionExpressionList = (ExpressionList<T>) acquiringTransactionResponseExpressionList;
}
return returningTypeOneExpressionList;
}