You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by th...@apache.org on 2021/10/07 14:18:32 UTC
[tapestry-5] branch rest updated: TAP5-2695: Create convenience
methods for contributing coercions
This is an automated email from the ASF dual-hosted git repository.
thiagohp pushed a commit to branch rest
in repository https://gitbox.apache.org/repos/asf/tapestry-5.git
The following commit(s) were added to refs/heads/rest by this push:
new 90747ad TAP5-2695: Create convenience methods for contributing coercions
90747ad is described below
commit 90747adefbe945e21dc5942434998301f4ef261a
Author: Thiago H. de Paula Figueiredo <th...@arsmachina.com.br>
AuthorDate: Thu Oct 7 11:18:23 2021 -0300
TAP5-2695: Create convenience methods for contributing coercions
---
.../tapestry5/commons/services/CoercionTuple.java | 31 ++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/commons/src/main/java/org/apache/tapestry5/commons/services/CoercionTuple.java b/commons/src/main/java/org/apache/tapestry5/commons/services/CoercionTuple.java
index 1a4ab17..473e830 100644
--- a/commons/src/main/java/org/apache/tapestry5/commons/services/CoercionTuple.java
+++ b/commons/src/main/java/org/apache/tapestry5/commons/services/CoercionTuple.java
@@ -14,6 +14,7 @@
package org.apache.tapestry5.commons.services;
+import org.apache.tapestry5.commons.MappedConfiguration;
import org.apache.tapestry5.plastic.PlasticUtils;
/**
@@ -90,6 +91,36 @@ public final class CoercionTuple<S, T>
}
/**
+ * Convenience method to create a coercion tuple using {@linkplain #create(Class, Class, Coercion)}
+ * and add it to a {@linkplain MappedConfiguration} in a single step.
+ *
+ * @since 5.8.0
+ */
+ @SuppressWarnings("rawtypes")
+ public static <S, T> void add(
+ MappedConfiguration<CoercionTuple.Key, CoercionTuple> configuration,
+ Class<S> sourceType, Class<T> targetType, Coercion<S, T> coercion)
+ {
+ CoercionTuple<S, T> coercionTuple = new CoercionTuple<S, T>(sourceType, targetType, coercion);
+ configuration.add(coercionTuple.getKey(), coercionTuple);
+ }
+
+ /**
+ * Convenience method to create a coercion tuple using {@linkplain #create(Class, Class, Coercion)}
+ * and override a matching one in a {@linkplain MappedConfiguration} in a single step.
+ *
+ * @since 5.8.0
+ */
+ @SuppressWarnings("rawtypes")
+ public static <S, T> void override(
+ MappedConfiguration<CoercionTuple.Key, CoercionTuple> configuration,
+ Class<S> sourceType, Class<T> targetType, Coercion<S, T> coercion)
+ {
+ CoercionTuple<S, T> coercionTuple = new CoercionTuple<S, T>(sourceType, targetType, coercion);
+ configuration.override(coercionTuple.getKey(), coercionTuple);
+ }
+
+ /**
* Convenience constructor to help with generics.
*
* @since 5.2.0