felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r1769793 - in /felix/trunk/converter/converter/src/main/java/org/osgi/util/converter: ConvertFunction.java Converting.java Rule.java
Date Tue, 15 Nov 2016 11:52:35 GMT
Author: davidb
Date: Tue Nov 15 11:52:35 2016
New Revision: 1769793

URL: http://svn.apache.org/viewvc?rev=1769793&view=rev
Log:
Felix Converter - reformat some interfaces.

Modified:
    felix/trunk/converter/converter/src/main/java/org/osgi/util/converter/ConvertFunction.java
    felix/trunk/converter/converter/src/main/java/org/osgi/util/converter/Converting.java
    felix/trunk/converter/converter/src/main/java/org/osgi/util/converter/Rule.java

Modified: felix/trunk/converter/converter/src/main/java/org/osgi/util/converter/ConvertFunction.java
URL: http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/main/java/org/osgi/util/converter/ConvertFunction.java?rev=1769793&r1=1769792&r2=1769793&view=diff
==============================================================================
--- felix/trunk/converter/converter/src/main/java/org/osgi/util/converter/ConvertFunction.java
(original)
+++ felix/trunk/converter/converter/src/main/java/org/osgi/util/converter/ConvertFunction.java
Tue Nov 15 11:52:35 2016
@@ -37,13 +37,16 @@ public interface ConvertFunction<F, T> {
 	 *            {@code null} as the convert function will not be invoked for
 	 *            null values.
 	 * @param targetType The target type.
-	 * @param key If the object was part of a map-like structure, the associated
-	 *            key is provided. Otherwise {@code null}.
+	 * @param root The root object, if this obj was embedded in a root object.
+	 *            Otherwise {@code null}.
+	 * @param keyPath If the object is embedded in a root object, the path of
+	 *            keys that reach this object. Otherwise {@code null}.
 	 * @return The conversion result or {@code null} to indicate that the
 	 *         convert function cannot handle this conversion. In this case the
 	 *         next matching rule or adapter will be given a opportunity to
 	 *         convert.
 	 * @throws Exception
 	 */
-	T convert(F obj, Type targetType, Object root, Object[] keyPath) throws Exception;
+	T convert(F obj, Type targetType, Object root, Object[] keyPath)
+			throws Exception;
 }

Modified: felix/trunk/converter/converter/src/main/java/org/osgi/util/converter/Converting.java
URL: http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/main/java/org/osgi/util/converter/Converting.java?rev=1769793&r1=1769792&r2=1769793&view=diff
==============================================================================
--- felix/trunk/converter/converter/src/main/java/org/osgi/util/converter/Converting.java
(original)
+++ felix/trunk/converter/converter/src/main/java/org/osgi/util/converter/Converting.java
Tue Nov 15 11:52:35 2016
@@ -29,69 +29,71 @@ import org.osgi.annotation.versioning.Pr
  */
 @ProviderType
 public interface Converting {
-    /**
-     * Always return a fully populated copy of the object, however if the object
-     * is an immutable built-in scalar such as String or Long, then a copy is
-     * not needed. By default a wrapped object is returned by the converter if
-     * possible.
-     *
-     * @return The current {@code Converting} object so that additional calls
-     *         can be chained.
-     */
-    Converting copy();
-
-    /**
-     * The default value to use when the object cannot be converted or in case
-     * of conversion from a {@code null} value.
-     *
-     * @param defVal The default value.
-     * @return The current {@code Converting} object so that additional calls
-     *         can be chained.
-     */
-    Converting defaultValue(Object defVal);
-
-    /**
-     * Provide additional information on how to treat the source object.
-     * @return A {@link ConvertingTypeSettings} to provide the details.
-     */
-    ConvertingTypeSettings source();
-
-    /**
-     * Provide additional information on how to treat the target type.
-     * @return A {@link ConvertingTypeSettings} to provide the details.
-     */
-    ConvertingTypeSettings target();
-
-    /**
-     * Specify the target object type for the conversion as a class object.
-     *
-     * @param cls The class to convert to.
-     * @return The converted object.
-     */
-    <T> T to(Class<T> cls);
-
-    /**
-     * Specify the target object type as a {@link TypeReference}. If the target
-     * class carries generics information a TypeReference should be used as this
-     * preserves the generic information whereas a Class object has this
-     * information erased. Example use:
-     *
-     * <pre>
-     * List&lt;String&gt; result = converter.convert(Arrays.asList(1, 2, 3))
-     *      .to(new TypeReference&lt;List&lt;String&gt;&gt;() {});
-     * </pre>
-     *
-     * @param ref A type reference to the object being converted to.
-     * @return The converted object.
-     */
-    <T> T to(TypeReference<T> ref);
-
-    /**
-     * Specify the target object type as a Java Reflection Type object.
-     *
-     * @param type A Type object to represent the target type to be converted
-     *            to.
-     * @return The converted object.
-     */
-    Object to(Type type);
+	/**
+	 * Always return a fully populated copy of the object, however if the object
+	 * is an immutable built-in scalar such as String or Long, then a copy is
+	 * not needed. By default a wrapped object is returned by the converter if
+	 * possible.
+	 *
+	 * @return The current {@code Converting} object so that additional calls
+	 *         can be chained.
+	 */
+	Converting copy();
+
+	/**
+	 * The default value to use when the object cannot be converted or in case
+	 * of conversion from a {@code null} value.
+	 *
+	 * @param defVal The default value.
+	 * @return The current {@code Converting} object so that additional calls
+	 *         can be chained.
+	 */
+	Converting defaultValue(Object defVal);
+
+	/**
+	 * Provide additional information on how to treat the source object.
+	 *
+	 * @return A {@link ConvertingTypeSettings} to provide the details.
+	 */
+	ConvertingTypeSettings source();
+
+	/**
+	 * Provide additional information on how to treat the target type.
+	 *
+	 * @return A {@link ConvertingTypeSettings} to provide the details.
+	 */
+	ConvertingTypeSettings target();
+
+	/**
+	 * Specify the target object type for the conversion as a class object.
+	 *
+	 * @param cls The class to convert to.
+	 * @return The converted object.
+	 */
+	<T> T to(Class<T> cls);
+
+	/**
+	 * Specify the target object type as a {@link TypeReference}. If the target
+	 * class carries generics information a TypeReference should be used as this
+	 * preserves the generic information whereas a Class object has this
+	 * information erased. Example use:
+	 *
+	 * <pre>
+	 * List&lt;String&gt; result = converter.convert(Arrays.asList(1, 2, 3))
+	 * 		.to(new TypeReference&lt;List&lt;String&gt;&gt;() {});
+	 * </pre>
+	 *
+	 * @param ref A type reference to the object being converted to.
+	 * @return The converted object.
+	 */
+	<T> T to(TypeReference<T> ref);
+
+	/**
+	 * Specify the target object type as a Java Reflection Type object.
+	 *
+	 * @param type A Type object to represent the target type to be converted
+	 *            to.
+	 * @return The converted object.
+	 */
+	Object to(Type type);
 }

Modified: felix/trunk/converter/converter/src/main/java/org/osgi/util/converter/Rule.java
URL: http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/main/java/org/osgi/util/converter/Rule.java?rev=1769793&r1=1769792&r2=1769793&view=diff
==============================================================================
--- felix/trunk/converter/converter/src/main/java/org/osgi/util/converter/Rule.java (original)
+++ felix/trunk/converter/converter/src/main/java/org/osgi/util/converter/Rule.java Tue Nov
15 11:52:35 2016
@@ -27,109 +27,112 @@ import java.lang.reflect.Type;
  * @Immutable
  */
 public class Rule<F, T> {
-    private final Type              sourceType;
-    private final Type              targetType;
+	private final Type				sourceType;
+	private final Type				targetType;
 
-    @SuppressWarnings("rawtypes")
-    private final ConvertFunction  toFun;
-    @SuppressWarnings("rawtypes")
-    private final ConvertFunction  backFun;
-
-    /**
-     * Create a bidirectional rule.
-     *
-     * @param fromCls The class from which to convert. If {@link Object} is
-     *            specified then this functions as a wildcard for generic
-     *            conversions.
-     * @param toCls The class to which to convert. If {@link Object} is
-     *            specified then this functions as a wildcard for generic
-     *            conversions.
-     * @param to The conversion function for this rule.
-     * @param back The reverse conversion for this rule.
-     */
-    public Rule(Class<F> fromCls, Class<T> toCls, ConvertFunction<F,T>
to,
-            ConvertFunction<T,F> back) {
-        this((Type) fromCls, (Type) toCls, to, back);
-    }
-
-    /**
-     * Create a single-direction rule.
-     *
-     * @param fromCls The class from which to convert. If {@link Object} is
-     *            specified then this functions as a wildcard for generic
-     *            conversions.
-     * @param toCls The class to which to convert. If {@link Object} is
-     *            specified then this functions as a wildcard for generic
-     *            conversions.
-     * @param to The conversion function for this rule.
-     */
-    public Rule(Class<F> fromCls, Class<T> toCls, ConvertFunction<F,T>
to) {
-        this(fromCls, toCls, to, null);
-    }
-
-    public Rule(TypeReference<F> fromType, TypeReference<T> toType, ConvertFunction<F,T>
to, ConvertFunction<F,T> back) {
-        this(fromType.getType(), toType.getType(), to, back);
-    }
-
-    public Rule(TypeReference<F> fromType, TypeReference<T> toType, ConvertFunction<F,T>
to) {
-        this(fromType.getType(), toType.getType(), to, null);
-    }
-
-    public Rule(Type fromType, Type toType,
-            @SuppressWarnings("rawtypes") ConvertFunction to, @SuppressWarnings("rawtypes")
ConvertFunction back) {
-        if (fromType.equals(toType)) {
-            if (fromType.equals(Object.class)) {
-                if (back != null) {
-                    throw new IllegalStateException(
-                            "Can only register one catchall converter");
-                }
-            } else {
-                throw new IllegalStateException(
-                        "Cannot register a converter to itself");
-            }
-        }
-
-        sourceType = fromType;
-        targetType = toType;
-        toFun = to;
-        backFun = back;
-    }
-
-    /**
-     * Accessor for the class to convert from.
-     *
-     * @return The class to convert from.
-     */
-    public Type getSourceType() {
-        return sourceType;
-    }
-
-    /**
-     * Accessor for the class to convert to.
-     *
-     * @return The class to convert to.
-     */
-    public Type getTargetType() {
-        return targetType;
-    }
-
-    /**
-     * Obtain the conversion function.
-     *
-     * @return The conversion function.
-     */
-    @SuppressWarnings("unchecked")
-    public ConvertFunction<F,T> getToFunction() {
-        return toFun;
-    }
-
-    /**
-     * Obtain the reverse conversion function.
-     *
-     * @return The reverse conversion function.
-     */
-    @SuppressWarnings("unchecked")
-    public ConvertFunction<T,F> getBackFunction() {
-        return backFun;
-    }
+	@SuppressWarnings("rawtypes")
+	private final ConvertFunction	toFun;
+	@SuppressWarnings("rawtypes")
+	private final ConvertFunction	backFun;
+
+	/**
+	 * Create a bidirectional rule.
+	 *
+	 * @param fromCls The class from which to convert. If {@link Object} is
+	 *            specified then this functions as a wildcard for generic
+	 *            conversions.
+	 * @param toCls The class to which to convert. If {@link Object} is
+	 *            specified then this functions as a wildcard for generic
+	 *            conversions.
+	 * @param to The conversion function for this rule.
+	 * @param back The reverse conversion for this rule.
+	 */
+	public Rule(Class<F> fromCls, Class<T> toCls, ConvertFunction<F,T> to,
+			ConvertFunction<T,F> back) {
+		this((Type) fromCls, (Type) toCls, to, back);
+	}
+
+	/**
+	 * Create a single-direction rule.
+	 *
+	 * @param fromCls The class from which to convert. If {@link Object} is
+	 *            specified then this functions as a wildcard for generic
+	 *            conversions.
+	 * @param toCls The class to which to convert. If {@link Object} is
+	 *            specified then this functions as a wildcard for generic
+	 *            conversions.
+	 * @param to The conversion function for this rule.
+	 */
+	public Rule(Class<F> fromCls, Class<T> toCls, ConvertFunction<F,T> to)
{
+		this(fromCls, toCls, to, null);
+	}
+
+	public Rule(TypeReference<F> fromType, TypeReference<T> toType,
+			ConvertFunction<F,T> to, ConvertFunction<F,T> back) {
+		this(fromType.getType(), toType.getType(), to, back);
+	}
+
+	public Rule(TypeReference<F> fromType, TypeReference<T> toType,
+			ConvertFunction<F,T> to) {
+		this(fromType.getType(), toType.getType(), to, null);
+	}
+
+	public Rule(Type fromType, Type toType,
+			@SuppressWarnings("rawtypes") ConvertFunction to,
+			@SuppressWarnings("rawtypes") ConvertFunction back) {
+		if (fromType.equals(toType)) {
+			if (fromType.equals(Object.class)) {
+				if (back != null) {
+					throw new IllegalStateException(
+							"Can only register one catchall converter");
+				}
+			} else {
+				throw new IllegalStateException(
+						"Cannot register a converter to itself");
+			}
+		}
+
+		sourceType = fromType;
+		targetType = toType;
+		toFun = to;
+		backFun = back;
+	}
+
+	/**
+	 * Accessor for the class to convert from.
+	 *
+	 * @return The class to convert from.
+	 */
+	public Type getSourceType() {
+		return sourceType;
+	}
+
+	/**
+	 * Accessor for the class to convert to.
+	 *
+	 * @return The class to convert to.
+	 */
+	public Type getTargetType() {
+		return targetType;
+	}
+
+	/**
+	 * Obtain the conversion function.
+	 *
+	 * @return The conversion function.
+	 */
+	@SuppressWarnings("unchecked")
+	public ConvertFunction<F,T> getToFunction() {
+		return toFun;
+	}
+
+	/**
+	 * Obtain the reverse conversion function.
+	 *
+	 * @return The reverse conversion function.
+	 */
+	@SuppressWarnings("unchecked")
+	public ConvertFunction<T,F> getBackFunction() {
+		return backFun;
+	}
 }



Mime
View raw message