Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 30c8305

Browse files
Challenge 44.
Predicate<String>, and, or, negate.
1 parent d461813 commit 30c8305

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /