List of usage examples for java.lang Class cast
@SuppressWarnings("unchecked") @HotSpotIntrinsicCandidate public T cast(Object obj)
From source file:com.liferay.portal.spring.extender.internal.bean.ApplicationContextServicePublisher.java
protected Set<Class<?>> getInterfaces(Object object) throws Exception { Class<? extends Object> clazz = getTargetClass(object); OSGiBeanProperties osgiBeanProperties = AnnotationUtils.findAnnotation(clazz, OSGiBeanProperties.class); if (osgiBeanProperties == null) { return new HashSet<>(Arrays.asList(ReflectionUtil.getInterfaces(object))); }//from w w w . j a v a2s. c o m Class<?>[] serviceClasses = osgiBeanProperties.service(); if (serviceClasses.length == 0) { return new HashSet<>(Arrays.asList(ReflectionUtil.getInterfaces(object))); } for (Class<?> serviceClazz : serviceClasses) { serviceClazz.cast(object); } return new HashSet<>(Arrays.asList(osgiBeanProperties.service())); }
From source file:ch.algotrader.config.ConfigLocator.java
public <T> T getConfig(final Class<T> clazz) { if (clazz == null) { return null; }//from ww w . j a va 2 s.c o m synchronized (this.beanMap) { T bean = clazz.cast(this.beanMap.get(clazz)); if (bean == null) { bean = new ConfigBeanFactory().create(this.configParams, clazz); this.beanMap.put(clazz, bean); } return bean; } }
From source file:com.github.rinde.rinsim.core.model.rand.RandomModel.java
@Override @Nonnull/*from ww w . j a v a 2s. c om*/ public <U> U get(Class<U> clazz) { if (clazz == RandomProvider.class) { return clazz.cast(new RngProvider()); } throw new IllegalArgumentException(); }
From source file:org.jboss.spring.deployers.AbstractSpringMetaDataDeployer.java
/** * Do a jndi lookup for bean factory.//www . j a va 2 s. com * * @param name the jndi name * @return bean factory instance * @throws Exception for any exception */ protected T lookup(String name) throws Exception { Class<T> beanFactoryClass = getExactBeanFactoryClass(); T beanFactory = beanFactoryClass.cast(Util.lookup(name, beanFactoryClass)); if (log.isTraceEnabled()) { log.trace("Found Spring bean factory [" + name + "]: " + beanFactory); } return beanFactory; }
From source file:org.openrdf.repository.sail.SailRepository.java
private <T> T findSailOf(Sail sail, Class<T> type) { if (type.isInstance(sail)) { return type.cast(sail); } else if (sail instanceof StackableSail) { return findSailOf(((StackableSail) sail).getBaseSail(), type); } else {/* w ww .j a v a 2 s. c o m*/ return null; } }
From source file:com.flexive.cmis.spi.FlexiveRepository.java
public <T> T getExtension(Class<T> klass) { if (klass == CopyDocumentExtension.class) { return klass.cast(CopyDocument.getInstance()); }/*from w w w. j a v a2 s.co m*/ return null; }
From source file:de.perdian.commons.i18n.polyglot.PolyglotImpl.java
@Override public T getInstance(Locale locale) { if (locale == null) { throw new IllegalArgumentException("Parameter 'locale' must not be null"); } else {// w w w . j av a 2s .co m T cachedInstance = this.getLocaleToInstanceCache().get(locale); if (cachedInstance == null) { Class<T> instanceClass = this.getInstanceClass(); cachedInstance = instanceClass.cast(Proxy.newProxyInstance(instanceClass.getClassLoader(), new Class[] { instanceClass }, this.createInvocationHandler(locale))); this.getLocaleToInstanceCache().put(locale, cachedInstance); } return cachedInstance; } }
From source file:hudson.model.Actionable.java
/** * Gets all actions of a specified type that contributed to this build. * * @param type The type of action to return. * @return//w w w. jav a 2 s . c om * may be empty but never null. * @see #getAction(Class) */ public <T extends Action> List<T> getActions(Class<T> type) { List<T> result = new Vector<T>(); for (Action a : getActions()) if (type.isInstance(a)) result.add(type.cast(a)); return result; }
From source file:ratpack.jackson.internal.JsonParser.java
@Override public <T> T parse(Context context, TypedData body, Parse<T, JsonParseOpts> parse) { JsonParseOpts opts = parse.getOpts(); Class<T> type = parse.getType(); ObjectMapper objectMapper = getObjectMapper(opts); try {// w w w. j av a 2 s. c o m InputStream inputStream = body.getInputStream(); if (type.equals(JsonNode.class)) { return type.cast(objectMapper.readTree(inputStream)); } else { return objectMapper.readValue(inputStream, type); } } catch (IOException e) { throw uncheck(e); } }
From source file:com.medallia.tiny.ObjectProvider.java
/** * Ensures that o is of type X and registers it. * Casts a {@link ClassCastException} if o is not of type X * @return this ObjectProvider// w w w . jav a 2 s. co m */ public <X> ObjectProvider castAndRegister(Class<X> c, Object o) { return register(c, c.cast(o)); }