exclude patterns:
开始申请休假3天。
Mia组长开始审批,休假3天
休假3天申请结果: Mia组长已批准你的3天休假申请。
开始申请休假6天。
Mia组长开始审批,休假6天
6天休假申请超出Mia组长的审批权限
Morgen项目经理开始审批,休假6天
休假6天申请结果: Morgen项目经理已批准你的6天休假申请。
开始申请休假21天。
Mia组长开始审批,休假21天
21天休假申请超出Mia组长的审批权限
Morgen项目经理开始审批,休假21天
21天休假申请超出Morgen项目经理的审批权限
Andrea总监开始审批,休假21天
休假21天申请结果: Andrea总监已批准你的21天休假申请。
开始申请休假32天。
Mia组长开始审批,休假32天
32天休假申请超出Mia组长的审批权限
Morgen项目经理开始审批,休假32天
32天休假申请超出Morgen项目经理的审批权限
Andrea总监开始审批,休假32天
32天休假申请超出Andrea总监的审批权限
Cyra副总裁开始审批,休假32天
休假32天申请结果: Cyra副总裁已批准你的32天休假申请。
开始申请休假108天。
Mia组长开始审批,休假108天
108天休假申请超出Mia组长的审批权限
Morgen项目经理开始审批,休假108天
108天休假申请超出Morgen项目经理的审批权限
Andrea总监开始审批,休假108天
108天休假申请超出Andrea总监的审批权限
Cyra副总裁开始审批,休假108天
108天休假申请超出Cyra副总裁的审批权限
Iris大老板开始审批,休假108天
休假108天申请结果: Iris老板已欣然同意你的108天休假申请,并慷慨特批无限期延长假期,工资同理!
开始申请休假367天。
Mia组长开始审批,休假367天
367天休假申请超出Mia组长的审批权限
Morgen项目经理开始审批,休假367天
367天休假申请超出Morgen项目经理的审批权限
Andrea总监开始审批,休假367天
367天休假申请超出Andrea总监的审批权限
Cyra副总裁开始审批,休假367天
367天休假申请超出Cyra副总裁的审批权限
Iris大老板开始审批,休假367天
index=5, interceptors.size=5
休假367天申请结果: 抱歉!没有这样的老板能批的了你367的假期,请尝试其它BOSS......
Class transformation time: 0.016466353s for 116 classes or 1.4195131896551724E-4s per class
Process finished with exit code 0
package com.windfallsheng.myresponsibilitychain;
import java.util.ArrayList;
import java.util.List;
class Client {
public static void main(String[] args) {
Client client = new Client();
final List<Interceptor> interceptors = client.initInterceptor();
System.out.println("\t" + "开始申请休假" + 3 + "天。");
String day3 = client.getInterceptorChain(interceptors, 3);
System.out.println("\t" + "休假3天申请结果:" + day3 + "\n");
System.out.println("\t" + "开始申请休假" + 6 + "天。");
String day6 = client.getInterceptorChain(interceptors, 6);
System.out.println("\t" + "休假6天申请结果:" + day6 + "\n");
System.out.println("\t" + "开始申请休假" + 21 + "天。");
String day21 = client.getInterceptorChain(interceptors, 21);
System.out.println("\t" + "休假21天申请结果:" + day21 + "\n");
System.out.println("\t" + "开始申请休假" + 32 + "天。");
String day32 = client.getInterceptorChain(interceptors, 32);
System.out.println("\t" + "休假32天申请结果:" + day32 + "\n");
System.out.println("\t" + "开始申请休假" + 108 + "天。");
String day108 = client.getInterceptorChain(interceptors, 108);
System.out.println("\t" + "休假108天申请结果:" + day108 + "\n");
System.out.println("\t" + "开始申请休假" + 367 + "天。");
String day367 = client.getInterceptorChain(interceptors, 367);
System.out.println("\t" + "休假367天申请结果:" + day367 + "\n");
}
private List<Interceptor> initInterceptor() {
List<Interceptor> interceptors = new ArrayList<>();
interceptors.add(new GroupLeaderInterceptor("Mia"));
interceptors.add(new ProjectManagerInterceptor("Morgen"));
interceptors.add(new DirectorInterceptor("Andrea"));
interceptors.add(new VicePresidentInterceptor("Cyra"));
interceptors.add(new BossInterceptor("Iris"));
return interceptors;
}
private String getInterceptorChain(List<Interceptor> interceptors, int days) {
Interceptor.Chain chain = new RealInterceptorChain(
interceptors, 0, days);
return chain.proceed(days);
}
}
package com.windfallsheng.myresponsibilitychain;
interface Interceptor {
String intercept(Chain chain);
interface Chain {
String proceed(int days);
}
}
package com.windfallsheng.myresponsibilitychain;
import java.util.List;
class RealInterceptorChain implements Interceptor.Chain {
private final List<Interceptor> interceptors;
private final int index;
/**
* 休假天数
*/
private final int days;
public RealInterceptorChain(List<Interceptor> interceptors, int index, int days) {
this.interceptors = interceptors;
this.index = index;
this.days = days;
}
@Override
public String proceed(int days) {
if (index >= interceptors.size()) {
System.out.println("\t" + "index=" + index + ", interceptors.size=" + interceptors.size());
return "\t" + "抱歉!没有这样的老板能批的了你" + days + "的假期,请尝试其它BOSS......";
}
RealInterceptorChain next = new RealInterceptorChain(
interceptors, index + 1, days);
Interceptor interceptor = interceptors.get(index);
String result = interceptor.intercept(next);
return result;
}
public int request() {
return days;
}
}
package com.windfallsheng.myresponsibilitychain;
/**
* 组长
*/
class GroupLeaderInterceptor implements Interceptor {
private String name;
public GroupLeaderInterceptor(String name) {
this.name = name;
}
@Override
public String intercept(Chain chain) {
RealInterceptorChain realChain = (RealInterceptorChain) chain;
int days = realChain.request();
System.out.println("\t" + name + "组长开始审批,休假" + days + "天");
if (days > 3) {
System.out.println("\t" + days + "天休假申请超出" + name + "组长的审批权限");
} else {
return "\t" + name + "组长已批准你的" + days + "天休假申请。";
}
return realChain.proceed(days);
}
}
package com.windfallsheng.myresponsibilitychain;
/**
* 项目经理
*/
class ProjectManagerInterceptor implements Interceptor {
private String name;
public ProjectManagerInterceptor(String name) {
this.name = name;
}
@Override
public String intercept(Chain chain) {
RealInterceptorChain realChain = (RealInterceptorChain) chain;
int days = realChain.request();
System.out.println("\t" + name + "项目经理开始审批,休假" + days + "天");
if (days > 7) {
System.out.println("\t" + days + "天休假申请超出" + name + "项目经理的审批权限");
} else {
return "\t" + name + "项目经理已批准你的" + days + "天休假申请。";
}
return realChain.proceed(days);
}
}
package com.windfallsheng.myresponsibilitychain;
/**
* 总监
*/
class DirectorInterceptor implements Interceptor {
private String name;
public DirectorInterceptor(String name) {
this.name = name;
}
@Override
public String intercept(Chain chain) {
RealInterceptorChain realChain = (RealInterceptorChain) chain;
int days = realChain.request();
System.out.println("\t" + name + "总监开始审批,休假" + days + "天");
if (days > 30) {
System.out.println("\t" + days + "天休假申请超出" + name + "总监的审批权限");
} else {
return "\t" + name + "总监已批准你的" + days + "天休假申请。";
}
return realChain.proceed(days);
}
}
package com.windfallsheng.myresponsibilitychain;
/**
* 副总裁
*/
class VicePresidentInterceptor implements Interceptor {
private String name;
public VicePresidentInterceptor(String name) {
this.name = name;
}
@Override
public String intercept(Chain chain) {
RealInterceptorChain realChain = (RealInterceptorChain) chain;
int days = realChain.request();
System.out.println("\t" + name + "副总裁开始审批,休假" + days + "天");
if (days > 90) {
System.out.println("\t" + days + "天休假申请超出" + name + "副总裁的审批权限");
} else {
return "\t" + name + "副总裁已批准你的" + days + "天休假申请。";
}
return realChain.proceed(days);
}
}
package com.windfallsheng.myresponsibilitychain;
/**
* 大老板
*/
class BossInterceptor implements Interceptor {
private String name;
public BossInterceptor(String name) {
this.name = name;
}
@Override
public String intercept(Chain chain) {
RealInterceptorChain realChain = (RealInterceptorChain) chain;
int days = realChain.request();
System.out.println("\t" + name + "大老板开始审批,休假" + days + "天");
if (days >= 90 && days < 365) {
return "\t" + name + "老板已欣然同意你的" + days + "天休假申请,并慷慨特批无限期延长假期,工资同理!";
}
return realChain.proceed(days);
}
}
源码下载地址:优快云