File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
src/main/java/challenge41_50 Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ package challenge41_50 ;
2+
3+ import java .util .function .Predicate ;
4+
5+ /**
6+ * String
7+ * Predicate<String>
8+ * and, or, negate ---> default implementation in the interface.
9+ * boolean test(String s) should be overridden.
10+ */
11+ public class Challenge_44 {
12+ public static void main ( String [] args ) {
13+ var newSlay = "---" ;
14+ var jamesShot = "---" ;
15+
16+ final Predicate <String > pyramidHeadAttack = new Predicate <String >() {
17+ @ Override
18+ public boolean test ( String s ) {
19+ return newSlay == new String (s ).intern ();
20+ } //true
21+ }.and (new PyramidHead ()) //&& false
22+ .or (james ->james .equals (jamesShot )) //||true
23+ .negate (); //!true--> false
24+ System .out .println (pyramidHeadAttack .test ("---" ));
25+
26+ }
27+
28+ static class PyramidHead implements Predicate <String > {
29+ @ Override
30+ public boolean test ( String s ) {
31+ return s .equals ("--!" );
32+ }
33+ }
34+ }
You can’t perform that action at this time.
0 commit comments