com.microsoft.azure.documentdb.internal.routing.PartitionKeyInternal Maven / Gradle / Ivy
package com.microsoft.azure.documentdb.internal.routing;
import static com.microsoft.azure.documentdb.internal.Utils.as;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import org.json.JSONObject;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.ObjectCodec;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.fasterxml.jackson.databind.node.NullNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import com.microsoft.azure.documentdb.PartitionKeyDefinition;
import com.microsoft.azure.documentdb.Undefined;
import com.microsoft.azure.documentdb.internal.RMResources;
import com.microsoft.azure.documentdb.internal.Strings;
import com.microsoft.azure.documentdb.internal.Utils;
/**
* Used internally to encapsulate internal information of a partition key in the Azure Cosmos DB database service.
*/
@JsonSerialize(using = PartitionKeyInternal.PartitionKeyInternalJsonSerializer.class)
@JsonDeserialize(using = PartitionKeyInternal.PartitionKeyInternalJsonDeserializer.class)
public class PartitionKeyInternal implements Comparable {
private static final String TYPE = "type";
private static final String MIN_NUMBER = "MinNumber";
private static final String MAX_NUMBER = "MaxNumber";
private static final String MIN_STRING = "MinString";
private static final String MAX_STRING = "MaxString";
private static final String INFINITY = "Infinity";
public static final PartitionKeyInternal EmptyPartitionKey =
new PartitionKeyInternal(new ArrayList());
@SuppressWarnings("serial")
public static final PartitionKeyInternal InfinityPartitionKey =
new PartitionKeyInternal(new ArrayList() {{
add(new InfinityPartitionKeyComponent());
}});
public static final String MaximumExclusiveEffectivePartitionKey = PartitionKeyInternalHelper.MaximumExclusiveEffectivePartitionKey;
public static final String MinimumInclusiveEffectivePartitionKey = PartitionKeyInternalHelper.MinimumInclusiveEffectivePartitionKey;
public static final PartitionKeyInternal InclusiveMinimum = PartitionKeyInternal.EmptyPartitionKey;
public static final PartitionKeyInternal ExclusiveMaximum = PartitionKeyInternal.InfinityPartitionKey;
public static final PartitionKeyInternal Empty = PartitionKeyInternal.EmptyPartitionKey;
final List components;
public PartitionKeyInternal(List values) {
if (values == null) {
throw new IllegalArgumentException("values");
}
this.components = values;
}
public static PartitionKeyInternal fromJsonString(String partitionKey) {
if (Strings.isNullOrEmpty(partitionKey)) {
throw new IllegalArgumentException(String.format(RMResources.UnableToDeserializePartitionKeyValue, partitionKey));
}
try {
return Utils.getSimpleObjectMapper().readValue(partitionKey, PartitionKeyInternal.class);
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
}
public static PartitionKeyInternal fromObjectArray(Object[] values, boolean strict) {
if (values == null) {
throw new IllegalArgumentException("values");
}
return PartitionKeyInternal.fromObjectArray(Arrays.asList(values), strict);
}
public static PartitionKeyInternal fromObjectArray(List