Formatted all files to the same standard
This commit is contained in:
		@@ -1,21 +1,22 @@
 | 
			
		||||
package com.iluwatar;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 *
 | 
			
		||||
 * 
 | 
			
		||||
 * Chain of Responsibility organizes request handlers (RequestHandler) into a
 | 
			
		||||
 * chain where each handler has a chance to act on the request on its turn. In
 | 
			
		||||
 * this example the king (OrcKing) makes requests and the military orcs
 | 
			
		||||
 * (OrcCommander, OrcOfficer, OrcSoldier) form the handler chain.
 | 
			
		||||
 *
 | 
			
		||||
 * 
 | 
			
		||||
 */
 | 
			
		||||
public class App {
 | 
			
		||||
 | 
			
		||||
    public static void main(String[] args) {
 | 
			
		||||
	public static void main(String[] args) {
 | 
			
		||||
 | 
			
		||||
        OrcKing king = new OrcKing();
 | 
			
		||||
        king.makeRequest(new Request(RequestType.DEFEND_CASTLE, "defend castle"));
 | 
			
		||||
        king.makeRequest(new Request(RequestType.TORTURE_PRISONER, "torture prisoner"));
 | 
			
		||||
        king.makeRequest(new Request(RequestType.COLLECT_TAX, "collect tax"));
 | 
			
		||||
		OrcKing king = new OrcKing();
 | 
			
		||||
		king.makeRequest(new Request(RequestType.DEFEND_CASTLE, "defend castle"));
 | 
			
		||||
		king.makeRequest(new Request(RequestType.TORTURE_PRISONER,
 | 
			
		||||
				"torture prisoner"));
 | 
			
		||||
		king.makeRequest(new Request(RequestType.COLLECT_TAX, "collect tax"));
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -5,7 +5,7 @@ public class OrcCommander extends RequestHandler {
 | 
			
		||||
	public OrcCommander(RequestHandler handler) {
 | 
			
		||||
		super(handler);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public void handleRequest(Request req) {
 | 
			
		||||
		if (req.getRequestType().equals(RequestType.DEFEND_CASTLE)) {
 | 
			
		||||
 
 | 
			
		||||
@@ -3,22 +3,22 @@ package com.iluwatar;
 | 
			
		||||
/**
 | 
			
		||||
 * 
 | 
			
		||||
 * Makes requests that are handled by the chain.
 | 
			
		||||
 *
 | 
			
		||||
 * 
 | 
			
		||||
 */
 | 
			
		||||
public class OrcKing {
 | 
			
		||||
 | 
			
		||||
	RequestHandler chain;
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
	public OrcKing() {
 | 
			
		||||
		buildChain();
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
	private void buildChain() {
 | 
			
		||||
		chain = new OrcCommander(new OrcOfficer(new OrcSoldier(null)));
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
	public void makeRequest(Request req) {
 | 
			
		||||
		chain.handleRequest(req);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -5,7 +5,7 @@ public class OrcOfficer extends RequestHandler {
 | 
			
		||||
	public OrcOfficer(RequestHandler handler) {
 | 
			
		||||
		super(handler);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public void handleRequest(Request req) {
 | 
			
		||||
		if (req.getRequestType().equals(RequestType.TORTURE_PRISONER)) {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,13 +1,13 @@
 | 
			
		||||
package com.iluwatar;
 | 
			
		||||
 | 
			
		||||
public abstract class RequestHandler {
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
	private RequestHandler next;
 | 
			
		||||
 | 
			
		||||
	public RequestHandler(RequestHandler next) {
 | 
			
		||||
		this.next = next;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
	public void handleRequest(Request req) {
 | 
			
		||||
		if (next != null) {
 | 
			
		||||
			next.handleRequest(req);
 | 
			
		||||
 
 | 
			
		||||
@@ -2,8 +2,6 @@ package com.iluwatar;
 | 
			
		||||
 | 
			
		||||
public enum RequestType {
 | 
			
		||||
 | 
			
		||||
	DEFEND_CASTLE,
 | 
			
		||||
	TORTURE_PRISONER,
 | 
			
		||||
	COLLECT_TAX
 | 
			
		||||
	
 | 
			
		||||
	DEFEND_CASTLE, TORTURE_PRISONER, COLLECT_TAX
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user