jackrabbit-oak-commits mailing list archives

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

URL: http://svn.apache.org/viewvc?rev=1399627&view=rev
Log:
OAK-380: Define conversion of property values
clean up

Modified:
    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/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/plugins/memory/StringPropertyState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/StringsPropertyState.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/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=1399627&r1=1399626&r2=1399627&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 12:41:24 2012
@@ -18,12 +18,14 @@
  */
 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;
 
@@ -37,7 +39,7 @@ import static org.apache.jackrabbit.oak.
  * providing default implementation which correspond to a property
  * without any value.
  */
-abstract class EmptyPropertyState implements PropertyState {
+public abstract class EmptyPropertyState implements PropertyState {
     private final String name;
 
     /**
@@ -48,6 +50,66 @@ abstract class EmptyPropertyState implem
         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/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=1399627&r1=1399626&r2=1399627&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 12:41:24 2012
@@ -68,7 +68,7 @@ abstract class MultiPropertyState<T> ext
         return Iterables.transform(getStrings(), new Function<String, Blob>() {
             @Override
             public Blob apply(String value) {
-                return new StringBasedBlob(value);
+                return EmptyPropertyState.getBinary(value);
             }
         });
     }
@@ -80,7 +80,7 @@ abstract class MultiPropertyState<T> ext
         return Iterables.transform(getStrings(), new Function<String, Long>() {
             @Override
             public Long apply(String value) {
-                return Long.parseLong(value);
+                return EmptyPropertyState.getLong(value);
             }
         });
     }
@@ -92,7 +92,7 @@ abstract class MultiPropertyState<T> ext
         return Iterables.transform(getStrings(), new Function<String, Double>() {
             @Override
             public Double apply(String value) {
-                return Double.parseDouble(value);
+                return EmptyPropertyState.getDouble(value);
             }
         });
     }
@@ -104,7 +104,7 @@ abstract class MultiPropertyState<T> ext
         return Iterables.transform(getStrings(), new Function<String, Boolean>() {
             @Override
             public Boolean apply(String value) {
-                return StringPropertyState.getBoolean(value);
+                return EmptyPropertyState.getBoolean(value);
             }
         });
     }
@@ -116,7 +116,7 @@ abstract class MultiPropertyState<T> ext
         return Iterables.transform(getStrings(), new Function<String, BigDecimal>()
{
             @Override
             public BigDecimal apply(String value) {
-                return new BigDecimal(value);
+                return EmptyPropertyState.getDecimal(value);
             }
         });
     }
@@ -126,7 +126,7 @@ abstract class MultiPropertyState<T> ext
      * @return  The value at the given {@code index} as {@link Blob}
      */
     protected Blob getBlob(int index) {
-        return new StringBasedBlob(getString(index));
+        return EmptyPropertyState.getBinary(getString(index));
     }
 
     /**
@@ -134,7 +134,7 @@ abstract class MultiPropertyState<T> ext
      * @return  The value at the given {@code index} as {@code long}
      */
     protected long getLong(int index) {
-        return Long.parseLong(getString(index));
+        return EmptyPropertyState.getLong(getString(index));
     }
 
     /**
@@ -142,7 +142,7 @@ abstract class MultiPropertyState<T> ext
      * @return  The value at the given {@code index} as {@code double}
      */
     protected double getDouble(int index) {
-        return Double.parseDouble(getString(index));
+        return EmptyPropertyState.getDouble(getString(index));
     }
 
     /**
@@ -150,7 +150,7 @@ abstract class MultiPropertyState<T> ext
      * @return  The value at the given {@code index} as {@code boolean}
      */
     protected boolean getBoolean(int index) {
-        return StringPropertyState.getBoolean(getString(index));
+        return EmptyPropertyState.getBoolean(getString(index));
     }
 
     /**
@@ -158,7 +158,7 @@ abstract class MultiPropertyState<T> ext
      * @return  The value at the given {@code index} as {@code BigDecimal}
      */
     protected BigDecimal getDecimal(int index) {
-        return new BigDecimal(getString(index));
+        return EmptyPropertyState.getDecimal(getString(index));
     }
 
     /**

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=1399627&r1=1399626&r2=1399627&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 12:41:24 2012
@@ -164,15 +164,15 @@ public final class PropertyStates {
             case PropertyType.STRING:
                 return new StringPropertyState(name, value);
             case PropertyType.BINARY:
-                return new BinaryPropertyState(name, new StringBasedBlob(value));
+                return new BinaryPropertyState(name, EmptyPropertyState.getBinary(value));
             case PropertyType.LONG:
-                return new LongPropertyState(name, SinglePropertyState.getLong(value));
+                return new LongPropertyState(name, EmptyPropertyState.getLong(value));
             case PropertyType.DOUBLE:
-                return new DoublePropertyState(name, StringPropertyState.getDouble(value));
+                return new DoublePropertyState(name, EmptyPropertyState.getDouble(value));
             case PropertyType.BOOLEAN:
-                return new BooleanPropertyState(name, StringPropertyState.getBoolean(value));
+                return new BooleanPropertyState(name, EmptyPropertyState.getBoolean(value));
             case PropertyType.DECIMAL:
-                return new DecimalPropertyState(name, StringPropertyState.getDecimal(value));
+                return new DecimalPropertyState(name, EmptyPropertyState.getDecimal(value));
             default:
                 return new GenericPropertyState(name, value, Type.fromTag(type, false));
         }
@@ -619,7 +619,7 @@ public final class PropertyStates {
             if (reader.matches(JsopReader.NUMBER)) {
                 String number = reader.getToken();
                 type = PropertyType.LONG;
-                values.add(StringPropertyState.getLong(number));
+                values.add(EmptyPropertyState.getLong(number));
             } else if (reader.matches(JsopReader.TRUE)) {
                 type = PropertyType.BOOLEAN;
                 values.add(true);
@@ -634,9 +634,9 @@ public final class PropertyStates {
                     if (type == PropertyType.BINARY) {
                         values.add(new KernelBlob(value, kernel));
                     } else if(type == PropertyType.DOUBLE) {
-                        values.add(StringPropertyState.getDouble(value));
+                        values.add(EmptyPropertyState.getDouble(value));
                     } else if(type == PropertyType.DECIMAL) {
-                        values.add(StringPropertyState.getDecimal(value));
+                        values.add(EmptyPropertyState.getDecimal(value));
                     } 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=1399627&r1=1399626&r2=1399627&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 12:41:24 2012
@@ -43,42 +43,6 @@ abstract class SinglePropertyState exten
     }
 
     /**
-     * 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 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);
-    }
-
-    /**
      * String representation of the value of the property state.
      * @return
      */
@@ -89,7 +53,7 @@ abstract class SinglePropertyState exten
      * {@link #getString()}.
      */
     protected Blob getBlob() {
-        return new StringBasedBlob(getString());
+        return getBinary(getString());
     }
 
     /**
@@ -110,7 +74,7 @@ abstract class SinglePropertyState exten
      * @return  {@code StringPropertyState.getBoolean(getString())}
      */
     protected boolean getBoolean() {
-        return StringPropertyState.getBoolean(getString());
+        return getBoolean(getString());
     }
 
     /**

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=1399627&r1=1399626&r2=1399627&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
Thu Oct 18 12:41:24 2012
@@ -30,27 +30,12 @@ public class StringPropertyState extends
         this.value = 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);
-    }
-
     @Override
     protected String getString() {
         return value;
     }
 
     @Override
-    protected boolean getBoolean() {
-        return getBoolean(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=1399627&r1=1399626&r2=1399627&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
Thu Oct 18 12:41:24 2012
@@ -20,8 +20,6 @@ package org.apache.jackrabbit.oak.plugin
 
 import java.util.List;
 
-import com.google.common.base.Function;
-import com.google.common.collect.Iterables;
 import org.apache.jackrabbit.oak.api.Type;
 
 public class StringsPropertyState extends MultiPropertyState<String> {
@@ -40,21 +38,6 @@ public class StringsPropertyState extend
     }
 
     @Override
-    protected Iterable<Boolean> getBooleans() {
-        return Iterables.transform(values, new Function<String, Boolean>() {
-            @Override
-            public Boolean apply(String value) {
-                return Boolean.parseBoolean(value);
-            }
-        });
-    }
-
-    @Override
-    protected boolean getBoolean(int index) {
-        return Boolean.parseBoolean(getString(index));
-    }
-
-    @Override
     public Type<?> getType() {
         return Type.STRINGS;
     }

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=1399627&r1=1399626&r2=1399627&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 12:41:24 2012
@@ -40,8 +40,8 @@ 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.plugins.memory.StringPropertyState;
 import org.apache.jackrabbit.oak.spi.query.PropertyValues;
 import org.apache.jackrabbit.util.ISO8601;
 import org.slf4j.Logger;
@@ -193,9 +193,9 @@ public class ValueFactoryImpl implements
                     pv = PropertyStates.binaryProperty("", value.getBytes("UTF-8"));
                     break;
                 case PropertyType.LONG:
-                    return createValue(StringPropertyState.getLong(value));
+                    return createValue(EmptyPropertyState.getLong(value));
                 case PropertyType.DOUBLE:
-                    return createValue(StringPropertyState.getDouble(value));
+                    return createValue(EmptyPropertyState.getDouble(value));
                 case PropertyType.DATE:
                     if (ISO8601.parse(value) == null) {
                         throw new ValueFormatException("Invalid date " + value);
@@ -203,7 +203,7 @@ public class ValueFactoryImpl implements
                     pv = PropertyStates.dateProperty("", value);
                     break;
                 case PropertyType.BOOLEAN:
-                    return createValue(StringPropertyState.getBoolean(value));
+                    return createValue(EmptyPropertyState.getBoolean(value));
                 case PropertyType.NAME:
                     String oakName = namePathMapper.getOakName(value);
                     if (oakName == null) {
@@ -240,7 +240,7 @@ public class ValueFactoryImpl implements
                     pv = PropertyStates.uriProperty("", value);
                     break;
                 case PropertyType.DECIMAL:
-                    return createValue(StringPropertyState.getDecimal(value));
+                    return createValue(EmptyPropertyState.getDecimal(value));
                 default:
                     throw new ValueFormatException("Invalid type: " + type);
             }



Mime
View raw message