#107 JavaDoc for Proxy example
This commit is contained in:
		| @@ -1,20 +1,20 @@ | ||||
| package com.iluwatar.proxy; | ||||
|  | ||||
| /** | ||||
|  *  | ||||
|  * Proxy (WizardTowerProxy) controls access to the actual object (WizardTower). | ||||
|  *  | ||||
|  */ | ||||
| public class App { | ||||
|  | ||||
| 	public static void main(String[] args) { | ||||
|  | ||||
| 		WizardTowerProxy tower = new WizardTowerProxy(); | ||||
| 		tower.enter(new Wizard("Red wizard")); | ||||
| 		tower.enter(new Wizard("White wizard")); | ||||
| 		tower.enter(new Wizard("Black wizard")); | ||||
| 		tower.enter(new Wizard("Green wizard")); | ||||
| 		tower.enter(new Wizard("Brown wizard")); | ||||
|  | ||||
| 	} | ||||
| } | ||||
| package com.iluwatar.proxy; | ||||
|  | ||||
| /** | ||||
|  *  | ||||
|  * Proxy ({@link WizardTowerProxy}) controls access to the actual object ({@link WizardTower}). | ||||
|  *  | ||||
|  */ | ||||
| public class App { | ||||
|  | ||||
| 	public static void main(String[] args) { | ||||
|  | ||||
| 		WizardTowerProxy tower = new WizardTowerProxy(); | ||||
| 		tower.enter(new Wizard("Red wizard")); | ||||
| 		tower.enter(new Wizard("White wizard")); | ||||
| 		tower.enter(new Wizard("Black wizard")); | ||||
| 		tower.enter(new Wizard("Green wizard")); | ||||
| 		tower.enter(new Wizard("Brown wizard")); | ||||
|  | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -1,16 +1,21 @@ | ||||
| package com.iluwatar.proxy; | ||||
|  | ||||
| public class Wizard { | ||||
|  | ||||
| 	private String name; | ||||
|  | ||||
| 	public Wizard(String name) { | ||||
| 		this.name = name; | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public String toString() { | ||||
| 		return name; | ||||
| 	} | ||||
|  | ||||
| } | ||||
| package com.iluwatar.proxy; | ||||
|  | ||||
| /** | ||||
|  *  | ||||
|  * Wizard | ||||
|  * | ||||
|  */ | ||||
| public class Wizard { | ||||
|  | ||||
| 	private String name; | ||||
|  | ||||
| 	public Wizard(String name) { | ||||
| 		this.name = name; | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public String toString() { | ||||
| 		return name; | ||||
| 	} | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -1,23 +1,23 @@ | ||||
| package com.iluwatar.proxy; | ||||
|  | ||||
| /** | ||||
|  *  | ||||
|  * The proxy controlling access to WizardTower. | ||||
|  *  | ||||
|  */ | ||||
| public class WizardTowerProxy extends WizardTower { | ||||
|  | ||||
| 	private static final int NUM_WIZARDS_ALLOWED = 3; | ||||
|  | ||||
| 	private int numWizards; | ||||
|  | ||||
| 	@Override | ||||
| 	public void enter(Wizard wizard) { | ||||
| 		if (numWizards < NUM_WIZARDS_ALLOWED) { | ||||
| 			super.enter(wizard); | ||||
| 			numWizards++; | ||||
| 		} else { | ||||
| 			System.out.println(wizard + " is not allowed to enter!"); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| package com.iluwatar.proxy; | ||||
|  | ||||
| /** | ||||
|  *  | ||||
|  * The proxy controlling access to the {@link WizardTower}. | ||||
|  *  | ||||
|  */ | ||||
| public class WizardTowerProxy extends WizardTower { | ||||
|  | ||||
| 	private static final int NUM_WIZARDS_ALLOWED = 3; | ||||
|  | ||||
| 	private int numWizards; | ||||
|  | ||||
| 	@Override | ||||
| 	public void enter(Wizard wizard) { | ||||
| 		if (numWizards < NUM_WIZARDS_ALLOWED) { | ||||
| 			super.enter(wizard); | ||||
| 			numWizards++; | ||||
| 		} else { | ||||
| 			System.out.println(wizard + " is not allowed to enter!"); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -1,14 +1,19 @@ | ||||
| package com.iluwatar.proxy; | ||||
|  | ||||
| import org.junit.Test; | ||||
|  | ||||
| import com.iluwatar.proxy.App; | ||||
|  | ||||
| public class AppTest { | ||||
|  | ||||
| 	@Test | ||||
| 	public void test() { | ||||
| 		String[] args = {}; | ||||
| 		App.main(args); | ||||
| 	} | ||||
| } | ||||
| package com.iluwatar.proxy; | ||||
|  | ||||
| import org.junit.Test; | ||||
|  | ||||
| import com.iluwatar.proxy.App; | ||||
|  | ||||
| /** | ||||
|  *  | ||||
|  * Application test | ||||
|  * | ||||
|  */ | ||||
| public class AppTest { | ||||
|  | ||||
| 	@Test | ||||
| 	public void test() { | ||||
| 		String[] args = {}; | ||||
| 		App.main(args); | ||||
| 	} | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user