public static boolean instanceOf(Class c, List<String> types) { for (String type: types) { if (instanceOf(c, type)) { return true; } } return false; }
public static Class<?> resolveToClass(Type implementation, Class<?> type, int parameterIndex) { if (implementation == null) { throw new NullPointerException("No null type accepted"); } // First resolve to type Type resolvedType = resolve(implementation, type, parameterIndex); // if (resolvedType != null) { return resolveToClass(resolvedType); } else { return null; } }
public static Class resolveToClass(Type type) { if (type == null) { throw new NullPointerException("No null type accepted"); } if (type instanceof Class<?>) { return (Class<?>)type; } else if (type instanceof TypeVariable) { TypeVariable resolvedTypeVariable = (TypeVariable)type; return resolveToClass(resolvedTypeVariable.getBounds()[0]); } else { throw new UnsupportedOperationException("Type resolution of " + type + " not yet implemented"); } }
Type resolved = null; if (gsc != null) { resolved = resolve(gsc, type, parameterIndex); if (resolved == null) { } else if (rawType instanceof Class<?>) { Class<?> classRawType = (Class<?>)rawType; Type resolved = resolve(classRawType, type, parameterIndex); if (resolved == null) { return null; for (int i = 0;i < a.length;i++) { if (a[i].equals(resolvedTV)) { return resolve(implementation, classRawType, i);
public static Class resolveToClass(Type type) { if (type == null) { throw new NullPointerException("No null type accepted"); } if (type instanceof Class<?>) { return (Class<?>)type; } else if (type instanceof TypeVariable) { TypeVariable resolvedTypeVariable = (TypeVariable)type; return resolveToClass(resolvedTypeVariable.getBounds()[0]); } else { throw new UnsupportedOperationException("Type resolution of " + type + " not yet implemented"); } }
Type resolved = null; if (gsc != null) { resolved = resolve(gsc, type, parameterIndex); if (resolved == null) { } else if (rawType instanceof Class<?>) { Class<?> classRawType = (Class<?>)rawType; Type resolved = resolve(classRawType, type, parameterIndex); if (resolved == null) { return null; for (int i = 0;i < a.length;i++) { if (a[i].equals(resolvedTV)) { return resolve(implementation, classRawType, i);
public static Class<?> resolveToClass(Type implementation, Class<?> type, int parameterIndex) { if (implementation == null) { throw new NullPointerException("No null type accepted"); } // First resolve to type Type resolvedType = resolve(implementation, type, parameterIndex); // if (resolvedType != null) { return resolveToClass(resolvedType); } else { return null; } }
public static boolean instanceOf(Class c, List<String> types) { for (String type: types) { if (instanceOf(c, type)) { return true; } } return false; }
@Override public Map<ContextualParameter, Object> getContextualArguments(Set<ContextualParameter> parameters) { Map<ContextualParameter, Object> args = super.getContextualArguments(parameters); for (ContextualParameter parameter : parameters) { ContextualParameter contextualParameter = (ContextualParameter)parameter; if (Event.class.isAssignableFrom(contextualParameter.getType())) { Class payloadType = Introspector.resolveToClass(contextualParameter.getGenericType(), Event.class, 0); if (payloadType.isInstance(req.getEvent().getValue())) { if (args.isEmpty()) { args = new HashMap<ContextualParameter, Object>(); } args.put(parameter, new Event(req.getEvent().getName(), req.getEvent().getValue())); } } } return args; }
@Test public void testBar() { class A extends ThreadLocal<String> {} Type resolved = Introspector.resolve(A.class, ThreadLocal.class, 0); assertEquals(String.class, resolved); assertEquals(String.class, Introspector.resolveToClass(A.class, ThreadLocal.class, 0)); }
public static boolean instanceOf(Class c, String type) { if (c.getName().equals(type)) { return true; } for (Class i : c.getInterfaces()) { if (instanceOf(i, type)) { return true; } } if (c.getSuperclass() != null) { return instanceOf(c.getSuperclass(), type); } return false; }
@Override public Map<ContextualParameter, Object> getContextualArguments(Set<ContextualParameter> parameters) { Map<ContextualParameter, Object> args = super.getContextualArguments(parameters); for (ContextualParameter parameter : parameters) { ContextualParameter contextualParameter = (ContextualParameter)parameter; if (Event.class.isAssignableFrom(contextualParameter.getType())) { Class payloadType = Introspector.resolveToClass(contextualParameter.getGenericType(), Event.class, 0); if (payloadType.isInstance(req.getEvent().getValue())) { if (args.isEmpty()) { args = new HashMap<ContextualParameter, Object>(); } args.put(parameter, new Event(req.getEvent().getName(), req.getEvent().getValue())); } } } return args; }
@Test public void testJuu() { class A extends InheritableThreadLocal<String> {} Type resolved = Introspector.resolve(A.class, ThreadLocal.class, 0); assertEquals(String.class, resolved); assertEquals(String.class, Introspector.resolveToClass(A.class, ThreadLocal.class, 0)); }
public static boolean instanceOf(Class c, String type) { if (c.getName().equals(type)) { return true; } for (Class i : c.getInterfaces()) { if (instanceOf(i, type)) { return true; } } if (c.getSuperclass() != null) { return instanceOf(c.getSuperclass(), type); } return false; }
@Test public void testJuu() { class A extends InheritableThreadLocal<String> {} Type resolved = Introspector.resolve(A.class, ThreadLocal.class, 0); assertEquals(String.class, resolved); assertEquals(String.class, Introspector.resolveToClass(A.class, ThreadLocal.class, 0)); }
@Test public void testInstanceOf() { assertEquals(true, Introspector.instanceOf(String.class, "java.lang.String")); assertEquals(true, Introspector.instanceOf(ArrayList.class, "java.util.List")); assertEquals(true, Introspector.instanceOf(List.class, "java.util.List")); assertEquals(true, Introspector.instanceOf(ArrayList.class, "java.util.AbstractList")); assertEquals(true, Introspector.instanceOf(ArrayList.class, "java.util.AbstractCollection")); assertEquals(false, Introspector.instanceOf(String.class, "java.lang.Integer")); }
@Test public void testBar() { class A extends ThreadLocal<String> {} Type resolved = Introspector.resolve(A.class, ThreadLocal.class, 0); assertEquals(String.class, resolved); assertEquals(String.class, Introspector.resolveToClass(A.class, ThreadLocal.class, 0)); }
@Test public void testInstanceOf() { assertEquals(true, Introspector.instanceOf(String.class, "java.lang.String")); assertEquals(true, Introspector.instanceOf(ArrayList.class, "java.util.List")); assertEquals(true, Introspector.instanceOf(List.class, "java.util.List")); assertEquals(true, Introspector.instanceOf(ArrayList.class, "java.util.AbstractList")); assertEquals(true, Introspector.instanceOf(ArrayList.class, "java.util.AbstractCollection")); assertEquals(false, Introspector.instanceOf(String.class, "java.lang.Integer")); }
@Test public void testDaa() { Type resolved = Introspector.resolve(InheritableThreadLocal.class, ThreadLocal.class, 0); assertTrue(resolved instanceof TypeVariable); TypeVariable tv = (TypeVariable)resolved; assertEquals(InheritableThreadLocal.class, tv.getGenericDeclaration()); assertEquals(Object.class, Introspector.resolveToClass(InheritableThreadLocal.class, ThreadLocal.class, 0)); }
@Test public void testInstanceOfList() { assertEquals(true, Introspector.instanceOf(String.class, Arrays.asList("java.lang.String", "java.lang.Integer"))); assertEquals(true, Introspector.instanceOf(String.class, Arrays.asList("java.lang.Integer", "java.lang.String"))); assertEquals(false, Introspector.instanceOf(String.class, Arrays.asList("java.lang.Boolean", "java.lang.Integer"))); } }