下面代碼 是過濾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());
