Java tutorial
/* * Copyright 2011-2016 ZuoBian.com All right reserved. This software is the confidential and proprietary information of * ZuoBian.com ("Confidential Information"). You shall not disclose such Confidential Information and shall use it only * in accordance with the terms of the license agreement you entered into with ZuoBian.com. */ package com.mmj.app.lucene.search.cons; import java.util.Date; import org.apache.commons.lang.StringUtils; import com.mmj.app.common.util.DateViewTools; /** * time: all 1d24? 3d 7d 30d 365d * * @author zxc Dec 10, 2014 11:25:22 AM */ public enum TimeSearchEnum { /** * */ ALL(0, "all", "", null), /** * 24? */ D1(1, "1d", "", DateViewTools.yesterDate()), /** * */ D3(2, "3d", "", DateViewTools.getDateBefore(3)), /** * */ D7(2, "7d", "", DateViewTools.getDateBefore(7)), /** * */ D30(2, "30d", "", DateViewTools.getDateBefore(30)), /** * */ D365(2, "365d", "", DateViewTools.getDateBefore(365)); private int value; private String name; private String desc; private Date startTime; private TimeSearchEnum(int value, String name, String desc, Date startTime) { this.value = value; this.name = name; this.desc = desc; this.startTime = startTime; } public String getDesc() { return desc; } public int getValue() { return value; } public String getName() { return name; } public Date getStartTime() { return startTime; } public Long getStartTimeLong() { return startTime == null ? null : startTime.getTime(); } /** * ?name? */ public static TimeSearchEnum getEnum(String name) { if (StringUtils.isEmpty(name)) { return ALL; } for (TimeSearchEnum current : values()) { if (StringUtils.equalsIgnoreCase(current.getName(), name)) { return current; } } return ALL; } /** * ?value? */ public static TimeSearchEnum getEnum(Integer value) { if (value == null) { return ALL; } for (TimeSearchEnum current : values()) { if (current.value == value) { return current; } } return ALL; } }