rules.java
来自「jsf example about book manager」· Java 代码 · 共 67 行
JAVA
67 行
package com.mycompany.expense;
/**
* This class contains methods encoding the rules for how a
* report in the sample expense report application may be
* handled by the current user.
*
* @author Hans Bergsten, Gefion Software <hans@gefionsoftware.com>
* @version 1.0
*/
public class Rules {
/**
* Returns "true" if the user is the report owner and the report
* isn't locked.
*/
public boolean canEdit(String user, boolean isManager, Report report) {
return report.getOwner().equals(user) && !isLocked(report);
}
/**
* Returns "true" if the user is the report owner and the report
* isn't locked.
*/
public boolean canDelete(String user, boolean isManager, Report report) {
return report.getOwner().equals(user) && !isLocked(report);
}
/**
* Returns "true" if the user is the report owner and the report
* isn't locked.
*/
public boolean canSubmit(String user, boolean isManager, Report report) {
return report.getOwner().equals(user) && !isLocked(report);
}
/**
* Returns "true" if the user is a manager and the report is
* "submitted".
*/
public boolean canAccept(String user, boolean isManager, Report report) {
return isManager && report.getStatus() == Report.STATUS_SUBMITTED;
}
/**
* Returns "true" if the user is a manager and the report is
* "submitted".
*/
public boolean canReject(String user, boolean isManager, Report report) {
return isManager && report.getStatus() == Report.STATUS_SUBMITTED;
}
/**
* Returns "true" if the user is a manager or the report owner.
*/
public boolean canView(String user, boolean isManager, Report report) {
return isManager || report.getOwner().equals(user);
}
/**
* Returns "true" if the report is either "submitted" or "accepted".
*/
public boolean isLocked(Report report) {
return report.getStatus() == Report.STATUS_SUBMITTED ||
report.getStatus() == Report.STATUS_ACCEPTED;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?