Revision created by MOE tool push_codebase.
[gae.git] / java / src / main / com / google / appengine / api / datastore / ExtendableEntityUtil.java
blob5bfa50ebece08efaafd872fbdff9adf5e6dc5dcf
1 package com.google.appengine.api.datastore;
3 import static com.google.appengine.api.datastore.DataTypeUtils.CheckValueOption.ALLOW_MULTI_VALUE;
4 import static com.google.appengine.api.datastore.DataTypeUtils.CheckValueOption.VALUE_PRE_CHECKED_WITHOUT_NAME;
6 import com.google.appengine.api.datastore.DataTypeUtils.CheckValueOption;
7 import com.google.apphosting.api.AppEngineInternal;
9 import java.util.EnumSet;
10 import java.util.Set;
12 /**
13 * Internal class that provides utility methods for {@link ExtendableEntity} objects.
16 @AppEngineInternal
17 public final class ExtendableEntityUtil {
19 /**
20 * Creates a new {@code Key} with the provided parent and kind. The instantiated
21 * {@Key} will be incomplete.
23 * @param parent the parent of the key to create, can be {@code null}
24 * @param kind the kind of the key to create
26 public static Key createKey(Key parent, String kind) {
27 return new Key(kind, parent);
30 /**
31 * Check if the input {@code Key} objects are equal (including keys that are
32 * incomplete).
34 * @param key1 the first input key
35 * @param key2 the second input key
36 * @return {@code true} if the keys are equal. {@code false} otherwise.
38 public static boolean areKeysEqual(Key key1, Key key2) {
39 return key1 == null ? key2 == null : key1.equals(key2, false);
42 /**
43 * If the specified object cannot be used as the value for a {@code Entity} property, throw
44 * an exception with the appropriate explanation.
46 * @param propertyName the name of the property.
47 * @param value value in question
48 * @param supportedTypes the types considered to be valid types for the value.
49 * @param valuePreChecked {@code true} if the value without the name has already been checked.
50 * {@code false} otherwise.
51 * @throws IllegalArgumentException if the type is not supported, or if the object is in
52 * some other way invalid.
54 public static void checkSupportedValue(String propertyName, Object value, boolean valuePreChecked,
55 Set<Class<?>> supportedTypes) {
56 EnumSet<CheckValueOption> options = EnumSet.of(ALLOW_MULTI_VALUE);
57 if (valuePreChecked) {
58 options.add(VALUE_PRE_CHECKED_WITHOUT_NAME);
60 DataTypeUtils.checkSupportedValue(propertyName, value, options, supportedTypes);
63 private ExtendableEntityUtil() {