List of usage examples for java.lang Class isInstance
@HotSpotIntrinsicCandidate public native boolean isInstance(Object obj);
From source file:com.architexa.diagrams.jdt.builder.ReloASTExtractor.java
public ASTNode getParent(Class<?> inst) { Iterator<ASTNode> it = context.iterator(); it.next(); // the first items is itself, the second one is parent while (it.hasNext()) { ASTNode node = it.next();/*from w w w . ja va2s.c om*/ if (inst.isInstance(node)) { return node; } } return null; }
From source file:edu.wisc.http.converter.xml.JaxbMarshallingHttpMessageConverter.java
@Override protected Object readFromSource(Class<?> clazz, HttpHeaders headers, Source source) throws IOException { try {// www. ja va 2s.com final Unmarshaller unmarshaller = this.jaxbContext.createUnmarshaller(); Object result = unmarshaller.unmarshal(source, clazz); if (result instanceof JAXBElement<?>) { result = ((JAXBElement<?>) result).getValue(); } if (!clazz.isInstance(result)) { throw new TypeMismatchException(result, clazz); } return result; } catch (JAXBException e) { throw new HttpMessageNotReadableException("Could not read [" + clazz + "]", e); } }
From source file:com.yahoo.bullet.result.RecordBox.java
private <T> Map<String, T> asMap(Class<T> clazz, Map.Entry<String, Object>... entries) { Objects.requireNonNull(clazz); Objects.requireNonNull(entries); Map<String, T> newMap = new LinkedHashMap<>(entries.length); for (Map.Entry<String, Object> entry : entries) { Object object = entry.getValue(); if (object != null && !clazz.isInstance(object)) { throw new RuntimeException("Object " + object + " is not an instance of class " + clazz.getName()); }/*from ww w .j av a2 s . c om*/ newMap.put(entry.getKey(), (T) entry.getValue()); } return newMap; }
From source file:org.nobel.highriseapi.mapper.SimpleXmlHttpMessageConverter.java
@Override protected Object readInternal(Class<? extends Object> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException { Reader source = new InputStreamReader(inputMessage.getBody(), getCharset(inputMessage.getHeaders())); try {//w w w . j a v a 2 s .c o m Object result = this.serializer.read(clazz, source); if (!clazz.isInstance(result)) { throw new TypeMismatchException(result, clazz); } return result; } catch (Exception ex) { throw new HttpMessageNotReadableException("Could not read [" + clazz + "]", ex); } }
From source file:org.carewebframework.api.AppFramework.java
/** * Finds a registered object belonging to the specified class. * //from w w w .j a v a2s . co m * @param clazz Returned object must be assignment-compatible with this class. * @param previousInstance Previous instance returned by this call. Search will start with the * entry that follows this one in the list. If this parameter is null, the search * starts at the beginning. * @return Reference to the discovered object or null if none found. */ public synchronized Object findObject(Class<?> clazz, Object previousInstance) { int i = previousInstance == null ? -1 : MiscUtil.indexOfInstance(registeredObjects, previousInstance); for (i++; i < registeredObjects.size(); i++) { Object object = registeredObjects.get(i); if (clazz.isInstance(object)) { return object; } } return null; }
From source file:com.jaliansystems.activeMQLite.impl.ObjectRepository.java
/** * Publish an object./*from w w w. ja v a 2 s .c o m*/ * * @param o * the object * @param iface * the interface implemented by the object. * @return the object handle */ public ObjectHandle publish(Object o, Class<?> iface) { if (!iface.isInterface()) throw new IllegalAccessError("Only objects that implement interfaces can be exported"); if (!iface.isInstance(o)) throw new IllegalArgumentException("The object should implement the interface"); publishedInterfaces.put(iface, o); exportedInterfaces.add(iface); return createHandle(o, iface); }
From source file:com.aw.swing.mvp.action.ActionResolver.java
public List<Action> getActionsOfType(Class clazz) { List<Action> allActionsOfType = new ArrayList(); Collection allActions = actions.values(); for (Iterator iterator = allActions.iterator(); iterator.hasNext();) { Action action = (Action) iterator.next(); if (clazz.isInstance(action)) { allActionsOfType.add(action); }//from w w w . j av a 2 s.c o m } return allActionsOfType; }
From source file:com.github.adejanovski.cassandra.jdbc.CassandraStatement.java
public <T> T unwrap(Class<T> iface) throws SQLException { if (iface.isInstance(this)) return iface.cast(this); throw new SQLFeatureNotSupportedException(String.format(NO_INTERFACE, iface.getSimpleName())); }
From source file:SampleAWTRenderer.java
/** * Return the control based on a control type for the PlugIn. *//*w ww.j a v a 2 s .c o m*/ public Object getControl(String controlType) { try { Class cls = Class.forName(controlType); Object cs[] = getControls(); for (int i = 0; i < cs.length; i++) { if (cls.isInstance(cs[i])) return cs[i]; } return null; } catch (Exception e) { // no such controlType or such control return null; } }
From source file:com.jaeksoft.searchlib.webservice.query.CommonQuery.java
@SuppressWarnings("unchecked") protected <T extends AbstractRequest> T getRequest(Client client, String template, Class<T> requestClass) throws SearchLibException { if (template == null || template.length() == 0) return null; AbstractRequest request = client.getNewRequest(template); if (!requestClass.isInstance(request)) throw new CommonServiceException( "The template " + template + " don't have the expected type: " + request.getType().getLabel()); return (T) request; }