commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r1525722 - in /commons/proper/lang/trunk/src: main/java/org/apache/commons/lang3/reflect/TypeUtils.java test/java/org/apache/commons/lang3/reflect/TypeUtilsTest.java
Date Mon, 23 Sep 2013 22:42:03 GMT
Author: mbenson
Date: Mon Sep 23 22:42:03 2013
New Revision: 1525722

URL: http://svn.apache.org/r1525722
Log:
provide simple method to wrap a given type to the Typed interface

Modified:
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java
    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/reflect/TypeUtilsTest.java

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java?rev=1525722&r1=1525721&r2=1525722&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java
(original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java
Mon Sep 23 22:42:03 2013
@@ -1540,6 +1540,22 @@ public class TypeUtils {
         return buf.append(':').append(typeVariableToString(var)).toString();
     }
 
+    /**
+     * Wrap the specified {@link Type} in a {@link Typed} wrapper.
+     *
+     * @param T inferred generic type
+     * @param type to wrap
+     * @return Typed<T>
+     */
+    public static <T> Typed<T> wrap(final Type type) {
+        return new Typed<T>() {
+            @Override
+            public Type getType() {
+                return type;
+            }
+        };
+    }
+
     private static String classToString(Class<?> c) {
         final StringBuilder buf = new StringBuilder();
 

Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/reflect/TypeUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/reflect/TypeUtilsTest.java?rev=1525722&r1=1525721&r2=1525722&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/reflect/TypeUtilsTest.java
(original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/reflect/TypeUtilsTest.java
Mon Sep 23 22:42:03 2013
@@ -716,6 +716,12 @@ public class TypeUtilsTest<B> {
         Assert.assertEquals(getClass().getName() + ":B", TypeUtils.toLongString(getClass().getTypeParameters()[0]));
     }
 
+    @Test
+    public void testWrap() {
+        final Type t = getClass().getTypeParameters()[0];
+        Assert.assertTrue(TypeUtils.equals(t, TypeUtils.wrap(t).getType()));
+    }
+
     public Iterable<? extends Map<Integer, ? extends Collection<?>>> iterable;
 
     public static <G extends Comparable<G>> G stub() {



Mime
View raw message