下面代码 是过滤List中的对象,->后面为条件,满足条件的才会放入List中
java 8 中lambda表达式写法
public static void filter(List<SQLStatement> stmtList) {
stmtList = stmtList.stream().filter(stmt -> !(stmt instanceof OracleInsertStatement) && stmt.getParent() == null).collect(Collectors.toList());
stmtList = stmtList.stream().filter(stmt -> !(stmt instanceof OracleUpdateStatement) && stmt.getParent() == null).collect(Collectors.toList());
stmtList = stmtList.stream().filter(stmt -> !(stmt instanceof OracleDeleteStatement) && stmt.getParent() == null).collect(Collectors.toList());
stmtList = stmtList.stream().filter(stmt -> !(stmt instanceof SQLSelectStatement) && stmt.getParent() == null).collect(Collectors.toList());
stmtList = stmtList.stream().filter(stmt -> !(stmt instanceof SQLUpdateStatement) && stmt.getParent() == null).collect(Collectors.toList());
stmtList = stmtList.stream().filter(stmt -> !(stmt instanceof SQLInsertStatement) && stmt.getParent() == null).collect(Collectors.toList());
stmtList = stmtList.stream().filter(stmt -> !(stmt instanceof SQLDeleteStatement) && stmt.getParent() == null).collect(Collectors.toList());
}
java 7 以前写法
stmtList.stream().filter(new Predicate<SQLStatement>() {
@Override
public boolean test(SQLStatement stmt) {
return !(stmt instanceof OracleInsertStatement);
}
}).collect(Collectors.toList());