jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1397467 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value: PropertyValue.java PropertyValues.java ValueFactoryImpl.java ValueImpl.java
Date Fri, 12 Oct 2012 08:40:50 GMT
Author: mduerig
Date: Fri Oct 12 08:40:50 2012
New Revision: 1397467

URL: http://svn.apache.org/viewvc?rev=1397467&view=rev
Log:
OAK-350: Unify PropertyState and CoreValue
Base ValueImpl directly on PropertyState instead of PropertyValue

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value/PropertyValue.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value/PropertyValues.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value/ValueFactoryImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value/ValueImpl.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value/PropertyValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value/PropertyValue.java?rev=1397467&r1=1397466&r2=1397467&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value/PropertyValue.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value/PropertyValue.java
Fri Oct 12 08:40:50 2012
@@ -18,17 +18,13 @@
  */
 package org.apache.jackrabbit.oak.value;
 
-import java.math.BigDecimal;
 import java.util.Calendar;
 import java.util.Iterator;
-import java.util.List;
 
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import javax.jcr.PropertyType;
 
-import com.google.common.collect.Lists;
-import org.apache.jackrabbit.oak.api.Blob;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.util.ISO8601;
@@ -60,77 +56,6 @@ public class PropertyValue implements Co
         return ps.getValue(type, index);
     }
 
-    public List<PropertyValue> values() {
-        List<PropertyValue> pvs = Lists.newArrayList();
-
-        int type = getType().tag();
-        switch (type) {
-            case PropertyType.STRING:
-                for (String value : getValue(Type.STRINGS)) {
-                    pvs.add(PropertyValues.newString(value));
-                }
-                break;
-            case PropertyType.BINARY:
-                for (Blob value : getValue(Type.BINARIES)) {
-                    pvs.add(PropertyValues.newBinary(value));
-                }
-                break;
-            case PropertyType.LONG:
-                for (Long value : getValue(Type.LONGS)) {
-                    pvs.add(PropertyValues.newLong(value));
-                }
-                break;
-            case PropertyType.DOUBLE:
-                for (Double value : getValue(Type.DOUBLES)) {
-                    pvs.add(PropertyValues.newDouble(value));
-                }
-                break;
-            case PropertyType.DATE:
-                for (String value : getValue(Type.DATES)) {
-                    pvs.add(PropertyValues.newDate(value));
-                }
-                break;
-            case PropertyType.BOOLEAN:
-                for (Boolean value : getValue(Type.BOOLEANS)) {
-                    pvs.add(PropertyValues.newBoolean(value));
-                }
-                break;
-            case PropertyType.NAME:
-                for (String value : getValue(Type.NAMES)) {
-                    pvs.add(PropertyValues.newName(value));
-                }
-                break;
-            case PropertyType.PATH:
-                for (String value : getValue(Type.PATHS)) {
-                    pvs.add(PropertyValues.newPath(value));
-                }
-                break;
-            case PropertyType.REFERENCE:
-                for (String value : getValue(Type.REFERENCES)) {
-                    pvs.add(PropertyValues.newReference(value));
-                }
-                break;
-            case PropertyType.WEAKREFERENCE:
-                for (String value : getValue(Type.WEAKREFERENCES)) {
-                    pvs.add(PropertyValues.newWeakReference(value));
-                }
-                break;
-            case PropertyType.URI:
-                for (String value : getValue(Type.URIS)) {
-                    pvs.add(PropertyValues.newUri(value));
-                }
-                break;
-            case PropertyType.DECIMAL:
-                for (BigDecimal value : getValue(Type.DECIMALS)) {
-                    pvs.add(PropertyValues.newDecimal(value));
-                }
-                break;
-            default:
-                throw new IllegalStateException("Invalid type: " + getType());
-        }
-        return pvs;
-    }
-
     public long size() {
         return ps.size();
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value/PropertyValues.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value/PropertyValues.java?rev=1397467&r1=1397466&r2=1397467&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value/PropertyValues.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value/PropertyValues.java
Fri Oct 12 08:40:50 2012
@@ -26,7 +26,6 @@ import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import javax.jcr.PropertyType;
 
-import org.apache.jackrabbit.oak.api.Blob;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
@@ -113,11 +112,6 @@ public class PropertyValues {
         return new PropertyValue(PropertyStates.binaryProperty("", value));
     }
 
-    @Nonnull
-    public static PropertyValue newBinary(Blob value) {
-        return new PropertyValue(PropertyStates.binaryProperty("", value));
-    }
-
     // --
 
     public static boolean match(PropertyValue p1, PropertyState p2) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value/ValueFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value/ValueFactoryImpl.java?rev=1397467&r1=1397466&r2=1397467&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value/ValueFactoryImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value/ValueFactoryImpl.java
Fri Oct 12 08:40:50 2012
@@ -38,6 +38,7 @@ import com.google.common.io.ByteStreams;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
 import org.apache.jackrabbit.oak.plugins.identifier.IdentifierManager;
+import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
 import org.apache.jackrabbit.oak.plugins.memory.StringPropertyState;
 import org.apache.jackrabbit.util.ISO8601;
 import org.slf4j.Logger;
@@ -66,10 +67,9 @@ public class ValueFactoryImpl implements
     }
 
     public static List<Value> createValues(PropertyState property, NamePathMapper namePathMapper)
{
-        List<PropertyValue> propertyValues = PropertyValues.create(property).values();
         List<Value> values = Lists.newArrayList();
-        for (PropertyValue val : propertyValues) {
-            values.add(new ValueImpl(val, namePathMapper));
+        for (int i = 0; i < property.count(); i++) {
+            values.add(new ValueImpl(property, i, namePathMapper));
         }
         return values;
     }
@@ -78,7 +78,7 @@ public class ValueFactoryImpl implements
 
     @Override
     public Value createValue(String value) {
-        return new ValueImpl(PropertyValues.newString(value), namePathMapper);
+        return new ValueImpl(PropertyStates.stringProperty("", value), namePathMapper);
     }
 
     @Override
@@ -86,8 +86,7 @@ public class ValueFactoryImpl implements
         try {
             try {
                 // TODO add streaming capability to ContentSession via KernelBasedBlob
-                PropertyValue pv = PropertyValues.newBinary(ByteStreams.toByteArray(value));
-                return new ValueImpl(pv, namePathMapper);
+                return new ValueImpl(PropertyStates.binaryProperty("", ByteStreams.toByteArray(value)),
namePathMapper);
             } finally {
                 value.close();
             }
@@ -109,23 +108,23 @@ public class ValueFactoryImpl implements
 
     @Override
     public Value createValue(long value) {
-        return new ValueImpl(PropertyValues.newLong(value), namePathMapper);
+        return new ValueImpl(PropertyStates.longProperty("", value), namePathMapper);
     }
 
     @Override
     public Value createValue(double value) {
-        return new ValueImpl(PropertyValues.newDouble(value), namePathMapper);
+        return new ValueImpl(PropertyStates.doubleProperty("", value), namePathMapper);
     }
 
     @Override
     public Value createValue(Calendar value) {
         String dateStr = ISO8601.format(value);
-        return new ValueImpl(PropertyValues.newDate(dateStr), namePathMapper);
+        return new ValueImpl(PropertyStates.dateProperty("", dateStr), namePathMapper);
     }
 
     @Override
     public Value createValue(boolean value) {
-        return new ValueImpl(PropertyValues.newBoolean(value), namePathMapper);
+        return new ValueImpl(PropertyStates.booleanProperty("", value), namePathMapper);
     }
 
     @Override
@@ -136,13 +135,13 @@ public class ValueFactoryImpl implements
     @Override
     public Value createValue(Node value, boolean weak) throws RepositoryException {
         return weak
-            ? new ValueImpl(PropertyValues.newWeakReference(value.getUUID()), namePathMapper)
-            : new ValueImpl(PropertyValues.newReference(value.getUUID()), namePathMapper);
+            ? new ValueImpl(PropertyStates.weakreferenceProperty("", value.getUUID()), namePathMapper)
+            : new ValueImpl(PropertyStates.referenceProperty("", value.getUUID()), namePathMapper);
     }
 
     @Override
     public Value createValue(BigDecimal value) {
-        return new ValueImpl(PropertyValues.newDecimal(value), namePathMapper);
+        return new ValueImpl(PropertyStates.decimalProperty("", value), namePathMapper);
     }
 
     @Override
@@ -152,12 +151,12 @@ public class ValueFactoryImpl implements
         }
 
         try {
-            PropertyValue pv;
+            PropertyState pv;
             switch (type) {
                 case PropertyType.STRING:
                     return createValue(value);
                 case PropertyType.BINARY:
-                    pv = PropertyValues.newBinary(value.getBytes("UTF-8"));
+                    pv = PropertyStates.binaryProperty("", value.getBytes("UTF-8"));
                     break;
                 case PropertyType.LONG:
                     return createValue(StringPropertyState.getLong(value));
@@ -167,7 +166,7 @@ public class ValueFactoryImpl implements
                     if (ISO8601.parse(value) == null) {
                         throw new ValueFormatException("Invalid date " + value);
                     }
-                    pv = PropertyValues.newDate(value);
+                    pv = PropertyStates.dateProperty("", value);
                     break;
                 case PropertyType.BOOLEAN:
                     return createValue(StringPropertyState.getBoolean(value));
@@ -176,7 +175,7 @@ public class ValueFactoryImpl implements
                     if (oakName == null) {
                         throw new ValueFormatException("Invalid name: " + value);
                     }
-                    pv = PropertyValues.newName(oakName);
+                    pv = PropertyStates.nameProperty("", oakName);
                     break;
                 case PropertyType.PATH:
                     String oakValue = value;
@@ -188,23 +187,23 @@ public class ValueFactoryImpl implements
                     if (oakValue == null) {
                         throw new ValueFormatException("Invalid path: " + value);
                     }
-                    pv = PropertyValues.newPath(oakValue);
+                    pv = PropertyStates.pathProperty("", oakValue);
                     break;
                 case PropertyType.REFERENCE:
                     if (!IdentifierManager.isValidUUID(value)) {
                         throw new ValueFormatException("Invalid reference value " + value);
                     }
-                    pv = PropertyValues.newReference(value);
+                    pv = PropertyStates.referenceProperty("", value);
                     break;
                 case PropertyType.WEAKREFERENCE:
                     if (!IdentifierManager.isValidUUID(value)) {
                         throw new ValueFormatException("Invalid weak reference value " +
value);
                     }
-                    pv = PropertyValues.newWeakReference(value);
+                    pv = PropertyStates.weakreferenceProperty("", value);
                     break;
                 case PropertyType.URI:
                     new URI(value);
-                    pv = PropertyValues.newUri(value);
+                    pv = PropertyStates.uriProperty("", value);
                     break;
                 case PropertyType.DECIMAL:
                     return createValue(StringPropertyState.getDecimal(value));

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value/ValueImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value/ValueImpl.java?rev=1397467&r1=1397466&r2=1397467&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value/ValueImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value/ValueImpl.java
Fri Oct 12 08:40:50 2012
@@ -45,27 +45,30 @@ import org.slf4j.LoggerFactory;
 public class ValueImpl implements Value {
     private static final Logger log = LoggerFactory.getLogger(ValueImpl.class);
 
-    private final PropertyValue value;
+    private final PropertyState propertyState;
+    private final int index;
     private final NamePathMapper namePathMapper;
 
     private InputStream stream = null;
 
-    ValueImpl(PropertyValue value, NamePathMapper namePathMapper) {
-        this.value = value;
+    ValueImpl(PropertyState propertyState, int index, NamePathMapper namePathMapper) {
+        this.propertyState = propertyState;
+        this.index = index;
         this.namePathMapper = namePathMapper;
     }
 
-    public ValueImpl(PropertyState property, NamePathMapper namePathMapper) {
-        this(PropertyValues.create(property), namePathMapper);
+    ValueImpl(PropertyState property, NamePathMapper namePathMapper) {
+        this(property, 0, namePathMapper);
     }
 
     //--------------------------------------------------------------< Value >---
+
     /**
      * @see javax.jcr.Value#getType()
      */
     @Override
     public int getType() {
-        return value.getType().tag();
+        return propertyState.getType().tag();
     }
 
     /**
@@ -74,7 +77,7 @@ public class ValueImpl implements Value 
     @Override
     public boolean getBoolean() throws RepositoryException {
         if (getType() == PropertyType.STRING || getType() == PropertyType.BINARY || getType()
== PropertyType.BOOLEAN) {
-            return value.getValue(Type.BOOLEAN);
+            return propertyState.getValue(Type.BOOLEAN, index);
         } else {
             throw new ValueFormatException("Incompatible type " + PropertyType.nameFromValue(getType()));
         }
@@ -113,7 +116,7 @@ public class ValueImpl implements Value 
                     Calendar cal = getDate();
                     return BigDecimal.valueOf(cal.getTimeInMillis());
                 default:
-                    return value.getValue(Type.DECIMAL);
+                    return propertyState.getValue(Type.DECIMAL, index);
             }
         } catch (NumberFormatException e) {
             throw new ValueFormatException("Incompatible type " + PropertyType.nameFromValue(getType()));
@@ -131,7 +134,7 @@ public class ValueImpl implements Value 
                     Calendar cal = getDate();
                     return cal.getTimeInMillis();
                 default:
-                    return value.getValue(Type.DOUBLE);
+                    return propertyState.getValue(Type.DOUBLE, index);
             }
         } catch (NumberFormatException e) {
             throw new ValueFormatException("Incompatible type " + PropertyType.nameFromValue(getType()));
@@ -149,7 +152,7 @@ public class ValueImpl implements Value 
                     Calendar cal = getDate();
                     return cal.getTimeInMillis();
                 default:
-                    return value.getValue(Type.LONG);
+                    return propertyState.getValue(Type.LONG, index);
             }
         } catch (NumberFormatException e) {
             throw new ValueFormatException("Incompatible type " + PropertyType.nameFromValue(getType()));
@@ -163,9 +166,9 @@ public class ValueImpl implements Value 
     public String getString() throws RepositoryException {
         switch (getType()) {
             case PropertyType.NAME:
-                return namePathMapper.getJcrName(value.getValue(Type.STRING));
+                return namePathMapper.getJcrName(propertyState.getValue(Type.STRING, index));
             case PropertyType.PATH:
-                String s = value.getValue(Type.STRING);
+                String s = propertyState.getValue(Type.STRING, index);
                 if (s.startsWith("[") && s.endsWith("]")) {
                     // identifier paths are returned as-is (JCR 2.0, 3.4.3.1)
                     return s;
@@ -178,7 +181,7 @@ public class ValueImpl implements Value 
                             "In this case a new Value instance must be acquired in order
to successfully call this method.");
                 }
                 try {
-                    final InputStream is = value.getValue(Type.BINARY).getNewStream();
+                    final InputStream is = propertyState.getValue(Type.BINARY, index).getNewStream();
                     try {
                         return CharStreams.toString(CharStreams.newReaderSupplier(
                                 new InputSupplier<InputStream>() {
@@ -194,7 +197,7 @@ public class ValueImpl implements Value 
                     throw new RepositoryException("conversion from stream to string failed",
e);
                 }
             default:
-                return value.getValue(Type.STRING);
+                return propertyState.getValue(Type.STRING, index);
         }
     }
 
@@ -216,11 +219,11 @@ public class ValueImpl implements Value 
                 return new ByteArrayInputStream(
                         getString().getBytes(Charsets.UTF_8));
         }
-        return value.getValue(Type.BINARY).getNewStream();
+        return propertyState.getValue(Type.BINARY, index).getNewStream();
     }
 
     long getStreamLength() {
-        return value.getValue(Type.BINARY).length();
+        return propertyState.getValue(Type.BINARY, index).length();
     }
 
     /**
@@ -237,9 +240,16 @@ public class ValueImpl implements Value 
      * @see Object#equals(Object)
      */
     @Override
-    public boolean equals(Object obj) {
-        if (obj instanceof ValueImpl) {
-            return value.equals(((ValueImpl) obj).value);
+    public boolean equals(Object other) {
+        if (other instanceof ValueImpl) {
+            ValueImpl that = (ValueImpl) other;
+            try {
+                // FIXME real equals implementation
+                return getType() == that.getType() && getString().equals(that.getString());
+            }
+            catch (RepositoryException e) {
+                throw new RuntimeException();
+            }
         } else {
             return false;
         }
@@ -250,12 +260,12 @@ public class ValueImpl implements Value 
      */
     @Override
     public int hashCode() {
-        return value.hashCode();
+        return propertyState.hashCode();
     }
 
     @Override
     public String toString() {
-        return value.toString();
+        return propertyState.getValue(Type.STRING, index);
     }
 
 }
\ No newline at end of file



Mime
View raw message