jackrabbit-oak-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Dürig (JIRA) <j...@apache.org>
Subject [jira] [Created] (OAK-350) Unify PropertyState and CoreValue
Date Thu, 27 Sep 2012 18:51:07 GMT
Michael Dürig created OAK-350:
---------------------------------

             Summary: Unify PropertyState and CoreValue
                 Key: OAK-350
                 URL: https://issues.apache.org/jira/browse/OAK-350
             Project: Jackrabbit Oak
          Issue Type: Improvement
          Components: core
            Reporter: Michael Dürig


With OAK-346 {{ValueImpl}} and {{ValueFactoryImpl}} are now part of the core. In order to
reduce the number of separate representations of values, I propose to unify CoreValue with
PropertyState and eventually deprecate and remove CoreValue.

I suggest to add generic methods to {{PropertyState}} for accessing the values directly instead
of looping them through an additional container:

{code}
/**
* Value of this property.
* The type of the return value is determined by the target {@code type}
* argument. If {@code type.isArray()} is true, this method returns an
* {@code Iterable} of the {@link Type#getBaseType() base type} of
* {@code type} containing all values of this property.
* If the target type is not the same as the type of this property an attempt
* is made to convert the value to the target type. If the conversion fails an
* exception is thrown.
* @param type target type
* @param <T>
* @return the value of this property
* @throws IllegalStateException if {@code type.isArray() == false} and
* {@code this.isArray() == true}. In other words, when trying to convert
* from an array to an atom.
* @throws IllegalArgumentException if {@code type} refers to an unkown type.
* @throws NumberFormatException if conversion to a number failed.
* @throws UnsupportedOperationException if conversion to boolean failed.
*/
@Nonnull
<T> T getValue(Type<T> type);

/**
* Value at the given {@code index}.
* The type of the return value is determined by the target {@code type}
* argument.
* If the target type is not the same as the type of this property an attempt
* is made to convert the value to the target type. If the conversion fails an
* exception is thrown.
* @param type target type
* @param index
* @param <T>
* @return the value of this property at the given {@code index}
* @throws IndexOutOfBoundsException if {@code index} is less than {@code 0} or
* greater or equals {@code count()}.
* @throws IllegalArgumentException if {@code type} refers to an unkown type or if
* {@code type.isArray()} is true.
*/
@Nonnull
<T> T getValue(Type<T> type, int index);
{code}

See [PropertyState | https://github.com/mduerig/jackrabbit-oak/blob/unify-value-and-propertystate/oak-core/src/main/java/org/apache/jackrabbit/oak/api/PropertyState.java],
[Type | https://github.com/mduerig/jackrabbit-oak/blob/unify-value-and-propertystate/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Type.java]
and [Blob | https://github.com/mduerig/jackrabbit-oak/blob/unify-value-and-propertystate/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Blob.java]
for the full proposal.

In addition of reducing the number of runtime instances this approach also simplifies client
code:

{code}
    String s = property.getValue().getString();
{code}

becomes

{code}
    String s = property.getValue(STRING);
{code}

And even better for multi valued properties:

{code}
    for(Value value : property.getValues()) {
        String s = value.getString();
        doSomething(s);
    }
{code}

becomes

{code}
    for(String s : property.getValue(STRINGS)) {
        doSomething(s);
    }
{code}

Furthermore this approach opens up the possibility for plugging in custom types later on by
adding handlers for custom instances of {{Type}}. 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message