All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.amazonaws.services.dynamodbv2.document.internal.InternalUtils Maven / Gradle / Ivy

Go to download

The AWS Java SDK for Amazon DynamoDB module holds the client classes that are used for communicating with Amazon DynamoDB Service

There is a newer version: 1.12.753
Show newest version
/*
 * 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 Item's given the low level
     * list of item information.
     */
    public static List toItemList(List> items) {
        return ItemUtils.toItemList(items);
    }

    /**
     * Converts an Item into the low-level representation;
     * or null if the input is null.
     */
    public static Map 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 fromSimpleMap(
        Map map) {
        return ItemUtils.fromSimpleMap(map);
    }

    /**
     * Converts a list of AttributeUpdate into the low-level
     * representation; or null if the input is null.
     */
    public static Map toAttributeValueUpdate(
        List attributesToUpdate) {
        return ItemUtils.toAttributeValueUpdate(attributesToUpdate);
    }

    /**
     * Converts a simple value into the low-level 
     * representation.
     *
     * @param value the given value which can be one of the followings:
     * 
    *
  • String
  • *
  • Set<String>
  • *
  • Number (including any subtypes and primitive types)
  • *
  • Set<Number>
  • *
  • byte[]
  • *
  • Set<byte[]>
  • *
  • ByteBuffer
  • *
  • Set<ByteBuffer>
  • *
  • Boolean or boolean
  • *
  • null
  • *
  • Map<String,T>, where T can be any type on this list but must not * induce any circular reference
  • *
  • List<T>, where T can be any type on this list but must not induce * any circular reference
  • *
* @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 AttributeValue into a list of * simple values. Each value in the returned list can be one of the * followings: * *
    *
  • String
  • *
  • Set<String>
  • *
  • Number (including any subtypes and primitive types)
  • *
  • Set<Number>
  • *
  • byte[]
  • *
  • Set<byte[]>
  • *
  • ByteBuffer
  • *
  • Set<ByteBuffer>
  • *
  • Boolean or boolean
  • *
  • null
  • *
  • Map<String,T>, where T can be any type on this list but must not * induce any circular reference
  • *
  • List<T>, where T can be any type on this list but must not induce * any circular reference
  • *
*/ public static List toSimpleList(List attrValues) { return ItemUtils.toSimpleList(attrValues); } /** * Convenient method to convert a list of low-level * AttributeValue into a list of values of the same type T. * Each value in the returned list can be one of the followings: *
    *
  • String
  • *
  • Set<String>
  • *
  • Number (including any subtypes and primitive types)
  • *
  • Set<Number>
  • *
  • byte[]
  • *
  • Set<byte[]>
  • *
  • ByteBuffer
  • *
  • Set<ByteBuffer>
  • *
  • Boolean or boolean
  • *
  • null
  • *
  • Map<String,T>, where T can be any type on this list but must not * induce any circular reference
  • *
  • List<T>, where T can be any type on this list but must not induce * any circular reference
  • *
*/ public static List toSimpleListValue(List values) { return ItemUtils.toSimpleListValue(values); } public static Map toSimpleMapValue( Map values) { return ItemUtils.toSimpleMapValue(values); } /** * Returns the string representation of the given value; or null if the * value is null. For BigDecimal it will be the string * representation without an exponent field. */ public static String valToString(Object val) { return ItemUtils.valToString(val); } /** * Converts a low-level AttributeValue into a simple value, * which can be one of the followings: * *
    *
  • String
  • *
  • Set<String>
  • *
  • Number (including any subtypes and primitive types)
  • *
  • Set<Number>
  • *
  • byte[]
  • *
  • Set<byte[]>
  • *
  • ByteBuffer
  • *
  • Set<ByteBuffer>
  • *
  • Boolean or boolean
  • *
  • null
  • *
  • Map<String,T>, where T can be any type on this list but must not * induce any circular reference
  • *
  • List<T>, where T can be any type on this list but must not induce * any circular reference
  • *
* * @throws IllegalArgumentException if an empty AttributeValue value is specified */ static 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 Expected. */ public static Map toExpectedAttributeValueMap( Collection expectedSet) { return ItemUtils.toExpectedAttributeValueMap(expectedSet); } /** * Returns the low level representation of a collection of Filter. */ public static Map toAttributeConditionMap(Collection> 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: * *
    *
  • String
  • *
  • Set<String>
  • *
  • Number (including any subtypes and primitive types)
  • *
  • Set<Number>
  • *
  • byte[]
  • *
  • Set<byte[]>
  • *
  • ByteBuffer
  • *
  • Set<ByteBuffer>
  • *
  • Boolean or boolean
  • *
  • null
  • *
  • Map<String,T>, where T can be any type on this list but must not * induce any circular reference
  • *
  • List<T>, where T can be any type on this list but must not induce * any circular reference
  • *
*/ public static AttributeValue[] toAttributeValues(Object[] values) { return ItemUtils.toAttributeValues(values); } /** * Converts the specified primary key into the low-level representation. */ public static Map toAttributeValueMap( Collection primaryKey) { return ItemUtils.toAttributeValueMap(primaryKey); } /** * Converts the specified primary key into the low-level representation. */ public static Map toAttributeValueMap( PrimaryKey primaryKey) { return ItemUtils.toAttributeValueMap(primaryKey); } /** * Converts the specified primary key into the low-level representation. */ public static Map 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 toBigDecimalSet(Number... val) { return ItemUtils.toBigDecimalSet(val); } public static Set toBigDecimalSet(Set vals) { return ItemUtils.toBigDecimalSet(vals); } /** * Append the custom user-agent string. *

Note to maintainers, this is technically not deprecated and not present in {@link ItemUtils}. It is truly meant for * internal use only.

*/ public static 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); } }