List of usage examples for java.lang Class cast
@SuppressWarnings("unchecked") @HotSpotIntrinsicCandidate public T cast(Object obj)
From source file:com.googlesource.gerrit.plugins.rabbitmq.config.PluginProperties.java
@Override public <T extends Section> T getSection(Class<T> clazz) { for (Section section : sections) { if (section.getClass() == clazz) { return clazz.cast(section); }/* ww w. j a va 2s. co m*/ } return null; }
From source file:com.nominanuda.hyperapi.HttpClientHyperApiFactory.java
public <T> T getInstance(String instanceHint, Class<? extends T> cl) { InvocationHandler handler = new HyperApiHttpInvocationHandler(cl, client, ifNull(uriPrefix, "") + ifNull(instanceHint, "")); Object p = Proxy.newProxyInstance(cl.getClassLoader(), new Class[] { cl }, handler); return cl.cast(p); }
From source file:org.apache.taverna.scufl2.rdfxml.ParserState.java
public <T extends WorkflowBean> T getCurrent(Class<T> beanType) { if (getStack().isEmpty()) throw new IllegalStateException("Parser stack is empty"); if (beanType.isInstance(getStack().peek())) return beanType.cast(getStack().peek()); T candidate = null;//from w w w. j a va 2s .c om for (WorkflowBean bean : getStack()) if (beanType.isInstance(bean)) // Don't return - we want the *last* candidate candidate = beanType.cast(bean); if (candidate == null) throw new IllegalStateException("Could not find a " + beanType + " on parser stack"); return candidate; }
From source file:com.shigengyu.hyperion.core.TransitionParameterSet.java
public <T> T get(final Class<T> clazz, String name) { if (parameters.containsKey(name)) { Object value = parameters.get(name).getValue(); if (value == null) { return null; }//from ww w . ja v a 2s. co m try { return clazz.cast(value); } catch (ClassCastException e) { throw new WorkflowExecutionException("Cannot cast value of transition parameter [" + name + "] from type [" + value.getClass().getName() + "] to type [" + clazz.getName() + "]"); } } else { return null; } }
From source file:jp.go.aist.six.util.core.xml.castor.CastorXmlMapper.java
public <T> T unmarshal(final Source source, final Class<T> type) { Object obj = unmarshal(source); return type.cast(obj); }
From source file:jp.go.aist.six.util.core.xml.castor.CastorXmlMapper.java
public <T> T unmarshal(final InputStream stream, final Class<T> type) { Object obj = unmarshal(stream); return type.cast(obj); }
From source file:jp.go.aist.six.util.core.xml.castor.CastorXmlMapper.java
public <T> T unmarshal(final Reader reader, final Class<T> type) { Object obj = unmarshal(reader); return type.cast(obj); }
From source file:edu.jhuapl.graphs.jfreechart.JFreeChartBaseSource.java
protected <T> T getParam(Map<String, Object> params, String fieldName, Class<T> klazz, T defaultValue) { Object val = params.get(fieldName); if (klazz.isInstance(val)) { return klazz.cast(val); } else {/*w w w . ja v a 2s.c om*/ return defaultValue; } }
From source file:hudson.util.PersistedList.java
public <U extends T> U get(Class<U> type) { for (T t : data) if (type.isInstance(t)) return type.cast(t); return null;/*from ww w . jav a 2 s . c o m*/ }
From source file:org.jsfr.json.provider.JacksonProvider.java
@Override public <T> T cast(JsonNode value, Class<T> tClass) { try {/*from w w w.j a va2 s .c om*/ if (om.canDeserialize(om.getTypeFactory().constructType(tClass))) { return om.treeToValue(value, tClass); } else { return tClass.cast(value); } } catch (JsonProcessingException e) { throw new JsonSurfingException(e); } }