-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathApply.java
More file actions
65 lines (49 loc) · 1.44 KB
/
Apply.java
File metadata and controls
65 lines (49 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package interfaces.classprocessor;
import java.util.*;
/**
* RUN:
* javac interfaces/classprocessor/Apply.java && java interfaces.classprocessor.Apply
*
* OUTPUT:
* Using Processor Upcase
* DISAGREEMENT WITH BELIEFS IS BY DEFINITION INCORRECT
* Using Processor Downcase
* disagreement with beliefs is by definition incorrect
* Using Processor Splitter
* [Disagreement, with, beliefs, is, by, definition, incorrect]
*/
public class Apply {
public static void process(Processor p, Object s) {
System.out.println("Using Processor " + p.name());
System.out.println(p.process(s));
}
public static String s = "Disagreement with beliefs is by definition incorrect";
public static void main(String[] args) {
process(new Upcase(), s);
process(new Downcase(), s);
process(new Splitter(), s);
}
}
class Processor {
public String name() {
return getClass().getSimpleName();
}
Object process(Object input) {
return input;
}
}
class Upcase extends Processor {
String process(Object input) {
return ((String) input).toUpperCase();
}
}
class Downcase extends Processor {
String process(Object input) {
return ((String) input).toLowerCase();
}
}
class Splitter extends Processor {
String process(Object input) {
return Arrays.toString(((String) input).split(" "));
}
}