1 /* 2 * Copyright 2004-2009 the original author or authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package org.springmodules.validation.util.condition.date; 18 19 import java.util.Calendar; 20 import java.util.Date; 21 22 import org.springframework.util.Assert; 23 24 /** 25 * An {@link AbstractDateCondition} implementation that checks whether the checked calendar is chronologically after 26 * a specific calendar. 27 * 28 * @author Uri Boness 29 */ 30 public class IsAfterDateCondition extends AbstractDateCondition { 31 32 private Calendar earlier; 33 34 /** 35 * Constructs a new IsAfterDateCondition with a given date to be compared with the checked calendar. 36 * 37 * @param earlier The date to be compared with the checked calendar. 38 */ 39 public IsAfterDateCondition(Date earlier) { 40 Assert.notNull(earlier, "IsAfterDateCondition cannot be initialized with a null date"); 41 this.earlier = Calendar.getInstance(); 42 this.earlier.setTime(earlier); 43 } 44 45 /** 46 * Constructs a new IsAfterDateCondition with a given calendar to be compared with the checked calendar. 47 * 48 * @param earlier The calendar to be compared with the checked calendar. 49 */ 50 public IsAfterDateCondition(Calendar earlier) { 51 Assert.notNull(earlier, "IsAfterDateCondition cannot be initialized with a null calendar"); 52 this.earlier = earlier; 53 } 54 55 /** 56 * Checks whether the given calendar is chornologically after the calendar associated with this condition. 57 * 58 * @param calendar The calendar to be checked. 59 * @return <code>true</code> if the given calender comes after the calendar associated with this condition, 60 * <code>false</code> otherwise. 61 */ 62 protected boolean checkCalendar(Calendar calendar) { 63 return earlier.getTimeInMillis() < calendar.getTimeInMillis(); 64 } 65 66 //=============================================== Setter/Getter ==================================================== 67 68 /** 69 * Returns the calendar associated with this condition. 70 * 71 * @return The calendar associated with this condition. 72 */ 73 public Calendar getEarlier() { 74 return earlier; 75 } 76 77 }