1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.expression;
18
19 import org.springframework.core.convert.TypeDescriptor;
20 import org.springframework.util.ObjectUtils;
21
22
23
24
25
26
27
28
29
30
31 public class TypedValue {
32
33 public static final TypedValue NULL = new TypedValue(null);
34
35
36 private final Object value;
37
38 private TypeDescriptor typeDescriptor;
39
40
41
42
43
44
45
46 public TypedValue(Object value) {
47 this.value = value;
48 this.typeDescriptor = null;
49 }
50
51
52
53
54
55
56
57 public TypedValue(Object value, TypeDescriptor typeDescriptor) {
58 this.value = value;
59 this.typeDescriptor = typeDescriptor;
60 }
61
62
63 public Object getValue() {
64 return this.value;
65 }
66
67 public TypeDescriptor getTypeDescriptor() {
68 if (this.typeDescriptor == null && this.value != null) {
69 this.typeDescriptor = TypeDescriptor.forObject(this.value);
70 }
71 return this.typeDescriptor;
72 }
73
74
75 @Override
76 public boolean equals(Object other) {
77 if (this == other) {
78 return true;
79 }
80 if (!(other instanceof TypedValue)) {
81 return false;
82 }
83 TypedValue otherTv = (TypedValue) other;
84
85 return (ObjectUtils.nullSafeEquals(this.value, otherTv.value) &&
86 ((this.typeDescriptor == null && otherTv.typeDescriptor == null) ||
87 ObjectUtils.nullSafeEquals(getTypeDescriptor(), otherTv.getTypeDescriptor())));
88 }
89
90 @Override
91 public int hashCode() {
92 return ObjectUtils.nullSafeHashCode(this.value);
93 }
94
95 @Override
96 public String toString() {
97 return "TypedValue: '" + this.value + "' of [" + getTypeDescriptor() + "]";
98 }
99
100 }