You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-issues@jackrabbit.apache.org by "Michael Dürig (JIRA)" <ji...@apache.org> on 2012/10/04 13:59:07 UTC

[jira] [Commented] (OAK-350) Unify PropertyState and CoreValue

    [ https://issues.apache.org/jira/browse/OAK-350?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13469315#comment-13469315 ] 

Michael Dürig commented on OAK-350:
-----------------------------------

Revision 1394002 introduced the initial changes required:
* {{NodeBuilder}} and {{Tree}} now have methods for directly setting values instead of going through {{CoreValue}}.
* {{CoreValue}} is now deprecated
* Methods using {{CoreValue}} are deprecated when alternatives exist

The current {{PropertyState}} implementations are still based on {{CoreValue}} but I plan to gradually phase them out.
                
> 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
>            Assignee: 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