Formatted all files to the same standard

This commit is contained in:
matthew
2014-10-08 13:42:12 +01:00
parent 53a2a8b150
commit 3da9ad5469
151 changed files with 952 additions and 870 deletions

View File

@ -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"));
}
}
}

View File

@ -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)) {

View File

@ -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);
}
}

View File

@ -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)) {

View File

@ -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);

View File

@ -2,8 +2,6 @@ package com.iluwatar;
public enum RequestType {
DEFEND_CASTLE,
TORTURE_PRISONER,
COLLECT_TAX
DEFEND_CASTLE, TORTURE_PRISONER, COLLECT_TAX
}