20
20
21
21
import java .io .Serializable ;
22
22
import java .io .UnsupportedEncodingException ;
23
+ import java .util .ArrayList ;
23
24
import java .util .Arrays ;
24
25
import java .util .List ;
25
26
import java .util .Set ;
28
29
import com .fasterxml .jackson .annotation .JsonAutoDetect .Visibility ;
29
30
import com .fasterxml .jackson .annotation .JsonInclude ;
30
31
import com .fasterxml .jackson .annotation .JsonProperty ;
31
- import com .google .common .collect .ImmutableList ;
32
- import com .google .common .collect .Iterables ;
33
32
import com .google .common .collect .Sets ;
34
33
35
34
/**
@@ -49,20 +48,14 @@ public static ParameterDesc newInstance(Object... objs) {
49
48
TblColRef col = (TblColRef ) obj ;
50
49
r .type = FunctionDesc .PARAMETER_TYPE_COLUMN ;
51
50
r .value = col .getIdentity ();
52
- r .colRefs = ImmutableList . of ( col ) ;
51
+ r .colRef = col ;
53
52
} else {
54
53
r .type = FunctionDesc .PARAMETER_TYPE_CONSTANT ;
55
54
r .value = (String ) obj ;
56
55
}
57
56
58
57
if (objs .length >= 2 ) {
59
58
r .nextParameter = newInstance (Arrays .copyOfRange (objs , 1 , objs .length ));
60
- if (r .nextParameter .colRefs .size () > 0 ) {
61
- if (r .colRefs .isEmpty ())
62
- r .colRefs = r .nextParameter .colRefs ;
63
- else
64
- r .colRefs = ImmutableList .copyOf (Iterables .concat (r .colRefs , r .nextParameter .colRefs ));
65
- }
66
59
}
67
60
return r ;
68
61
}
@@ -76,7 +69,8 @@ public static ParameterDesc newInstance(Object... objs) {
76
69
@ JsonInclude (JsonInclude .Include .NON_NULL )
77
70
private ParameterDesc nextParameter ;
78
71
79
- private List <TblColRef > colRefs = ImmutableList .of ();
72
+ private TblColRef colRef = null ;
73
+ private List <TblColRef > allColRefsIncludingNexts = null ;
80
74
private Set <PlainParameter > plainParameters = null ;
81
75
82
76
// Lazy evaluation
@@ -102,13 +96,28 @@ public String getValue() {
102
96
void setValue (String value ) {
103
97
this .value = value ;
104
98
}
99
+
100
+ public TblColRef getColRef () {
101
+ return colRef ;
102
+ }
105
103
106
- public List < TblColRef > getColRefs ( ) {
107
- return colRefs ;
104
+ void setColRef ( TblColRef colRef ) {
105
+ this . colRef = colRef ;
108
106
}
109
107
110
- void setColRefs (List <TblColRef > colRefs ) {
111
- this .colRefs = colRefs ;
108
+ public List <TblColRef > getColRefs () {
109
+ if (allColRefsIncludingNexts == null ) {
110
+ List <TblColRef > all = new ArrayList <>(2 );
111
+ ParameterDesc p = this ;
112
+ while (p != null ) {
113
+ if (p .isColumnType ())
114
+ all .add (p .getColRef ());
115
+
116
+ p = p .nextParameter ;
117
+ }
118
+ allColRefsIncludingNexts = all ;
119
+ }
120
+ return allColRefsIncludingNexts ;
112
121
}
113
122
114
123
public ParameterDesc getNextParameter () {
@@ -132,17 +141,12 @@ public boolean equals(Object o) {
132
141
return false ;
133
142
134
143
ParameterDesc p = this , q = that ;
135
- int refi = 0 , refj = 0 ;
136
144
for (; p != null && q != null ; p = p .nextParameter , q = q .nextParameter ) {
137
145
if (p .isColumnType ()) {
138
146
if (q .isColumnType () == false )
139
147
return false ;
140
- if (refi >= this .colRefs .size () || refj >= that .colRefs .size ())
141
- return false ;
142
- if (this .colRefs .get (refi ).equals (that .colRefs .get (refj )) == false )
148
+ if (this .getColRef ().equals (that .getColRef ()) == false )
143
149
return false ;
144
- refi ++;
145
- refj ++;
146
150
} else {
147
151
if (q .isColumnType () == true )
148
152
return false ;
@@ -171,13 +175,14 @@ public boolean equalInArbitraryOrder(Object o) {
171
175
@ Override
172
176
public int hashCode () {
173
177
int result = type != null ? type .hashCode () : 0 ;
174
- result = 31 * result + (colRefs != null ? colRefs .hashCode () : 0 );
178
+ result = 31 * result + (colRef != null ? colRef .hashCode () : 0 );
175
179
return result ;
176
180
}
177
181
178
182
@ Override
179
183
public String toString () {
180
- return "ParameterDesc [type=" + type + ", value=" + value + ", nextParam=" + nextParameter + "]" ;
184
+ String thisStr = isColumnType () ? colRef .toString () : value ;
185
+ return nextParameter == null ? thisStr : thisStr + "," + nextParameter .toString ();
181
186
}
182
187
183
188
/**
@@ -201,11 +206,9 @@ public boolean isColumnType() {
201
206
static Set <PlainParameter > createFromParameterDesc (ParameterDesc parameterDesc ) {
202
207
Set <PlainParameter > result = Sets .newHashSet ();
203
208
ParameterDesc local = parameterDesc ;
204
- List <TblColRef > totalColRef = parameterDesc .colRefs ;
205
- Integer colIndex = 0 ;
206
209
while (local != null ) {
207
210
if (local .isColumnType ()) {
208
- result .add (createSingleColumnParameter (local , totalColRef . get ( colIndex ++) ));
211
+ result .add (createSingleColumnParameter (local ));
209
212
} else {
210
213
result .add (createSingleValueParameter (local ));
211
214
}
@@ -221,11 +224,11 @@ static PlainParameter createSingleValueParameter(ParameterDesc parameterDesc) {
221
224
return single ;
222
225
}
223
226
224
- static PlainParameter createSingleColumnParameter (ParameterDesc parameterDesc , TblColRef colRef ) {
227
+ static PlainParameter createSingleColumnParameter (ParameterDesc parameterDesc ) {
225
228
PlainParameter single = new PlainParameter ();
226
229
single .type = parameterDesc .type ;
227
230
single .value = parameterDesc .value ;
228
- single .colRef = colRef ;
231
+ single .colRef = parameterDesc . colRef ;
229
232
return single ;
230
233
}
231
234
0 commit comments