File tree Expand file tree Collapse file tree 13 files changed +158
-5
lines changed Expand file tree Collapse file tree 13 files changed +158
-5
lines changed Original file line number Diff line number Diff line change 6
6
7
7
public class Client {
8
8
9
- public static void main (String [] args ) {
9
+ public static void main (String [] args ) throws InterruptedException {
10
10
Invoker invoker = new Invoker (new Receiver ());
11
11
invoker .setCommand (TypeCommand .OPEN );
12
12
invoker .execute ();
13
+ Thread .sleep (1500 );
13
14
invoker .setCommand (TypeCommand .EXIT );
14
15
invoker .execute ();
15
16
}
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ public ExitCommand(Receiver receiver) {
12
12
13
13
@ Override
14
14
public void execute () {
15
- receiver .close ();
15
+ receiver .exit ();
16
16
}
17
17
18
18
}
Original file line number Diff line number Diff line change 3
3
public class Receiver {
4
4
5
5
public void open () {
6
- System .out .println ("open. " );
6
+ System .out .println ("open" );
7
7
}
8
8
9
- public void close () {
10
- System .out .println ("close. " );
9
+ public void exit () {
10
+ System .out .println ("exit " );
11
11
}
12
12
}
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2
+ <classpath >
3
+ <classpathentry kind =" src" path =" src" />
4
+ <classpathentry kind =" con" path =" org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8" />
5
+ <classpathentry kind =" output" path =" bin" />
6
+ </classpath >
Original file line number Diff line number Diff line change
1
+ /bin /
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2
+ <projectDescription >
3
+ <name >Strategy</name >
4
+ <comment ></comment >
5
+ <projects >
6
+ </projects >
7
+ <buildSpec >
8
+ <buildCommand >
9
+ <name >org.eclipse.jdt.core.javabuilder</name >
10
+ <arguments >
11
+ </arguments >
12
+ </buildCommand >
13
+ </buildSpec >
14
+ <natures >
15
+ <nature >org.eclipse.jdt.core.javanature</nature >
16
+ </natures >
17
+ </projectDescription >
Original file line number Diff line number Diff line change
1
+ eclipse.preferences.version =1
2
+ org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode =enabled
3
+ org.eclipse.jdt.core.compiler.codegen.targetPlatform =1.8
4
+ org.eclipse.jdt.core.compiler.codegen.unusedLocal =preserve
5
+ org.eclipse.jdt.core.compiler.compliance =1.8
6
+ org.eclipse.jdt.core.compiler.debug.lineNumber =generate
7
+ org.eclipse.jdt.core.compiler.debug.localVariable =generate
8
+ org.eclipse.jdt.core.compiler.debug.sourceFile =generate
9
+ org.eclipse.jdt.core.compiler.problem.assertIdentifier =error
10
+ org.eclipse.jdt.core.compiler.problem.enumIdentifier =error
11
+ org.eclipse.jdt.core.compiler.source =1.8
Original file line number Diff line number Diff line change
1
+
2
+ public class ContextVisit <T > {
3
+
4
+ private Visit <T > visit ;
5
+
6
+ private Node <T > root ;
7
+
8
+ public ContextVisit (Node <T > root ) {
9
+ this .root = root ;
10
+ }
11
+
12
+ public void setRoot (Node <T > root ) {
13
+ this .root = root ;
14
+ }
15
+
16
+ public void setVisit (Visit <T > visit ) {
17
+ this .visit = visit ;
18
+ }
19
+
20
+ public void visit () {
21
+ visit .visit (root );
22
+ }
23
+ }
Original file line number Diff line number Diff line change
1
+
2
+ public class DeepVisit <T > implements Visit <T > {
3
+
4
+ @ Override
5
+ public void visit (Node <T > root ) {
6
+ System .out .print (root );
7
+ for (Node <T > node : root .getChildren ())
8
+ visit (node );
9
+ }
10
+
11
+ }
Original file line number Diff line number Diff line change
1
+ import java .util .ArrayList ;
2
+
3
+ public class LevelVisit <T > implements Visit <T > {
4
+
5
+ @ Override
6
+ public void visit (Node <T > root ) {
7
+ ArrayList <Node <T >> queue = new ArrayList <Node <T >>();
8
+ queue .add (root );
9
+ while (!queue .isEmpty ()) {
10
+ System .out .print (queue .get (0 ));
11
+ queue .addAll (queue .get (0 ).getChildren ());
12
+ queue .remove (0 );
13
+ }
14
+ }
15
+
16
+ }
You can’t perform that action at this time.
0 commit comments