今天看公司代码的时候,看到一个自己之前遗忘的知识点。
1. java里面虽然不提供go-to语句,但是使用label: 配合break可以实现这个功能。break主要用于控制跳出指定label代码块。
2. 可以直接使用Date自带方法来进行时间比较,状态实时计算出来。
3. @JsonFormat 格式化 json返回格式。
下面是这个前辈的代码:
import com.fasterxml.jackson.annotation.JsonFormat;
import java.io.Serializable;
import java.util.Date;
public class ActivityEntity implements Serializable {
private static final long serialVersionUID = 549127479215301040L;
private String aid;
private String title;
private Integer actType;
private Integer userDayPlayCount;
private Integer userTotalPlayCount;
private Integer userDayAwardCount;
private Integer userTotalAwardCount;
private String verificationPass;
@JsonFormat(
pattern = "yyyy-MM-dd HH:mm:ss",
timezone = "GMT+8"
)
private Date startTime;
@JsonFormat(
pattern = "yyyy-MM-dd HH:mm:ss",
timezone = "GMT+8"
)
private Date endTime;
@JsonFormat(
pattern = "yyyy-MM-dd HH:mm:ss",
timezone = "GMT+8"
)
private Date createTime;
private String remark;
public Integer getActivityStatus() {
Date now = new Date();
// 0 活动未开始 1 活动已开始 2 活动已经结束
return this.startTime.after(now)?Integer.valueOf(0):(this.endTime.before(now)?Integer.valueOf(2):Integer.valueOf(1));
}
public boolean isInProgress() {
return 1 == this.getActivityStatus().intValue();
}
public boolean isEnd() {
return 2 == this.getActivityStatus().intValue();
}
public boolean isNotStart() {
return 0 == this.getActivityStatus().intValue();
}
public ActivityEntity() {
}
public String getAid() {
return this.aid;
}
public String getTitle() {
return this.title;
}
public Integer getActType() {
return this.actType;
}
public Integer getUserDayPlayCount() {
return this.userDayPlayCount;
}
public Integer getUserTotalPlayCount() {
return this.userTotalPlayCount;
}
public Integer getUserDayAwardCount() {
return this.userDayAwardCount;
}
public Integer getUserTotalAwardCount() {
return this.userTotalAwardCount;
}
public String getVerificationPass() {
return this.verificationPass;
}
public Date getStartTime() {
return this.startTime;
}
public Date getEndTime() {
return this.endTime;
}
public Date getCreateTime() {
return this.createTime;
}
public String getRemark() {
return this.remark;
}
public void setAid(String aid) {
this.aid = aid;
}
public void setTitle(String title) {
this.title = title;
}
public void setActType(Integer actType) {
this.actType = actType;
}
public void setUserDayPlayCount(Integer userDayPlayCount) {
this.userDayPlayCount = userDayPlayCount;
}
public void setUserTotalPlayCount(Integer userTotalPlayCount) {
this.userTotalPlayCount = userTotalPlayCount;
}
public void setUserDayAwardCount(Integer userDayAwardCount) {
this.userDayAwardCount = userDayAwardCount;
}
public void setUserTotalAwardCount(Integer userTotalAwardCount) {
this.userTotalAwardCount = userTotalAwardCount;
}
public void setVerificationPass(String verificationPass) {
this.verificationPass = verificationPass;
}
public void setStartTime(Date startTime) {
this.startTime = startTime;
}
public void setEndTime(Date endTime) {
this.endTime = endTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public void setRemark(String remark) {
this.remark = remark;
}
public boolean equals(Object o) {
if(o == this) {
return true;
} else if(!(o instanceof ActivityEntity)) {
return false;
} else {
ActivityEntity other = (ActivityEntity)o;
if(!other.canEqual(this)) {
return false;
} else {
label155: {
Object this$aid = this.getAid();
Object other$aid = other.getAid();
if(this$aid == null) {
if(other$aid == null) {
break label155;
}
} else if(this$aid.equals(other$aid)) {
break label155;
}
return false;
}
Object this$title = this.getTitle();
Object other$title = other.getTitle();
if(this$title == null) {
if(other$title != null) {
return false;
}
} else if(!this$title.equals(other$title)) {
return false;
}
Object this$actType = this.getActType();
Object other$actType = other.getActType();
if(this$actType == null) {
if(other$actType != null) {
return false;
}
} else if(!this$actType.equals(other$actType)) {
return false;
}
label134: {
Object this$userDayPlayCount = this.getUserDayPlayCount();
Object other$userDayPlayCount = other.getUserDayPlayCount();
if(this$userDayPlayCount == null) {
if(other$userDayPlayCount == null) {
break label134;
}
} else if(this$userDayPlayCount.equals(other$userDayPlayCount)) {
break label134;
}
return false;
}
label127: {
Object this$userTotalPlayCount = this.getUserTotalPlayCount();
Object other$userTotalPlayCount = other.getUserTotalPlayCount();
if(this$userTotalPlayCount == null) {
if(other$userTotalPlayCount == null) {
break label127;
}
} else if(this$userTotalPlayCount.equals(other$userTotalPlayCount)) {
break label127;
}
return false;
}
label120: {
Object this$userDayAwardCount = this.getUserDayAwardCount();
Object other$userDayAwardCount = other.getUserDayAwardCount();
if(this$userDayAwardCount == null) {
if(other$userDayAwardCount == null) {
break label120;
}
} else if(this$userDayAwardCount.equals(other$userDayAwardCount)) {
break label120;
}
return false;
}
Object this$userTotalAwardCount = this.getUserTotalAwardCount();
Object other$userTotalAwardCount = other.getUserTotalAwardCount();
if(this$userTotalAwardCount == null) {
if(other$userTotalAwardCount != null) {
return false;
}
} else if(!this$userTotalAwardCount.equals(other$userTotalAwardCount)) {
return false;
}
label106: {
Object this$verificationPass = this.getVerificationPass();
Object other$verificationPass = other.getVerificationPass();
if(this$verificationPass == null) {
if(other$verificationPass == null) {
break label106;
}
} else if(this$verificationPass.equals(other$verificationPass)) {
break label106;
}
return false;
}
Object this$startTime = this.getStartTime();
Object other$startTime = other.getStartTime();
if(this$startTime == null) {
if(other$startTime != null) {
return false;
}
} else if(!this$startTime.equals(other$startTime)) {
return false;
}
label92: {
Object this$endTime = this.getEndTime();
Object other$endTime = other.getEndTime();
if(this$endTime == null) {
if(other$endTime == null) {
break label92;
}
} else if(this$endTime.equals(other$endTime)) {
break label92;
}
return false;
}
Object this$createTime = this.getCreateTime();
Object other$createTime = other.getCreateTime();
if(this$createTime == null) {
if(other$createTime != null) {
return false;
}
} else if(!this$createTime.equals(other$createTime)) {
return false;
}
Object this$remark = this.getRemark();
Object other$remark = other.getRemark();
if(this$remark == null) {
if(other$remark != null) {
return false;
}
} else if(!this$remark.equals(other$remark)) {
return false;
}
return true;
}
}
}
protected boolean canEqual(Object other) {
return other instanceof ActivityEntity;
}
public int hashCode() {
int PRIME = true;
int result = 1;
Object $aid = this.getAid();
int result = result * 59 + ($aid == null?0:$aid.hashCode());
Object $title = this.getTitle();
result = result * 59 + ($title == null?0:$title.hashCode());
Object $actType = this.getActType();
result = result * 59 + ($actType == null?0:$actType.hashCode());
Object $userDayPlayCount = this.getUserDayPlayCount();
result = result * 59 + ($userDayPlayCount == null?0:$userDayPlayCount.hashCode());
Object $userTotalPlayCount = this.getUserTotalPlayCount();
result = result * 59 + ($userTotalPlayCount == null?0:$userTotalPlayCount.hashCode());
Object $userDayAwardCount = this.getUserDayAwardCount();
result = result * 59 + ($userDayAwardCount == null?0:$userDayAwardCount.hashCode());
Object $userTotalAwardCount = this.getUserTotalAwardCount();
result = result * 59 + ($userTotalAwardCount == null?0:$userTotalAwardCount.hashCode());
Object $verificationPass = this.getVerificationPass();
result = result * 59 + ($verificationPass == null?0:$verificationPass.hashCode());
Object $startTime = this.getStartTime();
result = result * 59 + ($startTime == null?0:$startTime.hashCode());
Object $endTime = this.getEndTime();
result = result * 59 + ($endTime == null?0:$endTime.hashCode());
Object $createTime = this.getCreateTime();
result = result * 59 + ($createTime == null?0:$createTime.hashCode());
Object $remark = this.getRemark();
result = result * 59 + ($remark == null?0:$remark.hashCode());
return result;
}
public String toString() {
return "ActivityEntity(aid=" + this.getAid() + ", title=" + this.getTitle() + ", actType=" + this.getActType() + ", userDayPlayCount=" + this.getUserDayPlayCount() + ", userTotalPlayCount=" + this.getUserTotalPlayCount() + ", userDayAwardCount=" + this.getUserDayAwardCount() + ", userTotalAwardCount=" + this.getUserTotalAwardCount() + ", verificationPass=" + this.getVerificationPass() + ", startTime=" + this.getStartTime() + ", endTime=" + this.getEndTime() + ", createTime=" + this.getCreateTime() + ", remark=" + this.getRemark() + ")";
}
}