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