File tree Expand file tree Collapse file tree
main/java/com/iluwatar/proxy
test/java/com/iluwatar/proxy Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- package com.iluwatar.proxy;
2-
3- /**
4- *
5- * Proxy (WizardTowerProxy) controls access to the actual object (WizardTower).
6- *
7- */
8- public class App {
9-
10- public static void main(String[] args) {
11-
12- WizardTowerProxy tower = new WizardTowerProxy();
13- tower.enter(new Wizard("Red wizard"));
14- tower.enter(new Wizard("White wizard"));
15- tower.enter(new Wizard("Black wizard"));
16- tower.enter(new Wizard("Green wizard"));
17- tower.enter(new Wizard("Brown wizard"));
18-
19- }
20- }
1+ package com.iluwatar.proxy;
2+
3+ /**
4+ *
5+ * Proxy ({@link WizardTowerProxy} ) controls access to the actual object ({@link WizardTower}).
6+ *
7+ */
8+ public class App {
9+
10+ public static void main(String[] args) {
11+
12+ WizardTowerProxy tower = new WizardTowerProxy();
13+ tower.enter(new Wizard("Red wizard"));
14+ tower.enter(new Wizard("White wizard"));
15+ tower.enter(new Wizard("Black wizard"));
16+ tower.enter(new Wizard("Green wizard"));
17+ tower.enter(new Wizard("Brown wizard"));
18+
19+ }
20+ }
Original file line number Diff line number Diff line change 1- package com.iluwatar.proxy;
2-
3- public class Wizard {
4-
5- private String name;
6-
7- public Wizard(String name) {
8- this.name = name;
9- }
10-
11- @Override
12- public String toString() {
13- return name;
14- }
15-
16- }
1+ package com.iluwatar.proxy;
2+
3+ /**
4+ *
5+ * Wizard
6+ *
7+ */
8+ public class Wizard {
9+
10+ private String name;
11+
12+ public Wizard(String name) {
13+ this.name = name;
14+ }
15+
16+ @Override
17+ public String toString() {
18+ return name;
19+ }
20+
21+ }
Original file line number Diff line number Diff line change 1- package com.iluwatar.proxy;
2-
3- /**
4- *
5- * The proxy controlling access to WizardTower.
6- *
7- */
8- public class WizardTowerProxy extends WizardTower {
9-
10- private static final int NUM_WIZARDS_ALLOWED = 3;
11-
12- private int numWizards;
13-
14- @Override
15- public void enter(Wizard wizard) {
16- if (numWizards < NUM_WIZARDS_ALLOWED) {
17- super.enter(wizard);
18- numWizards++;
19- } else {
20- System.out.println(wizard + " is not allowed to enter!");
21- }
22- }
23- }
1+ package com.iluwatar.proxy;
2+
3+ /**
4+ *
5+ * The proxy controlling access to the {@link WizardTower}.
6+ *
7+ */
8+ public class WizardTowerProxy extends WizardTower {
9+
10+ private static final int NUM_WIZARDS_ALLOWED = 3;
11+
12+ private int numWizards;
13+
14+ @Override
15+ public void enter(Wizard wizard) {
16+ if (numWizards < NUM_WIZARDS_ALLOWED) {
17+ super.enter(wizard);
18+ numWizards++;
19+ } else {
20+ System.out.println(wizard + " is not allowed to enter!");
21+ }
22+ }
23+ }
Original file line number Diff line number Diff line change 1- package com.iluwatar.proxy;
2-
3- import org.junit.Test;
4-
5- import com.iluwatar.proxy.App;
6-
7- public class AppTest {
8-
9- @Test
10- public void test() {
11- String[] args = {};
12- App.main(args);
13- }
14- }
1+ package com.iluwatar.proxy;
2+
3+ import org.junit.Test;
4+
5+ import com.iluwatar.proxy.App;
6+
7+ /**
8+ *
9+ * Application test
10+ *
11+ */
12+ public class AppTest {
13+
14+ @Test
15+ public void test() {
16+ String[] args = {};
17+ App.main(args);
18+ }
19+ }
You can’t perform that action at this time.
0 commit comments