You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by md...@apache.org on 2012/10/12 13:58:41 UTC
svn commit: r1397526 -
/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/PropertyStates.java
Author: mduerig
Date: Fri Oct 12 11:58:41 2012
New Revision: 1397526
URL: http://svn.apache.org/viewvc?rev=1397526&view=rev
Log:
OAK-350: Unify PropertyState and CoreValue
Javadoc
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/PropertyStates.java
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/PropertyStates.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/PropertyStates.java?rev=1397526&r1=1397525&r2=1397526&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/PropertyStates.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/PropertyStates.java Fri Oct 12 11:58:41 2012
@@ -50,9 +50,21 @@ import static org.apache.jackrabbit.oak.
import static org.apache.jackrabbit.oak.api.Type.WEAKREFERENCE;
import static org.apache.jackrabbit.oak.api.Type.WEAKREFERENCES;
+/**
+ * Utility class for creating {@link PropertyState} instances.
+ */
public final class PropertyStates {
private PropertyStates() {}
+ /**
+ * Create a {@code PropertyState} based on a {@link Value}. The
+ * {@link Type} of the property state is determined by the
+ * type of the value.
+ * @param name The name of the property state
+ * @param value The value of the property state
+ * @return The new property state
+ * @throws RepositoryException forwarded from {@code value}
+ */
@Nonnull
public static PropertyState createProperty(String name, Value value) throws RepositoryException {
int type = value.getType();
@@ -74,6 +86,17 @@ public final class PropertyStates {
}
}
+ /**
+ * Create a multi valued {@code PropertyState} based on a list of
+ * {@link Value} instances. The {@link Type} of the property is determined
+ * by the type of the first value in the list or {@link Type#STRING} if the
+ * list is empty.
+ *
+ * @param name The name of the property state
+ * @param values The values of the property state
+ * @return The new property state
+ * @throws RepositoryException forwarded from {@code value}
+ */
@Nonnull
public static PropertyState createProperty(String name, Iterable<Value> values) throws RepositoryException {
Value first = Iterables.getFirst(values, null);
@@ -128,6 +151,13 @@ public final class PropertyStates {
}
}
+ /**
+ * Create a {@code PropertyState} from a string.
+ * @param name The name of the property state
+ * @param value The value of the property state
+ * @param type The type of the property state
+ * @return The new property state
+ */
@Nonnull
public static PropertyState createProperty(String name, String value, int type) {
switch (type) {
@@ -148,6 +178,13 @@ public final class PropertyStates {
}
}
+ /**
+ * Create a {@code PropertyState}.
+ * @param name The name of the property state
+ * @param value The value of the property state
+ * @param type The type of the property state
+ * @return The new property state
+ */
@SuppressWarnings("unchecked")
@Nonnull
public static <T> PropertyState createProperty(String name, T value, Type<T> type) {
@@ -192,6 +229,14 @@ public final class PropertyStates {
}
}
+ /**
+ * Create a {@code PropertyState} where the {@link Type} of the property state
+ * is inferred from the runtime type of {@code T} according to the mapping
+ * established through {@code Type}.
+ * @param name The name of the property state
+ * @param value The value of the property state
+ * @return The new property state
+ */
@Nonnull
public static <T> PropertyState createProperty(String name, T value) {
if (value instanceof String) {
@@ -223,6 +268,12 @@ public final class PropertyStates {
}
}
+ /**
+ * Create an empty {@code PropertyState}
+ * @param name The name of the property state
+ * @param type The type of the property state
+ * @return The new property state
+ */
public static PropertyState emptyProperty(String name, final Type<?> type) {
if (!type.isArray()) {
throw new IllegalArgumentException("Not an array type:" + type);
@@ -235,118 +286,332 @@ public final class PropertyStates {
};
}
+ /**
+ * Create a {@code PropertyState} from a string.
+ * @param name The name of the property state
+ * @param value The value of the property state
+ * @return The new property state of type {@link Type#STRING}
+ */
public static PropertyState stringProperty(String name, String value) {
return new StringPropertyState(name, value);
}
+ /**
+ * Create a {@code PropertyState} from an array of bytes.
+ * @param name The name of the property state
+ * @param value The value of the property state
+ * @return The new property state of type {@link Type#BINARY}
+ */
public static PropertyState binaryProperty(String name, byte[] value) {
return new BinaryPropertyState(name, new ArrayBasedBlob(value));
}
+ /**
+ * Create a {@code PropertyState} from a {@link Blob}.
+ * @param name The name of the property state
+ * @param value The value of the property state
+ * @return The new property state of type {@link Type#BINARY}
+ */
+ public static PropertyState binaryProperty(String name, Blob value) {
+ return new BinaryPropertyState(name, value);
+ }
+
+ /**
+ * Create a {@code PropertyState} from a {@link Value}.
+ * @param name The name of the property state
+ * @param value The value of the property state
+ * @return The new property state of type {@link Type#BINARY}
+ */
+ public static PropertyState binaryProperty(String name, Value value) {
+ return new BinaryPropertyState(name, new ValueBasedBlob(value));
+ }
+
+ /**
+ * Create a {@code PropertyState} from a long.
+ * @param name The name of the property state
+ * @param value The value of the property state
+ * @return The new property state of type {@link Type#LONG}
+ */
public static PropertyState longProperty(String name, long value) {
return new LongPropertyState(name, value);
}
+ /**
+ * Create a {@code PropertyState} from a double.
+ * @param name The name of the property state
+ * @param value The value of the property state
+ * @return The new property state of type {@link Type#DOUBLE}
+ */
public static PropertyState doubleProperty(String name, double value) {
return new DoublePropertyState(name, value);
}
+ /**
+ * Create a {@code PropertyState} from a date. No validation is performed
+ * on the string passed for {@code value}.
+ * @param name The name of the property state
+ * @param value The value of the property state
+ * @return The new property state of type {@link Type#DATE}
+ */
public static PropertyState dateProperty(String name, String value) {
return new GenericPropertyState(name, value, DATE);
}
+ /**
+ * Create a {@code PropertyState} from a boolean.
+ * @param name The name of the property state
+ * @param value The value of the property state
+ * @return The new property state of type {@link Type#BOOLEAN}
+ */
public static PropertyState booleanProperty(String name, boolean value) {
return new BooleanPropertyState(name, value);
}
+ /**
+ * Create a {@code PropertyState} from a name. No validation is performed
+ * on the string passed for {@code value}.
+ * @param name The name of the property state
+ * @param value The value of the property state
+ * @return The new property state of type {@link Type#NAME}
+ */
public static PropertyState nameProperty(String name, String value) {
return new GenericPropertyState(name, value, NAME);
}
+ /**
+ * Create a {@code PropertyState} from a path. No validation is performed
+ * on the string passed for {@code value}.
+ * @param name The name of the property state
+ * @param value The value of the property state
+ * @return The new property state of type {@link Type#PATH}
+ */
public static PropertyState pathProperty(String name, String value) {
return new GenericPropertyState(name, value, PATH);
}
+ /**
+ * Create a {@code PropertyState} from a reference. No validation is performed
+ * on the string passed for {@code value}.
+ * @param name The name of the property state
+ * @param value The value of the property state
+ * @return The new property state of type {@link Type#REFERENCE}
+ */
public static PropertyState referenceProperty(String name, String value) {
return new GenericPropertyState(name, value, REFERENCE);
}
+ /**
+ * Create a {@code PropertyState} from a weak reference. No validation is performed
+ * on the string passed for {@code value}.
+ * @param name The name of the property state
+ * @param value The value of the property state
+ * @return The new property state of type {@link Type#WEAKREFERENCE}
+ */
public static PropertyState weakreferenceProperty(String name, String value) {
return new GenericPropertyState(name, value, WEAKREFERENCE);
}
+ /**
+ * Create a {@code PropertyState} from a URI. No validation is performed
+ * on the string passed for {@code value}.
+ * @param name The name of the property state
+ * @param value The value of the property state
+ * @return The new property state of type {@link Type#URI}
+ */
public static PropertyState uriProperty(String name, String value) {
return new GenericPropertyState(name, value, URI);
}
+ /**
+ * Create a {@code PropertyState} from a decimal.
+ * @param name The name of the property state
+ * @param value The value of the property state
+ * @return The new property state of type {@link Type#DECIMAL}
+ */
public static PropertyState decimalProperty(String name, BigDecimal value) {
return new DecimalPropertyState(name, value);
}
- public static PropertyState binaryProperty(String name, Blob value) {
- return new BinaryPropertyState(name, value);
- }
-
- public static PropertyState binaryProperty(String name, Value value) {
- return new BinaryPropertyState(name, new ValueBasedBlob(value));
- }
-
+ /**
+ * Create a multi valued {@code PropertyState} from a list of strings.
+ * @param name The name of the property state
+ * @param values The values of the property state
+ * @return The new property state of type {@link Type#STRINGS}
+ */
public static PropertyState stringProperty(String name, Iterable<String> values) {
return new StringsPropertyState(name, Lists.newArrayList(values));
}
+ /**
+ * Create a multi valued {@code PropertyState} from a list of {@link Blob}.
+ * @param name The name of the property state
+ * @param values The values of the property state
+ * @return The new property state of type {@link Type#BINARIES}
+ */
public static PropertyState binaryPropertyFromBlob(String name, Iterable<Blob> values) {
return new BinariesPropertyState(name, Lists.newArrayList(values));
}
+ /**
+ * Create a multi valued {@code PropertyState} from a list of byte arrays.
+ * @param name The name of the property state
+ * @param values The values of the property state
+ * @return The new property state of type {@link Type#BINARIES}
+ */
+ public static PropertyState binaryPropertyFromArray(String name, Iterable<byte[]> values) {
+ List<Blob> blobs = Lists.newArrayList();
+ for (byte[] data : values) {
+ blobs.add(new ArrayBasedBlob(data));
+ }
+ return new BinariesPropertyState(name, blobs);
+ }
+
+ /**
+ * Create a multi valued {@code PropertyState} from a list of longs.
+ * @param name The name of the property state
+ * @param values The values of the property state
+ * @return The new property state of type {@link Type#LONGS}
+ */
public static PropertyState longProperty(String name, Iterable<Long> values) {
return new LongsPropertyState(name, Lists.newArrayList(values));
}
+ /**
+ * Create a multi valued {@code PropertyState} from a list of doubles.
+ * @param name The name of the property state
+ * @param values The values of the property state
+ * @return The new property state of type {@link Type#DOUBLES}
+ */
public static PropertyState doubleProperty(String name, Iterable<Double> values) {
return new DoublesPropertyState(name, Lists.newArrayList(values));
}
+ /**
+ * Create a multi valued {@code PropertyState} from a list of dates.
+ * No validation is performed on the strings passed for {@code values}.
+ * @param name The name of the property state
+ * @param values The values of the property state
+ * @return The new property state of type {@link Type#DATES}
+ */
public static PropertyState dateProperty(String name, Iterable<String> values) {
return new GenericsPropertyState(name, Lists.newArrayList(values), DATES);
}
+ /**
+ * Create a multi valued {@code PropertyState} from a list of booleans.
+ * @param name The name of the property state
+ * @param values The values of the property state
+ * @return The new property state of type {@link Type#BOOLEANS}
+ */
public static PropertyState booleanProperty(String name, Iterable<Boolean> values) {
return new BooleansPropertyState(name, Lists.newArrayList(values));
}
+ /**
+ * Create a multi valued {@code PropertyState} from a list of names.
+ * No validation is performed on the strings passed for {@code values}.
+ * @param name The name of the property state
+ * @param values The values of the property state
+ * @return The new property state of type {@link Type#NAMES}
+ */
public static PropertyState nameProperty(String name, Iterable<String> values) {
return new GenericsPropertyState(name, Lists.newArrayList(values), NAMES);
}
+ /**
+ * Create a multi valued {@code PropertyState} from a list of paths.
+ * No validation is performed on the strings passed for {@code values}.
+ * @param name The name of the property state
+ * @param values The values of the property state
+ * @return The new property state of type {@link Type#PATHS}
+ */
public static PropertyState pathProperty(String name, Iterable<String> values) {
return new GenericsPropertyState(name, Lists.newArrayList(values), PATHS);
}
+ /**
+ * Create a multi valued {@code PropertyState} from a list of references.
+ * No validation is performed on the strings passed for {@code values}.
+ * @param name The name of the property state
+ * @param values The values of the property state
+ * @return The new property state of type {@link Type#REFERENCES}
+ */
public static PropertyState referenceProperty(String name, Iterable<String> values) {
return new GenericsPropertyState(name, Lists.newArrayList(values), REFERENCES);
}
+ /**
+ * Create a multi valued {@code PropertyState} from a list of weak references.
+ * No validation is performed on the strings passed for {@code values}.
+ * @param name The name of the property state
+ * @param values The values of the property state
+ * @return The new property state of type {@link Type#WEAKREFERENCES}
+ */
public static PropertyState weakreferenceProperty(String name, Iterable<String> values) {
return new GenericsPropertyState(name, Lists.newArrayList(values), WEAKREFERENCES);
}
+ /**
+ * Create a multi valued {@code PropertyState} from a list of URIs.
+ * No validation is performed on the strings passed for {@code values}.
+ * @param name The name of the property state
+ * @param values The values of the property state
+ * @return The new property state of type {@link Type#URIS}
+ */
public static PropertyState uriProperty(String name, Iterable<String> values) {
return new GenericsPropertyState(name, Lists.newArrayList(values), URIS);
}
+ /**
+ * Create a multi valued {@code PropertyState} from a list of decimals.
+ * @param name The name of the property state
+ * @param values The values of the property state
+ * @return The new property state of type {@link Type#DECIMALS}
+ */
public static PropertyState decimalProperty(String name, Iterable<BigDecimal> values) {
return new DecimalsPropertyState(name, Lists.newArrayList(values));
}
- public static PropertyState binaryPropertyFromArray(String name, Iterable<byte[]> values) {
- List<Blob> blobs = Lists.newArrayList();
- for (byte[] data : values) {
- blobs.add(new ArrayBasedBlob(data));
+ /**
+ * Read a {@code PropertyState} from a {@link JsopReader}
+ * @param name The name of the property state
+ * @param reader The reader
+ * @param kernel {@link MicroKernel} instance used to resolve binaries
+ * @return The new property state of type {@link Type#DECIMALS}
+ */
+ public static PropertyState readProperty(String name, JsopReader reader, MicroKernel kernel) {
+ if (reader.matches(JsopReader.NUMBER)) {
+ String number = reader.getToken();
+ return createProperty(name, number, PropertyType.LONG);
+ } else if (reader.matches(JsopReader.TRUE)) {
+ return booleanProperty(name, true);
+ } else if (reader.matches(JsopReader.FALSE)) {
+ return booleanProperty(name, false);
+ } else if (reader.matches(JsopReader.STRING)) {
+ String jsonString = reader.getToken();
+ if (TypeCodes.startsWithCode(jsonString)) {
+ int type = TypeCodes.getTypeForCode(jsonString.substring(0, 3));
+ String value = jsonString.substring(4);
+ if (type == PropertyType.BINARY) {
+ return binaryProperty(name, new KernelBlob(value, kernel));
+ } else {
+ return createProperty(name, value, type);
+ }
+ } else {
+ return stringProperty(name, jsonString);
+ }
+ } else {
+ throw new IllegalArgumentException("Unexpected token: " + reader.getToken());
}
- return new BinariesPropertyState(name, blobs);
}
+ /**
+ * Read a multi valued {@code PropertyState} from a {@link JsopReader}
+ * @param name The name of the property state
+ * @param reader The reader
+ * @param kernel {@link MicroKernel} instance used to resolve binaries
+ * @return The new property state of type {@link Type#DECIMALS}
+ */
public static PropertyState readArrayProperty(String name, JsopReader reader, MicroKernel kernel) {
int type = PropertyType.STRING;
List<Object> values = Lists.newArrayList();
@@ -386,30 +651,4 @@ public final class PropertyStates {
}
return createProperty(name, values, (Type<Object>) Type.fromTag(type, true));
}
-
- public static PropertyState readProperty(String name, JsopReader reader, MicroKernel kernel) {
- if (reader.matches(JsopReader.NUMBER)) {
- String number = reader.getToken();
- return createProperty(name, number, PropertyType.LONG);
- } else if (reader.matches(JsopReader.TRUE)) {
- return booleanProperty(name, true);
- } else if (reader.matches(JsopReader.FALSE)) {
- return booleanProperty(name, false);
- } else if (reader.matches(JsopReader.STRING)) {
- String jsonString = reader.getToken();
- if (TypeCodes.startsWithCode(jsonString)) {
- int type = TypeCodes.getTypeForCode(jsonString.substring(0, 3));
- String value = jsonString.substring(4);
- if (type == PropertyType.BINARY) {
- return binaryProperty(name, new KernelBlob(value, kernel));
- } else {
- return createProperty(name, value, type);
- }
- } else {
- return stringProperty(name, jsonString);
- }
- } else {
- throw new IllegalArgumentException("Unexpected token: " + reader.getToken());
- }
- }
}