Coverage Report - org.kuali.rice.core.api.criteria.CriteriaDateTimeValue
 
Classes in this File Line Coverage Branch Coverage Complexity
CriteriaDateTimeValue
90%
19/21
50%
1/2
1.25
CriteriaDateTimeValue$Constants
0%
0/1
N/A
1.25
 
 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 org.apache.commons.lang.builder.ToStringBuilder;
 19  
 import org.kuali.rice.core.util.EqualsAndHashCodeUtils;
 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  
 import java.util.Calendar;
 27  
 import java.util.Date;
 28  
 
 29  
 /**
 30  
  * A CriteriaValue which stores date and time information in the form of a
 31  
  * {@link Calendar} value.
 32  
  * 
 33  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 34  
  *
 35  
  */
 36  2
 @XmlRootElement(name = CriteriaDateTimeValue.Constants.ROOT_ELEMENT_NAME)
 37  
 @XmlAccessorType(XmlAccessType.NONE)
 38  
 @XmlType(name = CriteriaDateTimeValue.Constants.TYPE_NAME)
 39  
 public final class CriteriaDateTimeValue implements CriteriaValue<Calendar> {
 40  
 
 41  
     @XmlValue
 42  
     private final Calendar value;
 43  
     
 44  17
     CriteriaDateTimeValue() {
 45  17
         this.value = null;
 46  17
     }
 47  
     
 48  22
     CriteriaDateTimeValue(Calendar value) {
 49  22
             validateValue(value);
 50  
         //defensive copy incoming calendar - keeps things immutable
 51  22
         this.value = (Calendar) value.clone();
 52  22
     }
 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  29
             if (value == null) {
 63  0
                     throw new IllegalArgumentException("Value cannot be null.");
 64  
             }
 65  29
     }
 66  
     
 67  
     @Override
 68  
     public Calendar getValue() {
 69  
         //defensive copy outgoing value - keeps things immutable
 70  2
         return (Calendar) value.clone();
 71  
     }
 72  
     
 73  
     @Override
 74  
     public int hashCode() {
 75  72
         return EqualsAndHashCodeUtils.hashCodeForCalendars(value);
 76  
     }
 77  
 
 78  
     @Override
 79  
     public boolean equals(Object obj) {
 80  
         //calendars equals use state that is not marshalled/unmarshalled by jaxb
 81  21
         return EqualsAndHashCodeUtils.equalsUsingCompareToOnFields(this, obj, "value");
 82  
     }
 83  
 
 84  
     @Override
 85  
     public String toString() {
 86  0
         return ToStringBuilder.reflectionToString(this);
 87  
     }
 88  
     
 89  
     /**
 90  
      * Defines some internal constants used on this class.
 91  
      */
 92  0
     static class Constants {
 93  
         final static String ROOT_ELEMENT_NAME = "dateTimeValue";
 94  
         final static String TYPE_NAME = "CriteriaDateTimeValueType";
 95  
     }
 96  
     
 97  
 }