List of usage examples for java.lang Class isInstance
@HotSpotIntrinsicCandidate public native boolean isInstance(Object obj);
From source file:me.j360.dubbo.modules.util.base.ExceptionUtil.java
/** * ??.//from w w w.ja v a2s . c o m */ @SuppressWarnings("unchecked") public static boolean isCausedBy(Throwable t, Class<? extends Exception>... causeExceptionClasses) { Throwable cause = t; while (cause != null) { for (Class<? extends Exception> causeClass : causeExceptionClasses) { if (causeClass.isInstance(cause)) { return true; } } cause = cause.getCause(); } return false; }
From source file:com.bluexml.side.build.tools.graph.jung.algorithms.GraphFilter.java
public static boolean testClassName(Object o, String name) { Class<?> forName; try {/* w w w . ja v a 2s . co m*/ forName = Class.forName("com.bluexml.side.build.tools.componants." + name); return forName.isInstance(o); } catch (ClassNotFoundException e) { logger.error(e.getMessage(), e); } return false; }
From source file:io.fabric8.devops.ProjectConfigs.java
/** * Configures the given {@link ProjectConfig} with a map of key value pairs from * something like a JBoss Forge command/*from ww w.j a v a2 s. co m*/ */ public static void configureProperties(ProjectConfig config, Map map) { Class<? extends ProjectConfig> clazz = config.getClass(); BeanInfo beanInfo = null; try { beanInfo = Introspector.getBeanInfo(clazz); } catch (IntrospectionException e) { LOG.warn("Could not introspect " + clazz.getName() + ". " + e, e); } if (beanInfo != null) { PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); for (PropertyDescriptor descriptor : propertyDescriptors) { Method writeMethod = descriptor.getWriteMethod(); if (writeMethod != null) { String name = descriptor.getName(); Object value = map.get(name); if (value != null) { Object safeValue = null; Class<?> propertyType = descriptor.getPropertyType(); if (propertyType.isInstance(value)) { safeValue = value; } else { PropertyEditor editor = descriptor.createPropertyEditor(config); if (editor == null) { editor = PropertyEditorManager.findEditor(propertyType); } if (editor != null) { String text = value.toString(); editor.setAsText(text); safeValue = editor.getValue(); } else { LOG.warn("Cannot update property " + name + " with value " + value + " of type " + propertyType.getName() + " on " + clazz.getName()); } } if (safeValue != null) { try { writeMethod.invoke(config, safeValue); } catch (Exception e) { LOG.warn("Failed to set property " + name + " with value " + value + " on " + clazz.getName() + " " + config + ". " + e, e); } } } } } } String flow = null; Object flowValue = map.get("pipeline"); if (flowValue == null) { flowValue = map.get("flow"); } if (flowValue != null) { flow = flowValue.toString(); } config.setPipeline(flow); }
From source file:de.laures.cewolf.taglib.CewolfChartFactory.java
/** * Helper to check if the given dataset is the expected type. * @param data The dataset//from w ww.j a v a2s . c o m * @param clazz Expected type (class) * @param chartType The chart type string * @throws IncompatibleDatasetException If not the expected class */ public static void check(Dataset data, Class clazz, String chartType) throws IncompatibleDatasetException { if (!clazz.isInstance(data)) { throw new IncompatibleDatasetException( "Charts of type " + chartType + " " + "need datasets of type " + clazz.getName()); } }
From source file:com.vmware.admiral.compute.container.volume.VolumeUtil.java
private static <T extends ResourceState> Map<String, T> filterDescriptions(Class<T> clazz, Collection<ComponentDescription> componentDescriptions) { return componentDescriptions.stream().filter(cd -> clazz.isInstance(cd.getServiceDocument())) .map(cd -> clazz.cast(cd.getServiceDocument())).collect(Collectors.toMap(c -> c.name, c -> c)); }
From source file:de.thorstenberger.taskmodel.complex.complextaskhandling.subtasklets.impl.SubTasklet_MCBuilder.java
/** * Return all instances of <code>clazz</code> from the given list. * * @param correctOrIncorrect/*from w w w. j a v a 2 s . c o m*/ * @param clazz * @return */ static int[] getIndices(List correctOrIncorrect, Class<?> clazz) { List<Integer> selected = new ArrayList<Integer>(); int idx = 0; for (Object o : correctOrIncorrect) { if (clazz.isInstance(o)) { selected.add(idx); } idx++; } return ArrayUtils.toPrimitive(selected.toArray(new Integer[selected.size()])); }
From source file:cc.sion.core.utils.Exceptions.java
/** * ??.//from www . j av a2 s . co m */ public static boolean isCausedBy(Exception ex, Class<? extends Exception>... causeExceptionClasses) { Throwable cause = ex; while (cause != null) { for (Class<? extends Exception> causeClass : causeExceptionClasses) { if (causeClass.isInstance(cause)) { return true; } } cause = cause.getCause(); } return false; }
From source file:cc.sion.core.utils.Exceptions.java
/** * ??.//from w ww. j a v a2 s . c om */ public static boolean isCausedBy(Throwable t, Class<? extends Exception>... causeExceptionClasses) { Throwable cause = t; while (cause != null) { for (Class<? extends Exception> causeClass : causeExceptionClasses) { if (causeClass.isInstance(cause)) { return true; } } cause = cause.getCause(); } return false; }
From source file:com.icesoft.faces.util.CoreUtils.java
public static boolean isPortletEnvironment() { if (portletEnvironment == null) { try {// w w w . j av a 2s. c o m Class portletRequestClass = Class.forName("javax.portlet.PortletRequest"); portletEnvironment = new Boolean(portletRequestClass .isInstance(FacesContext.getCurrentInstance().getExternalContext().getRequest())); } catch (Throwable e) { //both ClassNotFoundException and NoClassDefError //portlet not found portletEnvironment = Boolean.FALSE; } } return portletEnvironment.booleanValue(); }
From source file:com.excilys.ebi.bank.util.Asserts.java
public static void isInstanceOf(Class<?> type, Object obj, String messagePattern, Object arg) { notNull(type, "Type to check against must not be null"); if (!type.isInstance(obj)) { throw new IllegalArgumentException(MessageFormatter.format(messagePattern, arg).getMessage() + " Object of class [" + (obj != null ? obj.getClass().getName() : "null") + "] must be an instance of " + type); }//from ww w .jav a 2s . c om }