/** * Return the qualified name of the given class: usually simply * the class name, but component type class name + "[]" for arrays. * @param clazz the class * @return the qualified name of the class */ public static String getQualifiedName(Class<?> clazz) { Assert.notNull(clazz, "Class must not be null"); return clazz.getTypeName(); }
/** * Check whether the given class matches the user-specified type name. * @param clazz the class to check * @param typeName the type name to match */ public static boolean matchesTypeName(Class<?> clazz, @Nullable String typeName) { return (typeName != null && (typeName.equals(clazz.getTypeName()) || typeName.equals(clazz.getSimpleName()))); }
/** * Return the qualified name of the given class: usually simply * the class name, but component type class name + "[]" for arrays. * @param clazz the class * @return the qualified name of the class */ public static String getQualifiedName(Class<?> clazz) { Assert.notNull(clazz, "Class must not be null"); return clazz.getTypeName(); }
/** * Properties {@link #annotationType} and {@link #reason} are <b>not</b> * included on purpose. This allows more cache hits when using instances * of this class as keys in a hash map. */ private int computeHashCode() { return Objects.hash(annotationType.getTypeName(), engine, source); }
/** * Check whether the given class matches the user-specified type name. * @param clazz the class to check * @param typeName the type name to match */ public static boolean matchesTypeName(Class<?> clazz, @Nullable String typeName) { return (typeName != null && (typeName.equals(clazz.getTypeName()) || typeName.equals(clazz.getSimpleName()))); }
/** * Return a descriptive name for the given object's type: usually simply * the class name, but component type class name + "[]" for arrays, * and an appended list of implemented interfaces for JDK proxies. * @param value the value to introspect * @return the qualified name of the class */ @Nullable public static String getDescriptiveType(@Nullable Object value) { if (value == null) { return null; } Class<?> clazz = value.getClass(); if (Proxy.isProxyClass(clazz)) { StringBuilder result = new StringBuilder(clazz.getName()); result.append(" implementing "); Class<?>[] ifcs = clazz.getInterfaces(); for (int i = 0; i < ifcs.length; i++) { result.append(ifcs[i].getName()); if (i < ifcs.length - 1) { result.append(','); } } return result.toString(); } else { return clazz.getTypeName(); } }
private <T> T convertJdbcObjectToJavaType(Class<T> javaType, Object jdbcObject) { try { return javaType.cast(jdbcObject); } catch (ClassCastException classCastException) { throw JdbcConnectorException.createException("Could not convert " + jdbcObject.getClass().getTypeName() + " to " + javaType.getTypeName(), classCastException); } }
private static boolean hasSenderAnnotation(Method method) { final Class[] paramTypes = method.getParameterTypes(); final Annotation[][] paramAnnotations = method.getParameterAnnotations(); for (int i = 0; i < paramAnnotations.length; i++) { if (paramTypes[i].getTypeName().equals(ENTITY_REF_NAME)) { if (paramAnnotations[i].length == 0) { return false; } else { for (Annotation annotation: paramAnnotations[i]) { if (annotation instanceof Sender) { return true; } } } } } return true; }
private Object getProperty(Object bean, String fieldName) { try { Object property = PropertyUtils.getProperty(bean, fieldName); if (property == null) { // in case the bean is a Map, try again with a simple property, it might be masked by the Map property = PropertyUtils.getSimpleProperty(bean, fieldName); } log.debug("[field access] property {} of bean {}: {}", fieldName, bean.getClass().getTypeName(), property); return property; } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { log.debug("Unable to read property {} from {}", fieldName, bean); return null; } }
@Override public String getId() { return getBeanClass().getTypeName() + "#jersey"; } }
private static void registerFallback() { // Register fallback handler for consumer. // If you only want to handle degrading, you need to // check the type of BlockException. DubboFallbackRegistry.setConsumerFallback((a, b, ex) -> new RpcResult("Error: " + ex.getClass().getTypeName())); } }
@Override public boolean isApplicable(MethodReference methodReference) { return classSource.isSuperType(Resource.class.getTypeName(), methodReference.getClassName()).orElse(false); }
@Override public boolean canHandle(MethodReference method) { return classSource.isSuperType(Resource.class.getTypeName(), method.getClassName()).orElse(false); }
@Test public void namingClasses() { System.out.println(ActiveEventsTest.class.getCanonicalName()); System.out.println(ActiveEventsTest.class.getName()); System.out.println(ActiveEventsTest.class.getSimpleName()); System.out.println(ActiveEventsTest.class.getPackage() .getName()); System.out.println(ActiveEventsTest.class.getTypeName()); }
@Test public void itDeserializesExceptionsWithOnlyMessageConstructor() { ObjectNode response = response( error( ThrowableSerializationMixin.ERROR_CODE, VALID_MESSAGE, data(RuntimeException.class.getTypeName()))); Throwable throwable = resolver.resolveException(response); assertThat(throwable).isInstanceOf(RuntimeException.class).hasMessage(VALID_MESSAGE); }
@Test public void itPrefersMessageFromDataOverMessageFromError() { ObjectNode response = response( error( ThrowableSerializationMixin.ERROR_CODE, VALID_MESSAGE, data(RuntimeException.class.getTypeName(), "message=" + OTHER_MESSAGE))); Throwable throwable = resolver.resolveException(response); assertThat(throwable).isInstanceOf(RuntimeException.class).hasMessage(OTHER_MESSAGE); }
@Test public void itDeserializesPojoExceptionsWithJsonCreatorConstructor() { ObjectNode response = response( error( ThrowableSerializationMixin.ERROR_CODE, VALID_MESSAGE, data(PojoTestException.class.getTypeName(), "someValue=foo", "anotherValue=bar"))); Throwable throwable = resolver.resolveException(response); assertThat(throwable) .isInstanceOf(PojoTestException.class) .hasMessage("foo:bar") .hasFieldOrPropertyWithValue("someValue", "foo") .hasFieldOrPropertyWithValue("anotherValue", "bar"); }
@Test public void itReturnsNullForOtherErrorCodes() { ObjectNode response = response( error(RANDOM_ERROR_CODE, VALID_MESSAGE, data(PojoTestException.class.getTypeName()))); Throwable throwable = resolver.resolveException(response); assertThat(throwable).isNull(); }
@Test public void itReturnsNullWhenJacksonDeserializationFails() { ObjectNode response = response( error( ThrowableSerializationMixin.ERROR_CODE, VALID_MESSAGE, data(PojoTestException.class.getTypeName(), "invalidProperty=badValue"))); Throwable throwable = resolver.resolveException(response); assertThat(throwable).isNull(); }
@Test public void getInStreamUfs() throws Exception { WorkerNetAddress worker1 = new WorkerNetAddress().setHost("worker1"); WorkerNetAddress worker2 = new WorkerNetAddress().setHost("worker2"); BlockInfo info = new BlockInfo().setBlockId(0); URIStatus dummyStatus = new URIStatus(new FileInfo().setPersisted(true).setBlockIds(Collections.singletonList(0L)) .setFileBlockInfos(Collections.singletonList(new FileBlockInfo().setBlockInfo(info)))); OpenFilePOptions readOptions = OpenFilePOptions.newBuilder() .setFileReadLocationPolicy(MockFileWriteLocationPolicy.class.getTypeName()).build(); InStreamOptions options = new InStreamOptions(dummyStatus, readOptions, sConf); ((MockFileWriteLocationPolicy) options.getUfsReadLocationPolicy()) .setHosts(Arrays.asList(worker1, worker2)); when(mMasterClient.getBlockInfo(BLOCK_ID)).thenReturn(new BlockInfo()); when(mMasterClient.getWorkerInfoList()).thenReturn( Arrays.asList(new WorkerInfo().setAddress(worker1), new WorkerInfo().setAddress(worker2))); // Location policy chooses worker1 first. assertEquals(worker1, mBlockStore.getInStream(BLOCK_ID, options).getAddress()); // Location policy chooses worker2 second. assertEquals(worker2, mBlockStore.getInStream(BLOCK_ID, options).getAddress()); }