java 位运算 多个状态_位运算表示对象所处状态
通過一個integer類型屬性來表示對象所處的狀態:
CASE:
Invitor:邀請者對象模型
Integer Invitor.joinstatus:邀請者所處參加狀態
當前存在狀態聲明:是否被邀請,是否注冊用戶,是否拒絕,是否審批
設計思路:
bit0: 1-invited? , 0-not invited
bit1: 1-registed , 0-not registed
bit2: 1-refused? , 0-not refused
bit3: 1-approved , 0-not approved
Example:0111(7)=the invitor is invited ,and is registed ,and has been refused without approved.
//判斷joinstatus狀態
public static String theStatusOfApplicant(Invitor iv) throws TrainingAppException {
String status = "default";
if (((iv.getJoinStatus() & 0x8) == 0) && ((iv.getJoinStatus() & 0x4) == 0)) {
status = "default";// 待批準(0x0)
}
if (((iv.getJoinStatus() & 0x8) == 0x8) && ((iv.getJoinStatus() & 0x4) == 0)) {
status = "approved";// 已審批(0x4)
}
if (((iv.getJoinStatus() & 0x4) > 0) && ((iv.getJoinStatus() & 0x8) == 0)) {
status = "refused";// 已拒絕(0x8)
}
return status;
}
//更新joinstatus狀態(審批和拒絕為互斥)
private void updateJoinstatus(MainTrainingInfo mtrInfo, List invitors, Integer opertorType) {
for (Iterator it = invitors.iterator(); it.hasNext();) {
Invitor iv = (Invitor) it.next();
if (APPLY_OPERTORTYPE_APPROVE == opertorType.intValue()) { // approve
iv.setJoinStatus((iv.getJoinStatus() | 0x8) & 0x8);
} else {
iv.setJoinStatus((iv.getJoinStatus() | 0x4) & 0x4); // refuse
}
iv.setMainId(mtrInfo);
mtrInfo.getInvitor().add(iv);
}
persistence.update(mtrInfo);
if (APPLY_OPERTORTYPE_APPROVE == opertorType.intValue()) { // approve
log.info(" ### 申請已獲批準,發送邀請郵件.");
// Send Mails.
try {
instanceMailSendService.approveInvitorSendMail(mtrInfo, invitors, getHostEmail(mtrInfo),
MainTrainingInfoUtil.getLocale(mtrInfo), true, true);
} catch (Exception e) {
log.error(e.toString());
}
}
}
總結
以上是生活随笔為你收集整理的java 位运算 多个状态_位运算表示对象所处状态的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 子宫腺肌症能够怀孕吗
- 下一篇: 鬼谷子的作者是谁啊?