jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1400897 - /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/
Date Mon, 22 Oct 2012 14:40:46 GMT
Author: mduerig
Date: Mon Oct 22 14:40:45 2012
New Revision: 1400897

URL: http://svn.apache.org/viewvc?rev=1400897&view=rev
Log:
OAK-380: Define conversion of property values
refactor property state conversions

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/GenericPropertyState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/GenericsPropertyState.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/SinglePropertyState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/StringPropertyState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/StringsPropertyState.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=1400897&r1=1400896&r2=1400897&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 Mon Oct 22 14:40:45 2012
@@ -16,43 +16,21 @@
  */
 package org.apache.jackrabbit.oak.plugins.memory;
 
-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.plugins.value.Conversions;
+import org.apache.jackrabbit.oak.plugins.value.Conversions.Converter;
 
 import static org.apache.jackrabbit.oak.api.Type.BINARIES;
 
 public class BinariesPropertyState extends MultiPropertyState<Blob> {
-
-    protected BinariesPropertyState(String name, Iterable<Blob> values) {
+    public BinariesPropertyState(String name, Iterable<Blob> values) {
         super(name, values);
     }
 
     @Override
-    protected Iterable<String> getStrings() {
-        return Iterables.transform(values, new Function<Blob, String>() {
-            @Override
-            public String apply(Blob value) {
-                return Conversions.convert(value).toString();
-            }
-        });
-    }
-
-    @Override
-    protected String getString(int index) {
-        return Conversions.convert(values.get(index)).toString();
-    }
-
-    @Override
-    protected Iterable<Blob> getBlobs() {
-        return values;
-    }
-
-    @Override
-    protected Blob getBlob(int index) {
-        return values.get(index);
+    public Converter getConverter(Blob value) {
+        return Conversions.convert(value);
     }
 
     @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=1400897&r1=1400896&r2=1400897&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 Mon Oct 22 14:40:45 2012
@@ -19,23 +19,24 @@ 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.plugins.value.Conversions;
+import org.apache.jackrabbit.oak.plugins.value.Conversions.Converter;
 
-public class BinaryPropertyState extends SinglePropertyState {
+public class BinaryPropertyState extends SinglePropertyState<Blob> {
     private final Blob value;
 
-    protected BinaryPropertyState(String name, Blob value) {
+    public BinaryPropertyState(String name, Blob value) {
         super(name);
         this.value = value;
     }
 
     @Override
-    public String getString() {
-        return Conversions.convert(value).toString();
+    public Blob getValue() {
+        return value;
     }
 
     @Override
-    protected Blob getBlob() {
-        return value;
+    public Converter getConverter() {
+        return Conversions.convert(value);
     }
 
     @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=1400897&r1=1400896&r2=1400897&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 Mon Oct 22 14:40:45 2012
@@ -20,25 +20,26 @@ package org.apache.jackrabbit.oak.plugin
 
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.plugins.value.Conversions;
+import org.apache.jackrabbit.oak.plugins.value.Conversions.Converter;
 
 import static org.apache.jackrabbit.oak.api.Type.*;
 
-public class BooleanPropertyState extends SinglePropertyState {
+public class BooleanPropertyState extends SinglePropertyState<Boolean> {
     private final boolean value;
 
-    protected BooleanPropertyState(String name, boolean value) {
+    public BooleanPropertyState(String name, boolean value) {
         super(name);
         this.value = value;
     }
 
     @Override
-    protected String getString() {
-        return Conversions.convert(value).toString();
+    public Boolean getValue() {
+        return value;
     }
 
     @Override
-    protected boolean getBoolean() {
-        return value;
+    public Converter getConverter() {
+        return Conversions.convert(value);
     }
 
     @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=1400897&r1=1400896&r2=1400897&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 Mon Oct 22 14:40:45 2012
@@ -16,41 +16,20 @@
  */
 package org.apache.jackrabbit.oak.plugins.memory;
 
-import com.google.common.base.Function;
-import com.google.common.collect.Iterables;
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.plugins.value.Conversions;
+import org.apache.jackrabbit.oak.plugins.value.Conversions.Converter;
 
 import static org.apache.jackrabbit.oak.api.Type.BOOLEANS;
 
 public class BooleansPropertyState extends MultiPropertyState<Boolean> {
-    protected BooleansPropertyState(String name, Iterable<Boolean> values) {
+    public BooleansPropertyState(String name, Iterable<Boolean> values) {
         super(name, values);
     }
 
     @Override
-    protected Iterable<String> getStrings() {
-        return Iterables.transform(values, new Function<Boolean, String>() {
-            @Override
-            public String apply(Boolean value) {
-                return Conversions.convert(value).toString();
-            }
-        });
-    }
-
-    @Override
-    protected String getString(int index) {
-        return Conversions.convert(values.get(index)).toString();
-    }
-
-    @Override
-    protected Iterable<Boolean> getBooleans() {
-        return values;
-    }
-
-    @Override
-    protected boolean getBoolean(int index) {
-        return values.get(index);
+    public Converter getConverter(Boolean value) {
+        return Conversions.convert(value);
     }
 
     @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=1400897&r1=1400896&r2=1400897&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 Mon Oct 22 14:40:45 2012
@@ -20,40 +20,26 @@ import java.math.BigDecimal;
 
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.plugins.value.Conversions;
+import org.apache.jackrabbit.oak.plugins.value.Conversions.Converter;
 
 import static org.apache.jackrabbit.oak.api.Type.DECIMAL;
 
-public class DecimalPropertyState extends SinglePropertyState {
+public class DecimalPropertyState extends SinglePropertyState<BigDecimal> {
     private final BigDecimal value;
 
-    protected DecimalPropertyState(String name, BigDecimal value) {
+    public DecimalPropertyState(String name, BigDecimal value) {
         super(name);
         this.value = value;
     }
 
     @Override
-    public BigDecimal getDecimal() {
+    public BigDecimal getValue() {
         return value;
     }
 
     @Override
-    public double getDouble() {
-        return Conversions.convert(value).toDouble();
-    }
-
-    @Override
-    public long getLong() {
-        return Conversions.convert(value).toLong();
-    }
-
-    @Override
-    protected String getDate() {
-        return Conversions.convert(value).toDate();
-    }
-
-    @Override
-    public String getString() {
-        return Conversions.convert(value).toString();
+    public Converter getConverter() {
+        return Conversions.convert(value);
     }
 
     @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=1400897&r1=1400896&r2=1400897&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 Mon Oct 22 14:40:45 2012
@@ -18,87 +18,20 @@ package org.apache.jackrabbit.oak.plugin
 
 import java.math.BigDecimal;
 
-import com.google.common.base.Function;
-import com.google.common.collect.Iterables;
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.plugins.value.Conversions;
+import org.apache.jackrabbit.oak.plugins.value.Conversions.Converter;
 
 import static org.apache.jackrabbit.oak.api.Type.DECIMALS;
 
 public class DecimalsPropertyState extends MultiPropertyState<BigDecimal> {
-
-    protected DecimalsPropertyState(String name, Iterable<BigDecimal> values) {
+    public DecimalsPropertyState(String name, Iterable<BigDecimal> values) {
         super(name, values);
     }
 
     @Override
-    protected Iterable<BigDecimal> getDecimals() {
-        return values;
-    }
-
-    @Override
-    protected BigDecimal getDecimal(int index) {
-        return values.get(index);
-    }
-
-    @Override
-    protected Iterable<Double> getDoubles() {
-        return Iterables.transform(values, new Function<BigDecimal, Double>() {
-            @Override
-            public Double apply(BigDecimal value) {
-                return Conversions.convert(value).toDouble();
-            }
-        });
-    }
-
-    @Override
-    protected Iterable<String> getDates() {
-        return Iterables.transform(values, new Function<BigDecimal, String>() {
-            @Override
-            public String apply(BigDecimal value) {
-                return Conversions.convert(value).toDate();
-            }
-        });
-    }
-
-    @Override
-    protected double getDouble(int index) {
-        return Conversions.convert(values.get(index)).toDouble();
-    }
-
-    @Override
-    protected String getDate(int index) {
-        return Conversions.convert(values.get(index)).toDate();
-    }
-
-    @Override
-    protected Iterable<Long> getLongs() {
-        return Iterables.transform(values, new Function<BigDecimal, Long>() {
-            @Override
-            public Long apply(BigDecimal value) {
-                return Conversions.convert(value).toLong();
-            }
-        });
-    }
-
-    @Override
-    protected long getLong(int index) {
-        return Conversions.convert(values.get(index)).toLong();
-    }
-
-    @Override
-    protected Iterable<String> getStrings() {
-        return Iterables.transform(values, new Function<BigDecimal, String>() {
-            @Override
-            public String apply(BigDecimal value) {
-                return Conversions.convert(value).toString();
-            }
-        });
-    }
-
-    @Override
-    protected String getString(int index) {
-        return Conversions.convert(values.get(index)).toString();
+    public Converter getConverter(BigDecimal value) {
+        return Conversions.convert(value);
     }
 
     @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=1400897&r1=1400896&r2=1400897&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 Mon Oct 22 14:40:45 2012
@@ -18,44 +18,28 @@
  */
 package org.apache.jackrabbit.oak.plugins.memory;
 
-import java.math.BigDecimal;
-
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.plugins.value.Conversions;
+import org.apache.jackrabbit.oak.plugins.value.Conversions.Converter;
 
 import static org.apache.jackrabbit.oak.api.Type.DOUBLE;
 
-public class DoublePropertyState extends SinglePropertyState {
+public class DoublePropertyState extends SinglePropertyState<Double> {
     private final double value;
 
-    protected DoublePropertyState(String name, double value) {
+    public DoublePropertyState(String name, double value) {
         super(name);
         this.value = value;
     }
 
     @Override
-    public BigDecimal getDecimal() {
-        return Conversions.convert(value).toDecimal();
-    }
-
-    @Override
-    public double getDouble() {
+    public Double getValue() {
         return value;
     }
 
     @Override
-    public long getLong() {
-        return Conversions.convert(value).toLong();
-    }
-
-    @Override
-    protected String getDate() {
-        return Conversions.convert(value).toDate();
-    }
-
-    @Override
-    public String getString() {
-        return Conversions.convert(value).toString();
+    public Converter getConverter() {
+        return Conversions.convert(value);
     }
 
     @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=1400897&r1=1400896&r2=1400897&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 Mon Oct 22 14:40:45 2012
@@ -18,86 +18,20 @@
  */
 package org.apache.jackrabbit.oak.plugins.memory;
 
-import java.math.BigDecimal;
-
-import com.google.common.base.Function;
-import com.google.common.collect.Iterables;
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.plugins.value.Conversions;
+import org.apache.jackrabbit.oak.plugins.value.Conversions.Converter;
 
 import static org.apache.jackrabbit.oak.api.Type.DOUBLES;
 
 public class DoublesPropertyState extends MultiPropertyState<Double> {
-    protected DoublesPropertyState(String name, Iterable<Double>values) {
+    public DoublesPropertyState(String name, Iterable<Double>values) {
         super(name, values);
     }
 
     @Override
-    protected Iterable<BigDecimal> getDecimals() {
-        return Iterables.transform(values, new Function<Double, BigDecimal>() {
-            @Override
-            public BigDecimal apply(Double value) {
-                return Conversions.convert(value).toDecimal();
-            }
-        });
-    }
-
-    @Override
-    protected BigDecimal getDecimal(int index) {
-        return Conversions.convert(values.get(index)).toDecimal();
-    }
-
-    @Override
-    protected Iterable<Double> getDoubles() {
-        return values;
-    }
-
-    @Override
-    protected Iterable<String> getDates() {
-        return Iterables.transform(values, new Function<Double, String>() {
-            @Override
-            public String apply(Double value) {
-                return Conversions.convert(value).toDate();
-            }
-        });
-    }
-    @Override
-    protected double getDouble(int index) {
-        return values.get(index);
-    }
-
-    @Override
-    protected String getDate(int index) {
-        return Conversions.convert(values.get(index)).toDate();    }
-
-    @Override
-    protected Iterable<Long> getLongs() {
-        return Iterables.transform(values, new Function<Double, Long>() {
-            @Override
-            public Long apply(Double value) {
-                return Conversions.convert(value).toLong();
-            }
-        });
-    }
-
-    @Override
-    protected long getLong(int index) {
-        return Conversions.convert(values.get(index)).toLong();
-    }
-
-    @Override
-    protected Iterable<String> getStrings() {
-        return Iterables.transform(values, new Function<Double, String>() {
-            @Override
-            public String apply(Double value) {
-                return Conversions.convert(value).toString();
-            }
-        });
-    }
-
-    @Override
-    protected String getString(int index) {
-        return Conversions.convert(values.get(index)).toString();
+    public Converter getConverter(Double value) {
+        return Conversions.convert(value);
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/GenericPropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/GenericPropertyState.java?rev=1400897&r1=1400896&r2=1400897&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/GenericPropertyState.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/GenericPropertyState.java Mon Oct 22 14:40:45 2012
@@ -17,17 +17,19 @@
 package org.apache.jackrabbit.oak.plugins.memory;
 
 import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.plugins.value.Conversions;
+import org.apache.jackrabbit.oak.plugins.value.Conversions.Converter;
 
 import static com.google.common.base.Preconditions.checkArgument;
 
-public class GenericPropertyState extends SinglePropertyState {
+public class GenericPropertyState extends SinglePropertyState<String> {
     private final String value;
     private final Type<?> type;
 
     /**
      * @throws IllegalArgumentException if {@code type.isArray()} is {@code true}
      */
-    protected GenericPropertyState(String name, String value, Type<?> type) {
+    public GenericPropertyState(String name, String value, Type<?> type) {
         super(name);
         checkArgument(!type.isArray());
         this.value = value;
@@ -35,11 +37,16 @@ public class GenericPropertyState extend
     }
 
     @Override
-    protected String getString() {
+    public String getValue() {
         return value;
     }
 
     @Override
+    public Converter getConverter() {
+        return Conversions.convert(value);
+    }
+
+    @Override
     public Type<?> getType() {
         return type;
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/GenericsPropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/GenericsPropertyState.java?rev=1400897&r1=1400896&r2=1400897&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/GenericsPropertyState.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/GenericsPropertyState.java Mon Oct 22 14:40:45 2012
@@ -19,6 +19,8 @@
 package org.apache.jackrabbit.oak.plugins.memory;
 
 import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.plugins.value.Conversions;
+import org.apache.jackrabbit.oak.plugins.value.Conversions.Converter;
 
 import static com.google.common.base.Preconditions.checkArgument;
 
@@ -28,20 +30,15 @@ public class GenericsPropertyState exten
     /**
      * @throws IllegalArgumentException if {@code type.isArray()} is {@code false}
      */
-    protected GenericsPropertyState(String name, Iterable<String> values, Type<?> type) {
+    public GenericsPropertyState(String name, Iterable<String> values, Type<?> type) {
         super(name, values);
         checkArgument(type.isArray());
         this.type = type;
     }
 
     @Override
-    protected Iterable<String> getStrings() {
-        return values;
-    }
-
-    @Override
-    protected String getString(int index) {
-        return values.get(index);
+    public Converter getConverter(String value) {
+        return Conversions.convert(value);
     }
 
     @Override

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=1400897&r1=1400896&r2=1400897&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 Mon Oct 22 14:40:45 2012
@@ -18,13 +18,13 @@
  */
 package org.apache.jackrabbit.oak.plugins.memory;
 
-import java.math.BigDecimal;
 import java.util.Calendar;
 
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.plugins.value.Conversions;
+import org.apache.jackrabbit.oak.plugins.value.Conversions.Converter;
 
-public class LongPropertyState extends SinglePropertyState {
+public class LongPropertyState extends SinglePropertyState<Long> {
     private final long value;
     private final Type<?> type;
 
@@ -34,47 +34,60 @@ public class LongPropertyState extends S
         this.type = type;
     }
 
+    /**
+     * 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 LongPropertyState createLongProperty(String name, long value) {
         return new LongPropertyState(name, value, Type.LONG);
     }
 
+    /**
+     * Create a {@code PropertyState} for a date value 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#DATE}
+     */
     public static LongPropertyState createDateProperty(String name, long value) {
         return new LongPropertyState(name, value, Type.DATE);
     }
 
+    /**
+     * Create a {@code PropertyState} for a date.
+     * @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 LongPropertyState createDateProperty(String name, Calendar value) {
         return new LongPropertyState(name, Conversions.convert(value).toLong(), Type.DATE);
     }
 
+    /**
+     * Create a {@code PropertyState} for a date 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#DATE}
+     * @throws IllegalArgumentException if {@code value} is not a parseable to a date.
+     */
     public static LongPropertyState createDateProperty(String name, String value) {
         return createDateProperty(name, Conversions.convert(value).toCalendar());
     }
 
     @Override
-    public BigDecimal getDecimal() {
-        return Conversions.convert(value).toDecimal();
-    }
-
-    @Override
-    public double getDouble() {
-        return Conversions.convert(value).toDouble();
-    }
-
-    @Override
-    public long getLong() {
+    public Long getValue() {
         return value;
     }
 
     @Override
-    protected String getDate() {
-        return Conversions.convert(value).toDate();
-    }
-
-    @Override
-    public String getString() {
-        return type == Type.LONG
-            ? Conversions.convert(value).toString()
-            : getDate();
+    public Converter getConverter() {
+        if (type == Type.DATE) {
+            return Conversions.convert(Conversions.convert(value).toCalendar());
+        }
+        else {
+            return Conversions.convert(value);
+        }
     }
 
     @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=1400897&r1=1400896&r2=1400897&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 Mon Oct 22 14:40:45 2012
@@ -18,15 +18,13 @@
  */
 package org.apache.jackrabbit.oak.plugins.memory;
 
-import java.math.BigDecimal;
 import java.util.Calendar;
 import java.util.List;
 
-import com.google.common.base.Function;
-import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.plugins.value.Conversions;
+import org.apache.jackrabbit.oak.plugins.value.Conversions.Converter;
 
 public class LongsPropertyState extends MultiPropertyState<Long> {
     private final Type<?> type;
@@ -36,14 +34,32 @@ public class LongsPropertyState extends 
         this.type = type;
     }
 
+    /**
+     * 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 LongsPropertyState createLongsProperty(String name, Iterable<Long> values) {
         return new LongsPropertyState(name, Lists.newArrayList(values), Type.LONGS);
     }
 
+    /**
+     * Create a multi valued {@code PropertyState} of dates 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#DATES}
+     */
     public static LongsPropertyState createDatesPropertyFromLong(String name, Iterable<Long> values) {
         return new LongsPropertyState(name, Lists.newArrayList(values), Type.DATES);
     }
 
+    /**
+     * Create a multi valued {@code PropertyState} of dates.
+     * @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 LongsPropertyState createDatesPropertyFromCalendar(String name, Iterable<Calendar> values) {
         List<Long> dates = Lists.newArrayList();
         for (Calendar v : values) {
@@ -52,97 +68,32 @@ public class LongsPropertyState extends 
         return new LongsPropertyState(name, dates, Type.DATES);
     }
 
+    /**
+     * Create a multi valued {@code PropertyState} of dates 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#DATES}
+     * @throws IllegalArgumentException if one of the {@code values} is not a parseable to a date.
+     */
     public static LongsPropertyState createDatesProperty(String name, Iterable<String> values) {
-        List<Calendar> dates = Lists.newArrayList();
+        List<Long> dates = Lists.newArrayList();
         for (String v : values) {
-            dates.add(Conversions.convert(v).toCalendar());
+            dates.add(Conversions.convert(Conversions.convert(v).toCalendar()).toLong());
         }
-        return createDatesPropertyFromCalendar(name, dates);
-    }
-
-    @Override
-    protected Iterable<BigDecimal> getDecimals() {
-        return Iterables.transform(values, new Function<Long, BigDecimal>() {
-            @Override
-            public BigDecimal apply(Long value) {
-                return Conversions.convert(value).toDecimal();
-            }
-        });
-    }
-
-    @Override
-    protected BigDecimal getDecimal(int index) {
-        return Conversions.convert(values.get(index)).toDecimal();
-    }
-
-    @Override
-    protected Iterable<Double> getDoubles() {
-        return Iterables.transform(values, new Function<Long, Double>() {
-            @Override
-            public Double apply(Long value) {
-                return Conversions.convert(value).toDouble();
-            }
-        });
-    }
-
-    @Override
-    protected Iterable<String> getDates() {
-        return Iterables.transform(values, new Function<Long, String>() {
-            @Override
-            public String apply(Long value) {
-                return Conversions.convert(value).toDate();
-            }
-        });
-    }
-
-    @Override
-    protected double getDouble(int index) {
-        return Conversions.convert(values.get(index)).toDouble();
-    }
-
-    @Override
-    protected String getDate(int index) {
-        return Conversions.convert(values.get(index)).toDate();
-    }
-
-    @Override
-    protected Iterable<Long> getLongs() {
-        return values;
-    }
-
-    @Override
-    protected long getLong(int index) {
-        return values.get(index);
+        return new LongsPropertyState(name, dates, Type.DATES);
     }
 
     @Override
-    protected Iterable<String> getStrings() {
+    public Converter getConverter(Long value) {
         if (type == Type.DATES) {
-            return Iterables.transform(values, new Function<Long, String>() {
-                @Override
-                public String apply(Long value) {
-                    return Conversions.convert(value).toDate();
-                }
-            });
+            return Conversions.convert(Conversions.convert(value).toCalendar());
         }
         else {
-            return Iterables.transform(values, new Function<Long, String>() {
-                @Override
-                public String apply(Long value) {
-                    return Conversions.convert(value).toString();
-                }
-            });
+            return Conversions.convert(value);
         }
     }
 
     @Override
-    protected String getString(int index) {
-        return (type == Type.DATES)
-            ? getDate(index)
-            : Conversions.convert(values.get(index)).toString();
-    }
-
-    @Override
     public Type<?> getType() {
         return type;
     }

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=1400897&r1=1400896&r2=1400897&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 Mon Oct 22 14:40:45 2012
@@ -29,7 +29,7 @@ import com.google.common.collect.Iterabl
 import com.google.common.collect.Lists;
 import org.apache.jackrabbit.oak.api.Blob;
 import org.apache.jackrabbit.oak.api.Type;
-import org.apache.jackrabbit.oak.plugins.value.Conversions;
+import org.apache.jackrabbit.oak.plugins.value.Conversions.Converter;
 
 import static com.google.common.base.Preconditions.checkArgument;
 
@@ -51,136 +51,101 @@ abstract class MultiPropertyState<T> ext
     }
 
     /**
-     * @return  {@code Iterable} of the string representations of the values
-     * of the property state.
+     * Create a converter for converting a value to other types.
+     * @param  value  The value to convert
+     * @return  A converter for the value of this property
      */
-    protected abstract Iterable<String> getStrings();
+    public abstract Converter getConverter(T value);
 
-    /**
-     * @param index
-     * @return  String representation of the value at {@code index }of the
-     * property state.
-     */
-    protected abstract String getString(int index);
-
-    /**
-     * @return  The values of this property state as {@link Blob}s
-     */
-    protected Iterable<Blob> getBlobs() {
-        return Iterables.transform(getStrings(), new Function<String, Blob>() {
-            @Override
-            public Blob apply(String value) {
-                return Conversions.convert(value).toBinary();
-            }
-        });
-    }
-
-    /**
-     * @return  The values of this property state as {@code Long}s
-     */
-    protected Iterable<Long> getLongs() {
-        return Iterables.transform(getStrings(), new Function<String, Long>() {
-            @Override
-            public Long apply(String value) {
-                return Conversions.convert(value).toLong();
-            }
-        });
-    }
-
-    /**
-     * @return  The values of this property state as {@code Double}s
-     */
-    protected Iterable<Double> getDoubles() {
-        return Iterables.transform(getStrings(), new Function<String, Double>() {
-            @Override
-            public Double apply(String value) {
-                return Conversions.convert(value).toDouble();
-            }
-        });
-    }
-
-    /**
-     * @return  The values of this property state as {@code Dates}s
-     */
-    protected Iterable<String> getDates() {
-        return Iterables.transform(getStrings(), new Function<String, String>() {
-            @Override
-            public String apply(String value) {
-                return Conversions.convert(value).toDate();
-            }
-        });
-    }
-
-    /**
-     * @return  The values of this property state as {@code Booleans}s
-     */
-    protected Iterable<Boolean> getBooleans() {
-        return Iterables.transform(getStrings(), new Function<String, Boolean>() {
-            @Override
-            public Boolean apply(String value) {
-                return Conversions.convert(value).toBoolean();
-            }
-        });
-    }
-
-    /**
-     * @return  The values of this property state as {@code BigDecimal}s
-     */
-    protected Iterable<BigDecimal> getDecimals() {
-        return Iterables.transform(getStrings(), new Function<String, BigDecimal>() {
-            @Override
-            public BigDecimal apply(String value) {
-                return Conversions.convert(value).toDecimal();
-            }
-        });
-    }
-
-    /**
-     * @param index
-     * @return  The value at the given {@code index} as {@link Blob}
-     */
-    protected Blob getBlob(int index) {
-        return Conversions.convert(getString(index)).toBinary();
-    }
-
-    /**
-     * @param index
-     * @return  The value at the given {@code index} as {@code long}
-     */
-    protected long getLong(int index) {
-        return Conversions.convert(getString(index)).toLong();
-    }
-
-    /**
-     * @param index
-     * @return  The value at the given {@code index} as {@code double}
-     */
-    protected double getDouble(int index) {
-        return Conversions.convert(getString(index)).toDouble();
-    }
-
-    /**
-     * @param index
-     * @return  The value at the given {@code index} as {@code date}
-     */
-    protected String getDate(int index) {
-        return Conversions.convert(getString(index)).toDate();
-    }
-
-    /**
-     * @param index
-     * @return  The value at the given {@code index} as {@code boolean}
-     */
-    protected boolean getBoolean(int index) {
-        return Conversions.convert(getString(index)).toBoolean();
-    }
-
-    /**
-     * @param index
-     * @return  The value at the given {@code index} as {@code BigDecimal}
-     */
-    protected BigDecimal getDecimal(int index) {
-        return Conversions.convert(getString(index)).toDecimal();
+    @SuppressWarnings("unchecked")
+    private <S> S  convertTo(Type<S> type) {
+        switch (type.tag()) {
+            case PropertyType.STRING:
+                return (S) Iterables.transform(values, new Function<T, String>() {
+                    @Override
+                    public String apply(T value) {
+                        return getConverter(value).toString();
+                    }
+                });
+            case PropertyType.BINARY:
+                return (S) Iterables.transform(values, new Function<T, Blob>() {
+                    @Override
+                    public Blob apply(T value) {
+                        return getConverter(value).toBinary();
+                    }
+                });
+            case PropertyType.LONG:
+                return (S) Iterables.transform(values, new Function<T, Long>() {
+                    @Override
+                    public Long apply(T value) {
+                        return getConverter(value).toLong();
+                    }
+                });
+            case PropertyType.DOUBLE:
+                return (S) Iterables.transform(values, new Function<T, Double>() {
+                    @Override
+                    public Double apply(T value) {
+                        return getConverter(value).toDouble();
+                    }
+                });
+            case PropertyType.DATE:
+                return (S) Iterables.transform(values, new Function<T, String>() {
+                    @Override
+                    public String apply(T value) {
+                        return getConverter(value).toDate();
+                    }
+                });
+            case PropertyType.BOOLEAN:
+                return (S) Iterables.transform(values, new Function<T, Boolean>() {
+                    @Override
+                    public Boolean apply(T value) {
+                        return getConverter(value).toBoolean();
+                    }
+                });
+            case PropertyType.NAME:
+                return (S) Iterables.transform(values, new Function<T, String>() {
+                    @Override
+                    public String apply(T value) {
+                        return getConverter(value).toString();
+                    }
+                });
+            case PropertyType.PATH:
+                return (S) Iterables.transform(values, new Function<T, String>() {
+                    @Override
+                    public String apply(T value) {
+                        return getConverter(value).toString();
+                    }
+                });
+            case PropertyType.REFERENCE:
+                return (S) Iterables.transform(values, new Function<T, String>() {
+                    @Override
+                    public String apply(T value) {
+                        return getConverter(value).toString();
+                    }
+                });
+            case PropertyType.WEAKREFERENCE:
+                return (S) Iterables.transform(values, new Function<T, String>() {
+                    @Override
+                    public String apply(T value) {
+                        return getConverter(value).toString();
+                    }
+                });
+            case PropertyType.URI:
+                return (S) Iterables.transform(values, new Function<T, String>() {
+                    @Override
+                    public String apply(T value) {
+                        return getConverter(value).toString();
+                    }
+                });
+            case PropertyType.DECIMAL:
+                return (S) Iterables.transform(values, new Function<T, BigDecimal>() {
+                    @Override
+                    public BigDecimal apply(T value) {
+                        return getConverter(value).toDecimal();
+                    }
+                });
+            default: throw new IllegalArgumentException("Unknown type:" + type);
+        }
     }
 
     /**
@@ -190,22 +155,32 @@ abstract class MultiPropertyState<T> ext
     @SuppressWarnings("unchecked")
     @Nonnull
     @Override
-    public <T> T getValue(Type<T> type) {
+    public <S> S getValue(Type<S> type) {
         checkArgument(type.isArray(), "Type must not be an array type");
+        if (getType() == type) {
+            return (S) values;
+        }
+        else {
+            return convertTo(type);
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    private <S> S  convertTo(Type<S> type, int index) {
         switch (type.tag()) {
-            case PropertyType.STRING: return (T) getStrings();
-            case PropertyType.BINARY: return (T) getBlobs();
-            case PropertyType.LONG: return (T) getLongs();
-            case PropertyType.DOUBLE: return (T) getDoubles();
-            case PropertyType.DATE: return (T) getDates();
-            case PropertyType.BOOLEAN: return (T) getBooleans();
-            case PropertyType.NAME: return (T) getStrings();
-            case PropertyType.PATH: return (T) getStrings();
-            case PropertyType.REFERENCE: return (T) getStrings();
-            case PropertyType.WEAKREFERENCE: return (T) getStrings();
-            case PropertyType.URI: return (T) getStrings();
-            case PropertyType.DECIMAL: return (T) getDecimals();
-            default: throw new IllegalArgumentException("Invalid type:" + type);
+            case PropertyType.STRING: return (S) getConverter(values.get(index)).toString();
+            case PropertyType.BINARY: return (S) getConverter(values.get(index)).toBinary();
+            case PropertyType.LONG: return (S) (Long) getConverter(values.get(index)).toLong();
+            case PropertyType.DOUBLE: return (S) (Double) getConverter(values.get(index)).toDouble();
+            case PropertyType.DATE: return (S) getConverter(values.get(index)).toDate();
+            case PropertyType.BOOLEAN: return (S) (Boolean) getConverter(values.get(index)).toBoolean();
+            case PropertyType.NAME: return (S) getConverter(values.get(index)).toString();
+            case PropertyType.PATH: return (S) getConverter(values.get(index)).toString();
+            case PropertyType.REFERENCE: return (S) getConverter(values.get(index)).toString();
+            case PropertyType.WEAKREFERENCE: return (S) getConverter(values.get(index)).toString();
+            case PropertyType.URI: return (S) getConverter(values.get(index)).toString();
+            case PropertyType.DECIMAL: return (S) getConverter(values.get(index)).toDecimal();
+            default: throw new IllegalArgumentException("Unknown type:" + type);
         }
     }
 
@@ -217,26 +192,13 @@ abstract class MultiPropertyState<T> ext
     @SuppressWarnings("unchecked")
     @Nonnull
     @Override
-    public <T> T getValue(Type<T> type, int index) {
+    public <S> S getValue(Type<S> type, int index) {
         checkArgument(!type.isArray(), "Type must not be an array type");
-        if (index >= count()) {
-            throw new IndexOutOfBoundsException(String.valueOf(index));
+        if (getType().getBaseType() == type) {
+            return (S) values.get(index);
         }
-
-        switch (type.tag()) {
-            case PropertyType.STRING: return (T) getString(index);
-            case PropertyType.BINARY: return (T) getBlob(index);
-            case PropertyType.LONG: return (T) (Long) getLong(index);
-            case PropertyType.DOUBLE: return (T) (Double) getDouble(index);
-            case PropertyType.DATE: return (T) getDate(index);
-            case PropertyType.BOOLEAN: return (T) (Boolean) getBoolean(index);
-            case PropertyType.NAME: return (T) getString(index);
-            case PropertyType.PATH: return (T) getString(index);
-            case PropertyType.REFERENCE: return (T) getString(index);
-            case PropertyType.WEAKREFERENCE: return (T) getString(index);
-            case PropertyType.URI: return (T) getString(index);
-            case PropertyType.DECIMAL: return (T) getDecimal(index);
-            default: throw new IllegalArgumentException("Invalid type:" + type);
+        else {
+            return convertTo(type, index);
         }
     }
 
@@ -247,7 +209,7 @@ abstract class MultiPropertyState<T> ext
 
     @Override
     public long size(int index) {
-        return getString(index).length();
+        return convertTo(Type.STRING, index).length();
     }
 
 }

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=1400897&r1=1400896&r2=1400897&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 Mon Oct 22 14:40:45 2012
@@ -18,14 +18,11 @@
  */
 package org.apache.jackrabbit.oak.plugins.memory;
 
-import java.math.BigDecimal;
-
 import javax.annotation.Nonnull;
 import javax.jcr.PropertyType;
 
-import org.apache.jackrabbit.oak.api.Blob;
 import org.apache.jackrabbit.oak.api.Type;
-import org.apache.jackrabbit.oak.plugins.value.Conversions;
+import org.apache.jackrabbit.oak.plugins.value.Conversions.Converter;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static java.util.Collections.singleton;
@@ -33,7 +30,7 @@ import static java.util.Collections.sing
 /**
  * Abstract base class for single valued {@code PropertyState} implementations.
  */
-abstract class SinglePropertyState extends EmptyPropertyState {
+abstract class SinglePropertyState<T> extends EmptyPropertyState {
 
     /**
      * Create a new property state with the given {@code name}
@@ -44,61 +41,43 @@ abstract class SinglePropertyState exten
     }
 
     /**
-     * String representation of the value of the property state.
-     * @return
-     */
-    protected abstract String getString();
-
-    /**
-     * @return  A {@link StringBasedBlob} instance created by calling
-     * {@link #getString()}.
-     */
-    protected Blob getBlob() {
-        return Conversions.convert(getString()).toBinary();
-    }
-
-    /**
-     * @return  long value converted by {@code Conversions.convert(String)}
-     */
-    protected long getLong() {
-        return Conversions.convert(getString()).toLong();
-    }
-
-    /**
-     * @return  double value converted by {@code Conversions.convert(String)}
-     */
-    protected double getDouble() {
-        return Conversions.convert(getString()).toDouble();
-    }
-
-    /**
-     * @return  date value converted by {@code Conversions.convert(String)}
+     * @return  {@code false}
      */
-    protected String getDate() {
-        return Conversions.convert(getString()).toDate();
+    @Override
+    public boolean isArray() {
+        return false;
     }
 
     /**
-     * @return  boolean value converted by {@code Conversions.convert(String)}
+     * Create a converter for converting the value of this property to other types.
+     * @return  A converter for the value of this property
      */
-    protected boolean getBoolean() {
-        return Conversions.convert(getString()).toBoolean();
-    }
+    public abstract Converter getConverter();
 
-    /**
-     * @return  decimal value converted by {@code Conversions.convert(String)}
-     */
-    protected BigDecimal getDecimal() {
-        return Conversions.convert(getString()).toDecimal();
+    @SuppressWarnings("unchecked")
+    private <S> S  convertTo(Type<S> type) {
+        switch (type.tag()) {
+            case PropertyType.STRING: return (S) getConverter().toString();
+            case PropertyType.BINARY: return (S) getConverter().toBinary();
+            case PropertyType.LONG: return (S) (Long) getConverter().toLong();
+            case PropertyType.DOUBLE: return (S) (Double) getConverter().toDouble();
+            case PropertyType.DATE: return (S) getConverter().toDate();
+            case PropertyType.BOOLEAN: return (S) (Boolean) getConverter().toBoolean();
+            case PropertyType.NAME: return (S) getConverter().toString();
+            case PropertyType.PATH: return (S) getConverter().toString();
+            case PropertyType.REFERENCE: return (S) getConverter().toString();
+            case PropertyType.WEAKREFERENCE: return (S) getConverter().toString();
+            case PropertyType.URI: return (S) getConverter().toString();
+            case PropertyType.DECIMAL: return (S) getConverter().toDecimal();
+            default: throw new IllegalArgumentException("Unknown type:" + type);
+        }
     }
 
     /**
-     * @return  {@code false}
+     * The value of this property
+     * @return  Value of this property
      */
-    @Override
-    public boolean isArray() {
-        return false;
-    }
+    public abstract T getValue();
 
     /**
      * @throws IllegalArgumentException if {@code type} is not one of the
@@ -107,39 +86,21 @@ abstract class SinglePropertyState exten
     @SuppressWarnings("unchecked")
     @Nonnull
     @Override
-    public <T> T getValue(Type<T> type) {
+    public <S> S getValue(Type<S> type) {
         if (type.isArray()) {
-            switch (type.tag()) {
-                case PropertyType.STRING: return (T) singleton(getString());
-                case PropertyType.BINARY: return (T) singleton(getBlob());
-                case PropertyType.LONG: return (T) singleton(getLong());
-                case PropertyType.DOUBLE: return (T) singleton(getDouble());
-                case PropertyType.DATE: return (T) singleton(getDate());
-                case PropertyType.BOOLEAN: return (T) singleton(getBoolean());
-                case PropertyType.NAME: return (T) singleton(getString());
-                case PropertyType.PATH: return (T) singleton(getString());
-                case PropertyType.REFERENCE: return (T) singleton(getString());
-                case PropertyType.WEAKREFERENCE: return (T) singleton(getString());
-                case PropertyType.URI: return (T) singleton(getString());
-                case PropertyType.DECIMAL: return (T) singleton(getDecimal());
-                default: throw new IllegalArgumentException("Invalid primitive type:" + type);
+            if (getType() == type.getBaseType()) {
+                return (S) singleton(getValue());
+            }
+            else {
+                return (S) singleton(convertTo(type.getBaseType()));
             }
         }
         else {
-            switch (type.tag()) {
-                case PropertyType.STRING: return (T) getString();
-                case PropertyType.BINARY: return (T) getBlob();
-                case PropertyType.LONG: return (T) (Long) getLong();
-                case PropertyType.DOUBLE: return (T) (Double) getDouble();
-                case PropertyType.DATE: return (T) getDate();
-                case PropertyType.BOOLEAN: return (T) (Boolean) getBoolean();
-                case PropertyType.NAME: return (T) getString();
-                case PropertyType.PATH: return (T) getString();
-                case PropertyType.REFERENCE: return (T) getString();
-                case PropertyType.WEAKREFERENCE: return (T) getString();
-                case PropertyType.URI: return (T) getString();
-                case PropertyType.DECIMAL: return (T) getDecimal();
-                default: throw new IllegalArgumentException("Invalid array type:" + type);
+            if (getType() == type) {
+                return (S) getValue();
+            }
+            else {
+                return convertTo(type);
             }
         }
     }
@@ -150,7 +111,7 @@ abstract class SinglePropertyState exten
      */
     @Nonnull
     @Override
-    public <T> T getValue(Type<T> type, int index) {
+    public <S> S getValue(Type<S> type, int index) {
         checkArgument(!type.isArray(), "Type must not be an array type");
         if (index != 0) {
             throw new IndexOutOfBoundsException(String.valueOf(index));
@@ -163,7 +124,7 @@ abstract class SinglePropertyState exten
      */
     @Override
     public long size() {
-        return getString().length();
+        return convertTo(Type.STRING).length();
     }
 
     /**

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/StringPropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/StringPropertyState.java?rev=1400897&r1=1400896&r2=1400897&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/StringPropertyState.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/StringPropertyState.java Mon Oct 22 14:40:45 2012
@@ -19,23 +19,30 @@
 package org.apache.jackrabbit.oak.plugins.memory;
 
 import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.plugins.value.Conversions;
+import org.apache.jackrabbit.oak.plugins.value.Conversions.Converter;
 
 import static org.apache.jackrabbit.oak.api.Type.STRING;
 
-public class StringPropertyState extends SinglePropertyState {
+public class StringPropertyState extends SinglePropertyState<String> {
     private final String value;
 
-    protected StringPropertyState(String name, String value) {
+    public StringPropertyState(String name, String value) {
         super(name);
         this.value = value;
     }
 
     @Override
-    protected String getString() {
+    public String getValue() {
         return value;
     }
 
     @Override
+    public Converter getConverter() {
+        return Conversions.convert(value);
+    }
+
+    @Override
     public Type<?> getType() {
         return STRING;
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/StringsPropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/StringsPropertyState.java?rev=1400897&r1=1400896&r2=1400897&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/StringsPropertyState.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/StringsPropertyState.java Mon Oct 22 14:40:45 2012
@@ -19,20 +19,17 @@
 package org.apache.jackrabbit.oak.plugins.memory;
 
 import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.plugins.value.Conversions;
+import org.apache.jackrabbit.oak.plugins.value.Conversions.Converter;
 
 public class StringsPropertyState extends MultiPropertyState<String> {
-    protected StringsPropertyState(String name, Iterable<String> values) {
+    public StringsPropertyState(String name, Iterable<String> values) {
         super(name, values);
     }
 
     @Override
-    protected Iterable<String> getStrings() {
-        return values;
-    }
-
-    @Override
-    protected String getString(int index) {
-        return values.get(index);
+    public Converter getConverter(String value) {
+        return Conversions.convert(value);
     }
 
     @Override



Mime
View raw message