1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
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.kuali.rice.core.api.util.type.KualiDecimal;
22  import org.kuali.rice.core.api.util.type.KualiInteger;
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 java.math.BigDecimal;
30  import java.math.BigInteger;
31  
32  
33  
34  
35  
36  
37  
38  
39  @XmlRootElement(name = CriteriaKualiIntegerValue.Constants.ROOT_ELEMENT_NAME)
40  @XmlAccessorType(XmlAccessType.NONE)
41  @XmlType(name = CriteriaKualiIntegerValue.Constants.TYPE_NAME)
42  public final class CriteriaKualiIntegerValue implements CriteriaValue<KualiInteger> {
43  
44      @XmlValue
45      private final BigInteger value;
46  
47      CriteriaKualiIntegerValue() {
48          this.value = null;
49      }
50  
51      CriteriaKualiIntegerValue(KualiInteger value) {
52      	validateValue(value);
53          this.value = safeInstance(value);
54      }
55  
56      CriteriaKualiIntegerValue(long value) {
57          validateValue(value);
58          this.value = new KualiInteger(value).bigIntegerValue();
59      }
60  
61      CriteriaKualiIntegerValue(int value) {
62          validateValue(value);
63          this.value = new KualiInteger((long)value).bigIntegerValue();
64      }
65  
66      CriteriaKualiIntegerValue(String value) {
67          validateValue(value);
68          this.value = new KualiInteger(value).bigIntegerValue();
69      }
70  
71      CriteriaKualiIntegerValue(BigDecimal value) {
72          validateValue(value);
73          this.value = new KualiInteger(value).bigIntegerValue();
74      }
75  
76      private static void validateValue(Object value) {
77      	if (value == null) {
78      		throw new IllegalArgumentException("Value cannot be null.");
79      	}
80      }
81  
82      
83  
84  
85  
86  
87  
88  
89  
90      private static BigInteger safeInstance(KualiInteger val) {
91          return new BigInteger(val.bigIntegerValue().toString());
92      }
93      
94      @Override
95      public KualiInteger getValue() {
96          return new KualiInteger(this.value);
97      }
98      
99      @Override
100     public int hashCode() {
101         return HashCodeBuilder.reflectionHashCode(this);
102     }
103 
104     @Override
105     public boolean equals(Object obj) {
106         return EqualsBuilder.reflectionEquals(obj, this);
107     }
108 
109     @Override
110     public String toString() {
111         return ToStringBuilder.reflectionToString(this);
112     }
113     
114     
115 
116 
117     static class Constants {
118         final static String ROOT_ELEMENT_NAME = "kualiIntegerValue";
119         final static String TYPE_NAME = "CriteriaKualiIntegerValueType";
120     }
121     
122 }