Coverage Report - org.kuali.rice.core.api.criteria.CriteriaIntegerValue
 
Classes in this File Line Coverage Branch Coverage Complexity
CriteriaIntegerValue
86%
19/22
50%
2/4
1.444
CriteriaIntegerValue$Constants
0%
0/1
N/A
1.444
 
 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  
 
 22  
 import javax.xml.bind.annotation.XmlAccessType;
 23  
 import javax.xml.bind.annotation.XmlAccessorType;
 24  
 import javax.xml.bind.annotation.XmlRootElement;
 25  
 import javax.xml.bind.annotation.XmlType;
 26  
 import javax.xml.bind.annotation.XmlValue;
 27  
 import java.math.BigInteger;
 28  
 
 29  
 /**
 30  
  * A CriteriaValue which stores date and time information in the form of a
 31  
  * {@link BigInteger} value.
 32  
  * 
 33  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 34  
  *
 35  
  */
 36  2
 @XmlRootElement(name = CriteriaIntegerValue.Constants.ROOT_ELEMENT_NAME)
 37  
 @XmlAccessorType(XmlAccessType.NONE)
 38  
 @XmlType(name = CriteriaIntegerValue.Constants.TYPE_NAME)
 39  
 public final class CriteriaIntegerValue implements CriteriaValue<BigInteger> {
 40  
 
 41  
     @XmlValue
 42  
     private BigInteger value;
 43  
     
 44  34
     CriteriaIntegerValue() {
 45  34
         this.value = null;
 46  34
     }
 47  
     
 48  54
     CriteriaIntegerValue(BigInteger value) {
 49  54
             validateValue(value);
 50  54
         this.value = safeInstance(value);
 51  54
     }
 52  
     
 53  32
     CriteriaIntegerValue(Number value) {
 54  32
             validateValue(value);
 55  32
             this.value = BigInteger.valueOf(value.longValue());
 56  32
     }
 57  
     
 58  
     private static void validateValue(Object value) {
 59  86
             if (value == null) {
 60  0
                     throw new IllegalArgumentException("Value cannot be null.");
 61  
             }
 62  86
     }
 63  
 
 64  
     /**
 65  
      * Since BigInteger is not technically immutable we defensively copy when needed.
 66  
      *
 67  
      * see Effective Java 2nd ed. page 79 for details.
 68  
      *
 69  
      * @param val the big integer to check
 70  
      * @return the safe BigInteger
 71  
      */
 72  
     private static BigInteger safeInstance(BigInteger val) {
 73  54
         if (val.getClass() != BigInteger.class) {
 74  0
             return new BigInteger(val.toByteArray());
 75  
         }
 76  54
         return val;
 77  
     }
 78  
     
 79  
     @Override
 80  
     public BigInteger getValue() {
 81  2
         return value;
 82  
     }
 83  
     
 84  
     @Override
 85  
     public int hashCode() {
 86  230
         return HashCodeBuilder.reflectionHashCode(this);
 87  
     }
 88  
 
 89  
     @Override
 90  
     public boolean equals(Object obj) {
 91  34
         return EqualsBuilder.reflectionEquals(obj, this);
 92  
     }
 93  
 
 94  
     @Override
 95  
     public String toString() {
 96  0
         return ToStringBuilder.reflectionToString(this);
 97  
     }
 98  
     
 99  
     /**
 100  
      * Defines some internal constants used on this class.
 101  
      */
 102  0
     static class Constants {
 103  
         final static String ROOT_ELEMENT_NAME = "integerValue";
 104  
         final static String TYPE_NAME = "CriteriaIntegerValueType";
 105  
     }
 106  
     
 107  
 }