001 /* 002 * Sonar, open source software quality management tool. 003 * Copyright (C) 2008-2012 SonarSource 004 * mailto:contact AT sonarsource DOT com 005 * 006 * Sonar is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 3 of the License, or (at your option) any later version. 010 * 011 * Sonar is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public 017 * License along with Sonar; if not, write to the Free Software 018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 019 */ 020 package org.sonar.server.filters; 021 022 import org.apache.commons.lang.builder.ToStringBuilder; 023 import org.apache.commons.lang.builder.ToStringStyle; 024 import org.apache.commons.lang.time.DateUtils; 025 026 import java.util.Calendar; 027 import java.util.Date; 028 029 public class DateCriterion { 030 031 private String operator; 032 private Date date; 033 034 public DateCriterion(String operator, Date date) { 035 this.operator = operator; 036 this.date = date; 037 } 038 039 public DateCriterion() { 040 } 041 042 public String getOperator() { 043 return operator; 044 } 045 046 public DateCriterion setOperator(String operator) { 047 this.operator = operator; 048 return this; 049 } 050 051 public Date getDate() { 052 return date; 053 } 054 055 public DateCriterion setDate(Date date) { 056 this.date = date; 057 return this; 058 } 059 060 public DateCriterion setDate(int daysAgo) { 061 this.date = DateUtils.addDays(new Date(), -daysAgo); 062 this.date = DateUtils.truncate(this.date, Calendar.DATE); 063 return this; 064 } 065 066 @Override 067 public String toString() { 068 return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) 069 .append("operator", operator) 070 .append("date", date) 071 .toString(); 072 } 073 }