-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
InternalUtils.java
325 lines (295 loc) · 11.2 KB
/
InternalUtils.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
/*
* Copyright 2014-2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package com.amazonaws.services.dynamodbv2.document.internal;
import com.amazonaws.AmazonWebServiceRequest;
import com.amazonaws.services.dynamodbv2.document.AttributeUpdate;
import com.amazonaws.services.dynamodbv2.document.Expected;
import com.amazonaws.services.dynamodbv2.document.Item;
import com.amazonaws.services.dynamodbv2.document.ItemUtils;
import com.amazonaws.services.dynamodbv2.document.KeyAttribute;
import com.amazonaws.services.dynamodbv2.document.PrimaryKey;
import com.amazonaws.services.dynamodbv2.model.AttributeValue;
import com.amazonaws.services.dynamodbv2.model.AttributeValueUpdate;
import com.amazonaws.services.dynamodbv2.model.Condition;
import com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue;
import com.amazonaws.util.ValidationUtils;
import com.amazonaws.util.VersionInfoUtils;
import java.math.BigDecimal;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Internal utilities. Not meant for general use. May change without notice.
*
* @deprecated Use {@link ItemUtils} instead.
*/
@Deprecated
public enum InternalUtils {
;
/**
* Returns a non-null list of <code>Item</code>'s given the low level
* list of item information.
*/
public static List<Item> toItemList(List<Map<String, AttributeValue>> items) {
return ItemUtils.toItemList(items);
}
/**
* Converts an <code>Item</code> into the low-level representation;
* or null if the input is null.
*/
public static Map<String, AttributeValue> toAttributeValues(Item item) {
return ItemUtils.toAttributeValues(item);
}
/**
* Converts a map of string to simple objects into the low-level
* representation; or null if the input is null.
*/
public static Map<String, AttributeValue> fromSimpleMap(
Map<String, Object> map) {
return ItemUtils.fromSimpleMap(map);
}
/**
* Converts a list of <code>AttributeUpdate</code> into the low-level
* representation; or null if the input is null.
*/
public static Map<String, AttributeValueUpdate> toAttributeValueUpdate(
List<AttributeUpdate> attributesToUpdate) {
return ItemUtils.toAttributeValueUpdate(attributesToUpdate);
}
/**
* Converts a simple value into the low-level <code><AttributeValue/code>
* representation.
*
* @param value the given value which can be one of the followings:
* <ul>
* <li>String</li>
* <li>Set<String></li>
* <li>Number (including any subtypes and primitive types)</li>
* <li>Set<Number></li>
* <li>byte[]</li>
* <li>Set<byte[]></li>
* <li>ByteBuffer</li>
* <li>Set<ByteBuffer></li>
* <li>Boolean or boolean</li>
* <li>null</li>
* <li>Map<String,T>, where T can be any type on this list but must not
* induce any circular reference</li>
* <li>List<T>, where T can be any type on this list but must not induce
* any circular reference</li>
* </ul>
* @return a non-null low level representation of the input object value
* @throws UnsupportedOperationException if the input object type is not supported
*/
public static AttributeValue toAttributeValue(Object value) {
return ItemUtils.toAttributeValue(value);
}
/**
* Converts a list of low-level <code>AttributeValue</code> into a list of
* simple values. Each value in the returned list can be one of the
* followings:
*
* <ul>
* <li>String</li>
* <li>Set<String></li>
* <li>Number (including any subtypes and primitive types)</li>
* <li>Set<Number></li>
* <li>byte[]</li>
* <li>Set<byte[]></li>
* <li>ByteBuffer</li>
* <li>Set<ByteBuffer></li>
* <li>Boolean or boolean</li>
* <li>null</li>
* <li>Map<String,T>, where T can be any type on this list but must not
* induce any circular reference</li>
* <li>List<T>, where T can be any type on this list but must not induce
* any circular reference</li>
* </ul>
*/
public static List<Object> toSimpleList(List<AttributeValue> attrValues) {
return ItemUtils.toSimpleList(attrValues);
}
/**
* Convenient method to convert a list of low-level
* <code>AttributeValue</code> into a list of values of the same type T.
* Each value in the returned list can be one of the followings:
* <ul>
* <li>String</li>
* <li>Set<String></li>
* <li>Number (including any subtypes and primitive types)</li>
* <li>Set<Number></li>
* <li>byte[]</li>
* <li>Set<byte[]></li>
* <li>ByteBuffer</li>
* <li>Set<ByteBuffer></li>
* <li>Boolean or boolean</li>
* <li>null</li>
* <li>Map<String,T>, where T can be any type on this list but must not
* induce any circular reference</li>
* <li>List<T>, where T can be any type on this list but must not induce
* any circular reference</li>
* </ul>
*/
public static <T> List<T> toSimpleListValue(List<AttributeValue> values) {
return ItemUtils.toSimpleListValue(values);
}
public static <T> Map<String, T> toSimpleMapValue(
Map<String, AttributeValue> values) {
return ItemUtils.toSimpleMapValue(values);
}
/**
* Returns the string representation of the given value; or null if the
* value is null. For <code>BigDecimal</code> it will be the string
* representation without an exponent field.
*/
public static String valToString(Object val) {
return ItemUtils.valToString(val);
}
/**
* Converts a low-level <code>AttributeValue</code> into a simple value,
* which can be one of the followings:
*
* <ul>
* <li>String</li>
* <li>Set<String></li>
* <li>Number (including any subtypes and primitive types)</li>
* <li>Set<Number></li>
* <li>byte[]</li>
* <li>Set<byte[]></li>
* <li>ByteBuffer</li>
* <li>Set<ByteBuffer></li>
* <li>Boolean or boolean</li>
* <li>null</li>
* <li>Map<String,T>, where T can be any type on this list but must not
* induce any circular reference</li>
* <li>List<T>, where T can be any type on this list but must not induce
* any circular reference</li>
* </ul>
*
* @throws IllegalArgumentException if an empty <code>AttributeValue</code> value is specified
*/
static <T> T toSimpleValue(AttributeValue value) {
return ItemUtils.toSimpleValue(value);
}
/**
* Returns the minimum of the two input integers taking null into account.
* Returns null if both integers are null. Otherwise, a null Integer is
* treated as infinity.
*/
public static Integer minimum(Integer one, Integer two) {
return ItemUtils.minimum(one, two);
}
/**
* Returns the low level representation of a collection of <code>Expected</code>.
*/
public static Map<String, ExpectedAttributeValue> toExpectedAttributeValueMap(
Collection<Expected> expectedSet) {
return ItemUtils.toExpectedAttributeValueMap(expectedSet);
}
/**
* Returns the low level representation of a collection of <code>Filter</code>.
*/
public static Map<String, Condition> toAttributeConditionMap(Collection<? extends Filter<?>> filters) {
return ItemUtils.toAttributeConditionMap(filters);
}
/**
* Converts the input array of values into an array of low level
* representation of those values.
*
* A value in the input array can be one of the followings:
*
* <ul>
* <li>String</li>
* <li>Set<String></li>
* <li>Number (including any subtypes and primitive types)</li>
* <li>Set<Number></li>
* <li>byte[]</li>
* <li>Set<byte[]></li>
* <li>ByteBuffer</li>
* <li>Set<ByteBuffer></li>
* <li>Boolean or boolean</li>
* <li>null</li>
* <li>Map<String,T>, where T can be any type on this list but must not
* induce any circular reference</li>
* <li>List<T>, where T can be any type on this list but must not induce
* any circular reference</li>
* </ul>
*/
public static AttributeValue[] toAttributeValues(Object[] values) {
return ItemUtils.toAttributeValues(values);
}
/**
* Converts the specified primary key into the low-level representation.
*/
public static Map<String, AttributeValue> toAttributeValueMap(
Collection<KeyAttribute> primaryKey) {
return ItemUtils.toAttributeValueMap(primaryKey);
}
/**
* Converts the specified primary key into the low-level representation.
*/
public static Map<String, AttributeValue> toAttributeValueMap(
PrimaryKey primaryKey) {
return ItemUtils.toAttributeValueMap(primaryKey);
}
/**
* Converts the specified primary key into the low-level representation.
*/
public static Map<String, AttributeValue> toAttributeValueMap(
KeyAttribute... primaryKey) {
return ItemUtils.toAttributeValueMap(primaryKey);
}
/**
* Converts a number into BigDecimal representation.
*/
public static BigDecimal toBigDecimal(Number n) {
return ItemUtils.toBigDecimal(n);
}
public static Set<BigDecimal> toBigDecimalSet(Number... val) {
return ItemUtils.toBigDecimalSet(val);
}
public static Set<BigDecimal> toBigDecimalSet(Set<Number> vals) {
return ItemUtils.toBigDecimalSet(vals);
}
/**
* Append the custom user-agent string.
* <p>Note to maintainers, this is technically not deprecated and not present in {@link ItemUtils}. It is truly meant for
* internal use only.</p>
*/
public static <X extends AmazonWebServiceRequest> X applyUserAgent(X request) {
final String USER_AGENT = "dynamodb-table-api/" + VersionInfoUtils.getVersion();
request.getRequestClientOptions().appendUserAgent(USER_AGENT);
return request;
}
public static void rejectNullValue(Object val) {
ValidationUtils.assertNotNull(val, "val");
}
public static void rejectNullInput(Object input) {
ValidationUtils.assertNotNull(input, "val");
}
public static void rejectEmptyInput(Object[] input) {
ValidationUtils.assertNotEmpty(input, "input");
}
public static void rejectNullOrEmptyInput(Object[] input) {
rejectNullInput(input);
rejectEmptyInput(input);
}
public static void checkInvalidAttrName(String attrName) {
ItemUtils.checkInvalidAttrName(attrName);
}
public static void checkInvalidAttribute(String attrName, Object val) {
ItemUtils.checkInvalidAttribute(attrName, val);
}
}