Coverage Report - org.kuali.rice.core.api.criteria.CriteriaDateTimeValue
 
Classes in this File Line Coverage Branch Coverage Complexity
CriteriaDateTimeValue
82%
19/23
50%
3/6
1.5
CriteriaDateTimeValue$Constants
0%
0/1
N/A
1.5
 
 1  
 /*
 2  
  * Copyright 2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 1.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.opensource.org/licenses/ecl1.php
 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  
 package org.kuali.rice.core.api.criteria;
 17  
 
 18  
 import java.util.Calendar;
 19  
 import java.util.Date;
 20  
 
 21  
 import javax.xml.bind.annotation.XmlAccessType;
 22  
 import javax.xml.bind.annotation.XmlAccessorType;
 23  
 import javax.xml.bind.annotation.XmlRootElement;
 24  
 import javax.xml.bind.annotation.XmlType;
 25  
 import javax.xml.bind.annotation.XmlValue;
 26  
 
 27  
 import org.apache.commons.lang.builder.HashCodeBuilder;
 28  
 import org.apache.commons.lang.builder.ToStringBuilder;
 29  
 
 30  
 /**
 31  
  * A CriteriaValue which stores date and time information in the form of a
 32  
  * {@link Calendar} value.
 33  
  * 
 34  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 35  
  *
 36  
  */
 37  2
 @XmlRootElement(name = CriteriaDateTimeValue.Constants.ROOT_ELEMENT_NAME)
 38  
 @XmlAccessorType(XmlAccessType.NONE)
 39  
 @XmlType(name = CriteriaDateTimeValue.Constants.TYPE_NAME)
 40  
 public final class CriteriaDateTimeValue implements CriteriaValue<Calendar> {
 41  
 
 42  
     @XmlValue
 43  
     private final Calendar value;
 44  
     
 45  16
     CriteriaDateTimeValue() {
 46  16
         this.value = null;
 47  16
     }
 48  
     
 49  21
     CriteriaDateTimeValue(Calendar value) {
 50  21
             validateValue(value);
 51  21
         this.value = value;
 52  21
     }
 53  
     
 54  7
     CriteriaDateTimeValue(Date value) {
 55  7
             validateValue(value);
 56  7
             Calendar calendar = Calendar.getInstance();
 57  7
         calendar.setTimeInMillis(value.getTime());
 58  7
         this.value = calendar;
 59  7
     }
 60  
     
 61  
     private static void validateValue(Object value) {
 62  28
             if (value == null) {
 63  0
                     throw new IllegalArgumentException("Value cannot be null.");
 64  
             }
 65  28
     }
 66  
     
 67  
     @Override
 68  
     public Calendar getValue() {
 69  2
         return value;
 70  
     }
 71  
     
 72  
     @Override
 73  
     public int hashCode() {
 74  0
         return HashCodeBuilder.reflectionHashCode(this);
 75  
     }
 76  
 
 77  
     /**
 78  
      * Two CriteriaDateTimeValues are equal if they have the same epoch value (Calendar.getTimeInMillis())
 79  
      * 
 80  
      * @see java.lang.Object#equals(java.lang.Object)
 81  
      */
 82  
     @Override
 83  
     public boolean equals(Object obj) {
 84  18
             if (obj instanceof CriteriaDateTimeValue) {
 85  18
                     return value.getTimeInMillis() == ((CriteriaDateTimeValue)obj).value.getTimeInMillis();
 86  
             }
 87  0
         return false;
 88  
     }
 89  
 
 90  
     @Override
 91  
     public String toString() {
 92  0
         return ToStringBuilder.reflectionToString(this);
 93  
     }
 94  
     
 95  
     /**
 96  
      * Defines some internal constants used on this class.
 97  
      */
 98  0
     static class Constants {
 99  
         final static String ROOT_ELEMENT_NAME = "dateTimeValue";
 100  
         final static String TYPE_NAME = "CriteriaDateTimeValueType";
 101  
     }
 102  
     
 103  
 }