blob: d0c103516a0bc1657d624111f050f55572a2ee23 [file] [log] [blame]
Clément Béra81a031f2022-07-06 12:18:33 +02001// Copyright (c) 2022, the R8 project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5package lambda;
6
7import java.util.ArrayList;
8import java.util.List;
9
10public class Lambda {
11
12 interface StringPredicate {
13
14 boolean test(String t);
15
16 default StringPredicate or(StringPredicate other) {
17 return (t) -> test(t) || other.test(t);
18 }
19 }
20
21 public static void main(String[] args) {
22 ArrayList<String> strings = new ArrayList<>();
23 strings.add("abc");
24 strings.add("abb");
25 strings.add("bbc");
26 strings.add("aac");
27 strings.add("acc");
28 StringPredicate aaStart = Lambda::aaStart;
29 StringPredicate bbNot = Lambda::bbNot;
30 StringPredicate full = aaStart.or(bbNot);
31 for (String string : ((List<String>) strings.clone())) {
32 if (full.test(string)) {
33 strings.remove(string);
34 }
35 }
36 System.out.println(strings);
37 }
38
39 private static boolean aaStart(String str) {
40 return str.startsWith("aa");
41 }
42
43 private static boolean bbNot(String str) {
44 return !str.contains("bb");
45 }
46}