jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1399669 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak: plugins/memory/ value/
Date Thu, 18 Oct 2012 14:09:03 GMT
Author: mduerig
Date: Thu Oct 18 14:09:02 2012
New Revision: 1399669

URL: http://svn.apache.org/viewvc?rev=1399669&view=rev
Log:
OAK-380: Define conversion of property values
Make value conversions explicit through new Conversions class

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value/Conversions.java
  (with props)
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/BinariesPropertyState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/BinaryPropertyState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/BooleanPropertyState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/BooleansPropertyState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/DecimalPropertyState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/DecimalsPropertyState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/DoublePropertyState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/DoublesPropertyState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/EmptyPropertyState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/LongPropertyState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/LongsPropertyState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MultiPropertyState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/PropertyStates.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/SinglePropertyState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value/ValueFactoryImpl.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/BinariesPropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/BinariesPropertyState.java?rev=1399669&r1=1399668&r2=1399669&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/BinariesPropertyState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/BinariesPropertyState.java
Thu Oct 18 14:09:02 2012
@@ -22,6 +22,7 @@ import com.google.common.base.Function;
 import com.google.common.collect.Iterables;
 import org.apache.jackrabbit.oak.api.Blob;
 import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.value.Conversions;
 
 import static org.apache.jackrabbit.oak.api.Type.BINARIES;
 
@@ -36,14 +37,14 @@ public class BinariesPropertyState exten
         return Iterables.transform(values, new Function<Blob, String>() {
             @Override
             public String apply(Blob value) {
-                return "<binary>";
+                return Conversions.convert(value).toString();
             }
         });
     }
 
     @Override
     protected String getString(int index) {
-        return "<binary>";
+        return Conversions.convert(values.get(index)).toString();
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/BinaryPropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/BinaryPropertyState.java?rev=1399669&r1=1399668&r2=1399669&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/BinaryPropertyState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/BinaryPropertyState.java
Thu Oct 18 14:09:02 2012
@@ -18,6 +18,7 @@ package org.apache.jackrabbit.oak.plugin
 
 import org.apache.jackrabbit.oak.api.Blob;
 import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.value.Conversions;
 
 public class BinaryPropertyState extends SinglePropertyState {
     private final Blob value;
@@ -29,8 +30,7 @@ public class BinaryPropertyState extends
 
     @Override
     public String getString() {
-        // TODO find a better way to represent string values with Blobs
-        return value.toString();
+        return Conversions.convert(value).toString();
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/BooleanPropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/BooleanPropertyState.java?rev=1399669&r1=1399668&r2=1399669&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/BooleanPropertyState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/BooleanPropertyState.java
Thu Oct 18 14:09:02 2012
@@ -19,6 +19,7 @@
 package org.apache.jackrabbit.oak.plugins.memory;
 
 import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.value.Conversions;
 
 import static org.apache.jackrabbit.oak.api.Type.*;
 
@@ -32,7 +33,7 @@ public class BooleanPropertyState extend
 
     @Override
     protected String getString() {
-        return Boolean.toString(value);
+        return Conversions.convert(value).toString();
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/BooleansPropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/BooleansPropertyState.java?rev=1399669&r1=1399668&r2=1399669&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/BooleansPropertyState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/BooleansPropertyState.java
Thu Oct 18 14:09:02 2012
@@ -21,6 +21,7 @@ import java.util.List;
 import com.google.common.base.Function;
 import com.google.common.collect.Iterables;
 import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.value.Conversions;
 
 import static org.apache.jackrabbit.oak.api.Type.BOOLEANS;
 
@@ -34,14 +35,14 @@ public class BooleansPropertyState exten
         return Iterables.transform(values, new Function<Boolean, String>() {
             @Override
             public String apply(Boolean value) {
-                return Boolean.toString(value);
+                return Conversions.convert(value).toString();
             }
         });
     }
 
     @Override
     protected String getString(int index) {
-        return Boolean.toString(values.get(index));
+        return Conversions.convert(values.get(index)).toString();
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/DecimalPropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/DecimalPropertyState.java?rev=1399669&r1=1399668&r2=1399669&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/DecimalPropertyState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/DecimalPropertyState.java
Thu Oct 18 14:09:02 2012
@@ -19,6 +19,7 @@ package org.apache.jackrabbit.oak.plugin
 import java.math.BigDecimal;
 
 import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.value.Conversions;
 
 import static org.apache.jackrabbit.oak.api.Type.*;
 
@@ -37,17 +38,17 @@ public class DecimalPropertyState extend
 
     @Override
     public double getDouble() {
-        return value.doubleValue();
+        return Conversions.convert(value).toDouble();
     }
 
     @Override
     public long getLong() {
-        return value.longValue();
+        return Conversions.convert(value).toLong();
     }
 
     @Override
     public String getString() {
-        return value.toString();
+        return Conversions.convert(value).toString();
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/DecimalsPropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/DecimalsPropertyState.java?rev=1399669&r1=1399668&r2=1399669&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/DecimalsPropertyState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/DecimalsPropertyState.java
Thu Oct 18 14:09:02 2012
@@ -22,6 +22,7 @@ import java.util.List;
 import com.google.common.base.Function;
 import com.google.common.collect.Iterables;
 import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.value.Conversions;
 
 import static org.apache.jackrabbit.oak.api.Type.DECIMALS;
 
@@ -46,14 +47,14 @@ public class DecimalsPropertyState exten
         return Iterables.transform(values, new Function<BigDecimal, Double>() {
             @Override
             public Double apply(BigDecimal value) {
-                return value.doubleValue();
+                return Conversions.convert(value).toDouble();
             }
         });
     }
 
     @Override
     protected double getDouble(int index) {
-        return values.get(index).doubleValue();
+        return Conversions.convert(values.get(index)).toDouble();
     }
 
     @Override
@@ -61,14 +62,14 @@ public class DecimalsPropertyState exten
         return Iterables.transform(values, new Function<BigDecimal, Long>() {
             @Override
             public Long apply(BigDecimal value) {
-                return value.longValue();
+                return Conversions.convert(value).toLong();
             }
         });
     }
 
     @Override
     protected long getLong(int index) {
-        return values.get(index).longValue();
+        return Conversions.convert(values.get(index)).toLong();
     }
 
     @Override
@@ -76,14 +77,14 @@ public class DecimalsPropertyState exten
         return Iterables.transform(values, new Function<BigDecimal, String>() {
             @Override
             public String apply(BigDecimal value) {
-                return value.toString();
+                return Conversions.convert(value).toString();
             }
         });
     }
 
     @Override
     protected String getString(int index) {
-        return values.get(index).toString();
+        return Conversions.convert(values.get(index)).toString();
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/DoublePropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/DoublePropertyState.java?rev=1399669&r1=1399668&r2=1399669&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/DoublePropertyState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/DoublePropertyState.java
Thu Oct 18 14:09:02 2012
@@ -21,6 +21,7 @@ package org.apache.jackrabbit.oak.plugin
 import java.math.BigDecimal;
 
 import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.value.Conversions;
 
 import static org.apache.jackrabbit.oak.api.Type.*;
 
@@ -34,7 +35,7 @@ public class DoublePropertyState extends
 
     @Override
     public BigDecimal getDecimal() {
-        return new BigDecimal(value);
+        return Conversions.convert(value).toDecimal();
     }
 
     @Override
@@ -44,12 +45,12 @@ public class DoublePropertyState extends
 
     @Override
     public long getLong() {
-        return (long) value;
+        return Conversions.convert(value).toLong();
     }
 
     @Override
     public String getString() {
-        return String.valueOf(value);
+        return Conversions.convert(value).toString();
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/DoublesPropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/DoublesPropertyState.java?rev=1399669&r1=1399668&r2=1399669&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/DoublesPropertyState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/DoublesPropertyState.java
Thu Oct 18 14:09:02 2012
@@ -24,6 +24,7 @@ import java.util.List;
 import com.google.common.base.Function;
 import com.google.common.collect.Iterables;
 import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.value.Conversions;
 
 import static org.apache.jackrabbit.oak.api.Type.DOUBLES;
 
@@ -37,14 +38,14 @@ public class DoublesPropertyState extend
         return Iterables.transform(values, new Function<Double, BigDecimal>() {
             @Override
             public BigDecimal apply(Double value) {
-                return new BigDecimal(value);
+                return Conversions.convert(value).toDecimal();
             }
         });
     }
 
     @Override
     protected BigDecimal getDecimal(int index) {
-        return new BigDecimal(values.get(index));
+        return Conversions.convert(values.get(index)).toDecimal();
     }
 
     @Override
@@ -62,14 +63,14 @@ public class DoublesPropertyState extend
         return Iterables.transform(values, new Function<Double, Long>() {
             @Override
             public Long apply(Double value) {
-                return value.longValue();
+                return Conversions.convert(value).toLong();
             }
         });
     }
 
     @Override
     protected long getLong(int index) {
-        return values.get(index).longValue();
+        return Conversions.convert(values.get(index)).toLong();
     }
 
     @Override
@@ -77,14 +78,14 @@ public class DoublesPropertyState extend
         return Iterables.transform(values, new Function<Double, String>() {
             @Override
             public String apply(Double value) {
-                return String.valueOf(value);
+                return Conversions.convert(value).toString();
             }
         });
     }
 
     @Override
     protected String getString(int index) {
-        return String.valueOf(values.get(index));
+        return Conversions.convert(values.get(index)).toString();
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/EmptyPropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/EmptyPropertyState.java?rev=1399669&r1=1399668&r2=1399669&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/EmptyPropertyState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/EmptyPropertyState.java
Thu Oct 18 14:09:02 2012
@@ -18,14 +18,12 @@
  */
 package org.apache.jackrabbit.oak.plugins.memory;
 
-import java.math.BigDecimal;
 import java.util.Collections;
 
 import javax.annotation.Nonnull;
 import javax.jcr.PropertyType;
 
 import com.google.common.collect.Iterables;
-import org.apache.jackrabbit.oak.api.Blob;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Type;
 
@@ -50,66 +48,6 @@ public abstract class EmptyPropertyState
         this.name = name;
     }
 
-    /**
-     * Utility method defining the conversion from {@code String}
-     * to a binary value
-     *
-     * @param value  The string to convert to a binary
-     * @return  The binary value parsed from {@code value}
-     */
-    public static Blob getBinary(String value) {
-        return new StringBasedBlob(value);
-    }
-
-    /**
-     * Utility method defining the conversion from {@code String}
-     * to {@code long}.
-     * @param value  The string to convert to a long
-     * @return  The long value parsed from {@code value}
-     * @throws NumberFormatException  if the string does not contain a
-     * parseable long.
-     */
-    public static long getLong(String value) {
-        return Long.parseLong(value);
-    }
-
-    /**
-     * Utility method defining the conversion from {@code String}
-     * to {@code double}.
-     *
-     * @param value  The string to convert to a double
-     * @return  The double value parsed from {@code value}
-     * @throws NumberFormatException  if the string does not contain a
-     * parseable double.
-     */
-    public static double getDouble(String value) {
-        return Double.parseDouble(value);
-    }
-
-    /**
-     * Utility method defining the conversion from {@code String}
-     * to {@code boolean}.
-     *
-     *
-     * @param value  The string to convert to a boolean
-     * @return  The boolean value parsed from {@code value}
-     */
-    public static boolean getBoolean(String value) {
-        return Boolean.parseBoolean(value);
-    }
-
-    /**
-     * Utility method defining the conversion from {@code String}
-     * to {@code BigDecimal}.
-     * @param value  The string to convert to a BigDecimal
-     * @return  The BigDecimal value parsed from {@code value}
-     * @throws NumberFormatException  if the string does not contain a
-     * parseable BigDecimal.
-     */
-    public static BigDecimal getDecimal(String value) {
-        return new BigDecimal(value);
-    }
-
     @Nonnull
     @Override
     public String getName() {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/LongPropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/LongPropertyState.java?rev=1399669&r1=1399668&r2=1399669&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/LongPropertyState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/LongPropertyState.java
Thu Oct 18 14:09:02 2012
@@ -21,6 +21,7 @@ package org.apache.jackrabbit.oak.plugin
 import java.math.BigDecimal;
 
 import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.value.Conversions;
 
 import static org.apache.jackrabbit.oak.api.Type.*;
 
@@ -34,12 +35,12 @@ public class LongPropertyState extends S
 
     @Override
     public BigDecimal getDecimal() {
-        return new BigDecimal(value);
+        return Conversions.convert(value).toDecimal();
     }
 
     @Override
     public double getDouble() {
-        return value;
+        return Conversions.convert(value).toDouble();
     }
 
     @Override
@@ -49,7 +50,7 @@ public class LongPropertyState extends S
 
     @Override
     public String getString() {
-        return String.valueOf(value);
+        return Conversions.convert(value).toString();
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/LongsPropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/LongsPropertyState.java?rev=1399669&r1=1399668&r2=1399669&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/LongsPropertyState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/LongsPropertyState.java
Thu Oct 18 14:09:02 2012
@@ -24,6 +24,7 @@ import java.util.List;
 import com.google.common.base.Function;
 import com.google.common.collect.Iterables;
 import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.value.Conversions;
 
 import static org.apache.jackrabbit.oak.api.Type.LONGS;
 
@@ -38,14 +39,14 @@ public class LongsPropertyState extends 
         return Iterables.transform(values, new Function<Long, BigDecimal>() {
             @Override
             public BigDecimal apply(Long value) {
-                return new BigDecimal(value);
+                return Conversions.convert(value).toDecimal();
             }
         });
     }
 
     @Override
     protected BigDecimal getDecimal(int index) {
-        return new BigDecimal(values.get(index));
+        return Conversions.convert(values.get(index)).toDecimal();
     }
 
     @Override
@@ -53,14 +54,14 @@ public class LongsPropertyState extends 
         return Iterables.transform(values, new Function<Long, Double>() {
             @Override
             public Double apply(Long value) {
-                return value.doubleValue();
+                return Conversions.convert(value).toDouble();
             }
         });
     }
 
     @Override
     protected double getDouble(int index) {
-        return values.get(index);
+        return Conversions.convert(values.get(index)).toDouble();
     }
 
     @Override
@@ -78,14 +79,14 @@ public class LongsPropertyState extends 
         return Iterables.transform(values, new Function<Long, String>() {
             @Override
             public String apply(Long value) {
-                return String.valueOf(value);
+                return Conversions.convert(value).toString();
             }
         });
     }
 
     @Override
     protected String getString(int index) {
-        return String.valueOf(values.get(index));
+        return Conversions.convert(values.get(index)).toString();
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MultiPropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MultiPropertyState.java?rev=1399669&r1=1399668&r2=1399669&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MultiPropertyState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MultiPropertyState.java
Thu Oct 18 14:09:02 2012
@@ -28,6 +28,7 @@ import com.google.common.base.Function;
 import com.google.common.collect.Iterables;
 import org.apache.jackrabbit.oak.api.Blob;
 import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.value.Conversions;
 
 import static com.google.common.base.Preconditions.checkArgument;
 
@@ -68,7 +69,7 @@ abstract class MultiPropertyState<T> ext
         return Iterables.transform(getStrings(), new Function<String, Blob>() {
             @Override
             public Blob apply(String value) {
-                return EmptyPropertyState.getBinary(value);
+                return Conversions.convert(value).toBinary();
             }
         });
     }
@@ -80,7 +81,7 @@ abstract class MultiPropertyState<T> ext
         return Iterables.transform(getStrings(), new Function<String, Long>() {
             @Override
             public Long apply(String value) {
-                return EmptyPropertyState.getLong(value);
+                return Conversions.convert(value).toLong();
             }
         });
     }
@@ -92,7 +93,7 @@ abstract class MultiPropertyState<T> ext
         return Iterables.transform(getStrings(), new Function<String, Double>() {
             @Override
             public Double apply(String value) {
-                return EmptyPropertyState.getDouble(value);
+                return Conversions.convert(value).toDouble();
             }
         });
     }
@@ -104,7 +105,7 @@ abstract class MultiPropertyState<T> ext
         return Iterables.transform(getStrings(), new Function<String, Boolean>() {
             @Override
             public Boolean apply(String value) {
-                return EmptyPropertyState.getBoolean(value);
+                return Conversions.convert(value).toBoolean();
             }
         });
     }
@@ -116,7 +117,7 @@ abstract class MultiPropertyState<T> ext
         return Iterables.transform(getStrings(), new Function<String, BigDecimal>()
{
             @Override
             public BigDecimal apply(String value) {
-                return EmptyPropertyState.getDecimal(value);
+                return Conversions.convert(value).toDecimal();
             }
         });
     }
@@ -126,7 +127,7 @@ abstract class MultiPropertyState<T> ext
      * @return  The value at the given {@code index} as {@link Blob}
      */
     protected Blob getBlob(int index) {
-        return EmptyPropertyState.getBinary(getString(index));
+        return Conversions.convert(getString(index)).toBinary();
     }
 
     /**
@@ -134,7 +135,7 @@ abstract class MultiPropertyState<T> ext
      * @return  The value at the given {@code index} as {@code long}
      */
     protected long getLong(int index) {
-        return EmptyPropertyState.getLong(getString(index));
+        return Conversions.convert(getString(index)).toLong();
     }
 
     /**
@@ -142,7 +143,7 @@ abstract class MultiPropertyState<T> ext
      * @return  The value at the given {@code index} as {@code double}
      */
     protected double getDouble(int index) {
-        return EmptyPropertyState.getDouble(getString(index));
+        return Conversions.convert(getString(index)).toDouble();
     }
 
     /**
@@ -150,7 +151,7 @@ abstract class MultiPropertyState<T> ext
      * @return  The value at the given {@code index} as {@code boolean}
      */
     protected boolean getBoolean(int index) {
-        return EmptyPropertyState.getBoolean(getString(index));
+        return Conversions.convert(getString(index)).toBoolean();
     }
 
     /**
@@ -158,7 +159,7 @@ abstract class MultiPropertyState<T> ext
      * @return  The value at the given {@code index} as {@code BigDecimal}
      */
     protected BigDecimal getDecimal(int index) {
-        return EmptyPropertyState.getDecimal(getString(index));
+        return Conversions.convert(getString(index)).toDecimal();
     }
 
     /**

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=1399669&r1=1399668&r2=1399669&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
Thu Oct 18 14:09:02 2012
@@ -35,6 +35,7 @@ import org.apache.jackrabbit.oak.api.Pro
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.kernel.KernelBlob;
 import org.apache.jackrabbit.oak.kernel.TypeCodes;
+import org.apache.jackrabbit.oak.value.Conversions;
 
 import static org.apache.jackrabbit.oak.api.Type.DATE;
 import static org.apache.jackrabbit.oak.api.Type.DATES;
@@ -164,15 +165,15 @@ public final class PropertyStates {
             case PropertyType.STRING:
                 return new StringPropertyState(name, value);
             case PropertyType.BINARY:
-                return new BinaryPropertyState(name, EmptyPropertyState.getBinary(value));
+                return new BinaryPropertyState(name, Conversions.convert(value).toBinary());
             case PropertyType.LONG:
-                return new LongPropertyState(name, EmptyPropertyState.getLong(value));
+                return new LongPropertyState(name, Conversions.convert(value).toLong());
             case PropertyType.DOUBLE:
-                return new DoublePropertyState(name, EmptyPropertyState.getDouble(value));
+                return new DoublePropertyState(name, Conversions.convert(value).toDouble());
             case PropertyType.BOOLEAN:
-                return new BooleanPropertyState(name, EmptyPropertyState.getBoolean(value));
+                return new BooleanPropertyState(name, Conversions.convert(value).toBoolean());
             case PropertyType.DECIMAL:
-                return new DecimalPropertyState(name, EmptyPropertyState.getDecimal(value));
+                return new DecimalPropertyState(name, Conversions.convert(value).toDecimal());
             default:
                 return new GenericPropertyState(name, value, Type.fromTag(type, false));
         }
@@ -619,7 +620,7 @@ public final class PropertyStates {
             if (reader.matches(JsopReader.NUMBER)) {
                 String number = reader.getToken();
                 type = PropertyType.LONG;
-                values.add(EmptyPropertyState.getLong(number));
+                values.add(Conversions.convert(number).toLong());
             } else if (reader.matches(JsopReader.TRUE)) {
                 type = PropertyType.BOOLEAN;
                 values.add(true);
@@ -634,9 +635,9 @@ public final class PropertyStates {
                     if (type == PropertyType.BINARY) {
                         values.add(new KernelBlob(value, kernel));
                     } else if(type == PropertyType.DOUBLE) {
-                        values.add(EmptyPropertyState.getDouble(value));
+                        values.add(Conversions.convert(value).toDouble());
                     } else if(type == PropertyType.DECIMAL) {
-                        values.add(EmptyPropertyState.getDecimal(value));
+                        values.add(Conversions.convert(value).toDecimal());
                     } else {
                         values.add(value);
                     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/SinglePropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/SinglePropertyState.java?rev=1399669&r1=1399668&r2=1399669&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/SinglePropertyState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/SinglePropertyState.java
Thu Oct 18 14:09:02 2012
@@ -25,6 +25,7 @@ import javax.jcr.PropertyType;
 
 import org.apache.jackrabbit.oak.api.Blob;
 import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.value.Conversions;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static java.util.Collections.singleton;
@@ -53,35 +54,35 @@ abstract class SinglePropertyState exten
      * {@link #getString()}.
      */
     protected Blob getBlob() {
-        return getBinary(getString());
+        return Conversions.convert(getString()).toBinary();
     }
 
     /**
      * @return  {@code getLong(getString())}
      */
     protected long getLong() {
-        return getLong(getString());
+        return Conversions.convert(getString()).toLong();
     }
 
     /**
      * @return  {@code getDouble(getString())}
      */
     protected double getDouble() {
-        return getDouble(getString());
+        return Conversions.convert(getString()).toDouble();
     }
 
     /**
      * @return  {@code StringPropertyState.getBoolean(getString())}
      */
     protected boolean getBoolean() {
-        return getBoolean(getString());
+        return Conversions.convert(getString()).toBoolean();
     }
 
     /**
      * @return  {@code getDecimal(getString())}
      */
     protected BigDecimal getDecimal() {
-        return getDecimal(getString());
+        return Conversions.convert(getString()).toDecimal();
     }
 
     /**

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value/Conversions.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value/Conversions.java?rev=1399669&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value/Conversions.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value/Conversions.java
Thu Oct 18 14:09:02 2012
@@ -0,0 +1,260 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.jackrabbit.oak.value;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.math.BigDecimal;
+
+import com.google.common.io.ByteStreams;
+import org.apache.jackrabbit.oak.api.Blob;
+import org.apache.jackrabbit.oak.plugins.memory.StringBasedBlob;
+
+/**
+ * Utility class defining the conversion that take place between {@link org.apache.jackrabbit.oak.api.PropertyState}s
+ * of different types.
+ * <p>
+ * Example:
+ * <pre>
+ *    double three = convert("3.0").toDouble();
+ * </pre>
+ */
+public final class Conversions {
+    private Conversions() {}
+
+    /**
+     * A converter converts a value to its representation as a specific target type. Not
all target
+     * types might be supported for a given value in which case implementations throw an
exception.
+     * The default implementations of the various conversion methods all operate on the string
+     * representation of the underlying value (i.e. call {@code Converter.toString()}.
+     */
+    public abstract static class Converter {
+
+        /**
+         * Convert to string
+         * @return  string representation of the converted value
+         */
+        public abstract String toString();
+
+        /**
+         * Convert to binary. This default implementation returns an new instance
+         * of {@link StringBasedBlob}.
+         * @return  binary representation of the converted value
+         */
+        public Blob toBinary() {
+            return new StringBasedBlob(toString());
+        }
+
+        /**
+         * Convert to long. This default implementation is based on {@code Long.parseLong(String)}.
+         * @return  long representation of the converted value
+         * @throws NumberFormatException
+         */
+        public long toLong() {
+            return Long.parseLong(toString());
+        }
+
+        /**
+         * Convert to double. This default implementation is based on {@code Double.parseDouble(String)}.
+         * @return  double representation of the converted value
+         * @throws NumberFormatException
+         */
+        public double toDouble() {
+            return Double.parseDouble(toString());
+        }
+
+        /**
+         * Convert to boolean. This default implementation is based on {@code Boolean.parseBoolean(String)}.
+         * @return  boolean representation of the converted value
+         */
+        public boolean toBoolean() {
+            return Boolean.parseBoolean(toString());
+        }
+
+        /**
+         * Convert to decimal. This default implementation is based on {@code new BigDecimal(String)}.
+         * @return  decimal representation of the converted value
+         * @throws NumberFormatException
+         */
+        public BigDecimal toDecimal() {
+            return new BigDecimal(toString());
+        }
+    }
+
+    /**
+     * Create a converter for a string.
+     * @param value  The string to convert
+     * @return  A converter for {@code value}
+     * @throws NumberFormatException
+     */
+    public static Converter convert(final String value) {
+        return new Converter() {
+            @Override
+            public String toString() {
+                return value;
+            }
+        };
+    }
+
+    /**
+     * Create a converter for a binary.
+     * For the conversion to {@code String} the binary in interpreted as UTF-8 encoded string.
+     * @param value  The binary to convert
+     * @return  A converter for {@code value}
+     * @throws IllegalArgumentException  if the binary is inaccessible
+     */
+    public static Converter convert(final Blob value) {
+        return new Converter() {
+            @Override
+            public String toString() {
+                try {
+                    InputStream in = value.getNewStream();
+                    try {
+                        return new String(ByteStreams.toByteArray(in), "UTF-8");
+                    }
+                    finally {
+                        in.close();
+                    }
+                }
+                catch (IOException e) {
+                    throw new IllegalArgumentException(e);
+                }
+            }
+
+            @Override
+            public Blob toBinary() {
+                return value;
+            }
+        };
+    }
+
+    /**
+     * Create a converter for a long. {@code String.valueOf(long)} is used for the conversion
to {@code String}.
+     * The conversions to {@code double} and {@code long} return the {@code value} itself.
+     * The conversion to decimal uses {@code new BigDecimal(long)}.
+     * @param value  The long to convert
+     * @return  A converter for {@code value}
+     */
+    public static Converter convert(final long value) {
+        return new Converter() {
+            @Override
+            public String toString() {
+                return String.valueOf(value);
+            }
+
+            @Override
+            public long toLong() {
+                return value;
+            }
+
+            @Override
+            public double toDouble() {
+                return value;
+            }
+
+            @Override
+            public BigDecimal toDecimal() {
+                return new BigDecimal(value);
+            }
+        };
+    }
+
+    /**
+     * Create a converter for a double. {@code String.valueOf(double)} is used for the conversion
to {@code String}.
+     * The conversions to {@code double} and {@code long} return the {@code value} itself
where in the former case
+     * the value is casted to {@code long}.
+     * The conversion to decimal uses {@code new BigDecimal(double)}.
+     * @param value  The double to convert
+     * @return  A converter for {@code value}
+     */
+    public static Converter convert(final double value) {
+        return new Converter() {
+            @Override
+            public String toString() {
+                return String.valueOf(value);
+            }
+
+            @Override
+            public long toLong() {
+                return (long) value;
+            }
+
+            @Override
+            public double toDouble() {
+                return value;
+            }
+
+            @Override
+            public BigDecimal toDecimal() {
+                return new BigDecimal(value);
+            }
+        };
+    }
+
+    /**
+     * Create a converter for a boolean. {@code Boolean.toString(boolean)} is used for the
conversion to {@code String}.
+     * @param value  The boolean to convert
+     * @return  A converter for {@code value}
+     */
+    public static Converter convert(final boolean value) {
+        return new Converter() {
+            @Override
+            public String toString() {
+                return Boolean.toString(value);
+            }
+
+            @Override
+            public boolean toBoolean() {
+                return value;
+            }
+        };
+    }
+
+    /**
+     * Create a converter for a decimal. {@code BigDecimal.toString()} is used for the conversion
to {@code String}.
+     * {@code BigDecimal.longValue()} and {@code BigDecimal.doubleValue()} is used for the
conversions to
+     * {@code long} and {@code double}, respectively.
+     * @param value  The decimal to convert
+     * @return  A converter for {@code value}
+     */
+    public static Converter convert(final BigDecimal value) {
+        return new Converter() {
+            @Override
+            public String toString() {
+                return value.toString();
+            }
+
+            @Override
+            public long toLong() {
+                return value.longValue();
+            }
+
+            @Override
+            public double toDouble() {
+                return value.doubleValue();
+            }
+
+            @Override
+            public BigDecimal toDecimal() {
+                return value;
+            }
+        };
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value/Conversions.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/value/Conversions.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

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=1399669&r1=1399668&r2=1399669&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
Thu Oct 18 14:09:02 2012
@@ -40,7 +40,6 @@ import org.apache.jackrabbit.oak.api.Pro
 import org.apache.jackrabbit.oak.api.PropertyValue;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
 import org.apache.jackrabbit.oak.plugins.identifier.IdentifierManager;
-import org.apache.jackrabbit.oak.plugins.memory.EmptyPropertyState;
 import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
 import org.apache.jackrabbit.oak.spi.query.PropertyValues;
 import org.apache.jackrabbit.util.ISO8601;
@@ -193,9 +192,9 @@ public class ValueFactoryImpl implements
                     pv = PropertyStates.binaryProperty("", value.getBytes("UTF-8"));
                     break;
                 case PropertyType.LONG:
-                    return createValue(EmptyPropertyState.getLong(value));
+                    return createValue(Conversions.convert(value).toLong());
                 case PropertyType.DOUBLE:
-                    return createValue(EmptyPropertyState.getDouble(value));
+                    return createValue(Conversions.convert(value).toDouble());
                 case PropertyType.DATE:
                     if (ISO8601.parse(value) == null) {
                         throw new ValueFormatException("Invalid date " + value);
@@ -203,7 +202,7 @@ public class ValueFactoryImpl implements
                     pv = PropertyStates.dateProperty("", value);
                     break;
                 case PropertyType.BOOLEAN:
-                    return createValue(EmptyPropertyState.getBoolean(value));
+                    return createValue(Conversions.convert(value).toBoolean());
                 case PropertyType.NAME:
                     String oakName = namePathMapper.getOakName(value);
                     if (oakName == null) {
@@ -240,7 +239,7 @@ public class ValueFactoryImpl implements
                     pv = PropertyStates.uriProperty("", value);
                     break;
                 case PropertyType.DECIMAL:
-                    return createValue(EmptyPropertyState.getDecimal(value));
+                    return createValue(Conversions.convert(value).toDecimal());
                 default:
                     throw new ValueFormatException("Invalid type: " + type);
             }



Mime
View raw message