Formatted all files to the same standard
This commit is contained in:
@ -1,22 +1,22 @@
|
||||
package com.iluwatar;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Visitor pattern defines mechanism to apply operations (UnitVisitor) on nodes
|
||||
* (Unit) in hierarchy. New operations can be added without altering the node
|
||||
* interface.
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class App {
|
||||
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) {
|
||||
|
||||
Commander commander = new Commander(
|
||||
new Sergeant(new Soldier(), new Soldier(), new Soldier()),
|
||||
new Sergeant(new Soldier(), new Soldier(), new Soldier()));
|
||||
commander.accept(new SoldierVisitor());
|
||||
commander.accept(new SergeantVisitor());
|
||||
commander.accept(new CommanderVisitor());
|
||||
Commander commander = new Commander(new Sergeant(new Soldier(),
|
||||
new Soldier(), new Soldier()), new Sergeant(new Soldier(),
|
||||
new Soldier(), new Soldier()));
|
||||
commander.accept(new SoldierVisitor());
|
||||
commander.accept(new SergeantVisitor());
|
||||
commander.accept(new CommanderVisitor());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ package com.iluwatar;
|
||||
|
||||
public class Commander extends Unit {
|
||||
|
||||
public Commander(Unit ... children) {
|
||||
public Commander(Unit... children) {
|
||||
super(children);
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ public class Commander extends Unit {
|
||||
visitor.visitCommander(this);
|
||||
super.accept(visitor);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "commander";
|
||||
|
@ -2,7 +2,7 @@ package com.iluwatar;
|
||||
|
||||
public class Sergeant extends Unit {
|
||||
|
||||
public Sergeant(Unit ... children) {
|
||||
public Sergeant(Unit... children) {
|
||||
super(children);
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ public class Sergeant extends Unit {
|
||||
visitor.visitSergeant(this);
|
||||
super.accept(visitor);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "sergeant";
|
||||
|
@ -2,7 +2,7 @@ package com.iluwatar;
|
||||
|
||||
public class Soldier extends Unit {
|
||||
|
||||
public Soldier(Unit ... children) {
|
||||
public Soldier(Unit... children) {
|
||||
super(children);
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ public class Soldier extends Unit {
|
||||
visitor.visitSoldier(this);
|
||||
super.accept(visitor);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "soldier";
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.iluwatar;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Interface for the nodes in hierarchy.
|
||||
*
|
||||
*/
|
||||
@ -9,12 +9,12 @@ public abstract class Unit {
|
||||
|
||||
private Unit[] children;
|
||||
|
||||
public Unit(Unit ... children) {
|
||||
public Unit(Unit... children) {
|
||||
this.children = children;
|
||||
}
|
||||
|
||||
|
||||
public void accept(UnitVisitor visitor) {
|
||||
for (Unit child: children) {
|
||||
for (Unit child : children) {
|
||||
child.accept(visitor);
|
||||
}
|
||||
}
|
||||
|
@ -3,12 +3,14 @@ package com.iluwatar;
|
||||
/**
|
||||
*
|
||||
* Visitor interface.
|
||||
*
|
||||
*
|
||||
*/
|
||||
public interface UnitVisitor {
|
||||
|
||||
void visitSoldier(Soldier soldier);
|
||||
|
||||
void visitSergeant(Sergeant sergeant);
|
||||
|
||||
void visitCommander(Commander commander);
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user