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 org.springmodules.validation.util.condition.date.AbstractDateCondition} implementation that checks 26 * whether the checked calendar is chronologically before a specific calendar. 27 * 28 * @author Uri Boness 29 */ 30 public class IsBeforeDateCondition extends AbstractDateCondition { 31 32 private Calendar later; 33 34 /** 35 * Constructs a new IsBeforeDateCondition with a given date to be compared with the checked calendar. 36 * 37 * @param later The date to be compared with the checked calendar. 38 */ 39 public IsBeforeDateCondition(Date later) { 40 Assert.notNull(later, "IsBeforeDateCondition cannot be initialized with a null date"); 41 this.later = Calendar.getInstance(); 42 this.later.setTime(later); 43 } 44 45 /** 46 * Constructs a new IsBeforeDateCondition with a given calendar to be compared with the checked calendar. 47 * 48 * @param later The calendar to be compared with the checked calendar. 49 */ 50 public IsBeforeDateCondition(Calendar later) { 51 Assert.notNull(later, "IsBeforeDateCondition cannot be initialized with a null calendar"); 52 this.later = later; 53 } 54 55 /** 56 * Checks whether the given calendar is chornologically before 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 before the calendar associated with this condition, 60 * <code>false</code> otherwise. 61 */ 62 protected boolean checkCalendar(Calendar calendar) { 63 return later.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 getLater() { 74 return later; 75 } 76 77 }