List of usage examples for java.lang Class isInterface
@HotSpotIntrinsicCandidate public native boolean isInterface();
From source file:org.grouplens.grapht.util.Types.java
/** * <p>/*w w w. j a v a2 s. co m*/ * Return true if the type is not abstract and not an interface. This will * return true essentially when the class "should" have a default * constructor or a constructor annotated with {@link Inject @Inject} to be * used properly. * <p> * As another special rule, if the input type is {@link Void}, false is * returned because for most intents and purposes, it is not instantiable. * * @param type The type to test * @return True if it should be instantiable */ public static boolean shouldBeInstantiable(Class<?> type) { return !Modifier.isAbstract(type.getModifiers()) && !type.isInterface() && !Void.class.equals(type); }
From source file:org.bremersee.comparator.ObjectComparatorImpl.java
private static Method findMethod(Class<?> clazz, String name, Class<?>... paramTypes) { Class<?> searchType = clazz; while (searchType != null) { Method[] methods = (searchType.isInterface() ? searchType.getMethods() : searchType.getDeclaredMethods()); for (Method method : methods) { if (name.equals(method.getName()) && (paramTypes == null || Arrays.equals(paramTypes, method.getParameterTypes()))) { return method; }/*from w w w. j av a 2 s . com*/ } searchType = searchType.getSuperclass(); } return null; }
From source file:org.beanfuse.struts2.action.helper.QueryHelper.java
/** * ????//from w w w .jav a 2 s . com * * @param clazz * @param prefix * @param exclusiveAttrNames * @return */ public static List extractConditions(Class clazz, String prefix, String exclusiveAttrNames) { Object entity = null; try { if (clazz.isInterface()) { EntityType entityType = Model.getEntityType(clazz.getName()); clazz = entityType.getEntityClass(); } entity = clazz.newInstance(); } catch (Exception e) { throw new RuntimeException("[RequestUtil.extractConditions]: error in in initialize " + clazz); } List conditions = new ArrayList(); HttpServletRequest request = ServletActionContext.getRequest(); Map params = ParamHelper.getParams(prefix, exclusiveAttrNames); for (Iterator iter = params.keySet().iterator(); iter.hasNext();) { String attr = (String) iter.next(); String strValue = ((String) params.get(attr)).trim(); // if (StringUtils.isNotEmpty(strValue)) { try { if (RESERVED_NULL && "null".equals(strValue)) { conditions.add(new Condition(prefix + "." + attr + " is null")); } else { Model.getPopulator().populateValue(attr, strValue, entity); Object settedValue = PropertyUtils.getProperty(entity, attr); if (null == settedValue) continue; if (settedValue instanceof String) { conditions.add(new Condition(prefix + "." + attr + " like :" + attr.replace('.', '_'), "%" + (String) settedValue + "%")); } else { conditions.add(new Condition(prefix + "." + attr + "=:" + attr.replace('.', '_'), settedValue)); } } } catch (Exception e) { logger.debug( "[populateFromParams]:error in populate entity " + prefix + "'s attribute " + attr); } } } return conditions; }
From source file:org.grouplens.grapht.util.Types.java
/** * Return true if the type is not abstract and not an interface, and has * a constructor annotated with {@link Inject} or its only constructor * is the default constructor.//from www. j a v a 2 s . c o m * * @param type A class type * @return True if the class type is instantiable */ public static boolean isInstantiable(Class<?> type) { if (!Modifier.isAbstract(type.getModifiers()) && !type.isInterface()) { // first check for a constructor annotated with @Inject, // - this doesn't care how many we'll let the injector complain // if there are more than one for (Constructor<?> c : type.getDeclaredConstructors()) { if (c.getAnnotation(Inject.class) != null) { return true; } } // check if we only have the public default constructor if (type.getConstructors().length == 1 && type.getConstructors()[0].getParameterTypes().length == 0) { return true; } } // no constructor available return false; }
From source file:com.eatnumber1.util.cglib.EnhancerUtils.java
private static Enhancer getEnhancer(@NotNull Class<?> type, @Nullable Class<?>... interfaces) { Enhancer enhancer = new Enhancer(); List<Class<?>> interfaceList = interfaces == null ? new ArrayList<Class<?>>() : new ArrayList<Class<?>>(Arrays.asList(interfaces)); if (type.isInterface()) { interfaceList.add(type);/*from ww w . j a va2 s. c om*/ } else { enhancer.setSuperclass(type); } enhancer.setInterfaces(interfaceList.toArray(new Class<?>[interfaceList.size()])); return enhancer; }
From source file:org.beangle.struts2.helper.QueryHelper.java
/** * ????/*from ww w . j av a2s . c om*/ * * @param clazz * @param prefix * @param exclusiveAttrNames * @return */ public static List<Condition> extractConditions(Class<?> clazz, String prefix, String exclusiveAttrNames) { Object entity = null; try { if (clazz.isInterface()) { EntityType entityType = Model.getEntityType(clazz.getName()); clazz = entityType.getEntityClass(); } entity = clazz.newInstance(); } catch (Exception e) { throw new RuntimeException("[RequestUtil.extractConditions]: error in in initialize " + clazz); } List<Condition> conditions = CollectUtils.newArrayList(); Map<String, Object> params = Params.sub(prefix, exclusiveAttrNames); for (Map.Entry<String, Object> entry : params.entrySet()) { String attr = entry.getKey(); String strValue = entry.getValue().toString().trim(); // if (StringUtils.isNotEmpty(strValue)) { try { if (RESERVED_NULL && "null".equals(strValue)) { conditions.add(new Condition(prefix + "." + attr + " is null")); } else { StringBuilder sb = new StringBuilder(); String[] keys = attr.split("\\|"); Condition condition = new Condition(null); for (String key : keys) { if (sb.length() > 0) { sb.append(" or "); } ; String namedParam = key.replace('.', '_').replace('|', '_'); Model.getPopulator().populateValue(entity, key, strValue); Object settedValue = PropertyUtils.getProperty(entity, key); if (null == settedValue) continue; if (settedValue instanceof String) { sb.append(prefix).append(".").append(key).append(" like :").append(namedParam); settedValue = "%" + settedValue + "%"; } else { sb.append(prefix).append(".").append(key).append(" = :").append(namedParam); } condition.param(settedValue); } condition.setContent(sb.toString()); conditions.add(condition); } } catch (Exception e) { logger.debug( "[populateFromParams]:error in populate entity " + prefix + "'s attribute " + attr); } } } return conditions; }
From source file:com.github.cherimojava.data.mongo.entity.EntityFactory.java
/** * Sets a default class for a given Interface, which will be used if a Add method is invoked but no underlying * object is existing yet. Supplied class must provide a parameterless public constructor and must be not abstract * * @param interfaze on for which the given implementation will be invoked * @param implementation concrete implementation of the given interface of which a new instance might be created * must have a empty constructor and can't be abstract * @param <T>//from w w w . j a v a 2 s .c o m */ public static <T> void setDefaultClass(Class<T> interfaze, Class<? extends T> implementation) { checkArgument(interfaze.isInterface(), "Can set default Classes only for interfaces"); checkArgument(!implementation.isInterface(), "Default class can't be an interface itself"); checkArgument(!Modifier.isAbstract(implementation.getModifiers()), "Implementation can't be abstract"); try { implementation.getConstructor(); } catch (NoSuchMethodException e) { throw new IllegalArgumentException( "Supplied implementation does not provide a parameterless constructor."); } interfaceImpls.put(interfaze, implementation); }
From source file:org.apache.tajo.engine.function.FunctionLoader.java
/** * This method finds and build FunctionDesc for the legacy function and UD(A)F system. * * @return A list of FunctionDescs/*from w w w. ja va 2 s .c o m*/ */ public static List<FunctionDesc> findLegacyFunctions() { List<FunctionDesc> sqlFuncs = new ArrayList<>(); Set<Class> functionClasses = ClassUtil.findClasses(Function.class, "org.apache.tajo.engine.function"); for (Class eachClass : functionClasses) { if (eachClass.isInterface() || Modifier.isAbstract(eachClass.getModifiers())) { continue; } Function function = null; try { function = (Function) eachClass.newInstance(); } catch (Exception e) { LOG.warn(eachClass + " cannot instantiate Function class because of " + e.getMessage(), e); continue; } String functionName = function.getClass().getAnnotation(Description.class).functionName(); String[] synonyms = function.getClass().getAnnotation(Description.class).synonyms(); String description = function.getClass().getAnnotation(Description.class).description(); String detail = function.getClass().getAnnotation(Description.class).detail(); String example = function.getClass().getAnnotation(Description.class).example(); TajoDataTypes.Type returnType = function.getClass().getAnnotation(Description.class).returnType(); ParamTypes[] paramArray = function.getClass().getAnnotation(Description.class).paramTypes(); String[] allFunctionNames = null; if (synonyms != null && synonyms.length > 0) { allFunctionNames = new String[1 + synonyms.length]; allFunctionNames[0] = functionName; System.arraycopy(synonyms, 0, allFunctionNames, 1, synonyms.length); } else { allFunctionNames = new String[] { functionName }; } for (String eachFunctionName : allFunctionNames) { for (ParamTypes params : paramArray) { ParamOptionTypes[] paramOptionArray; if (params.paramOptionTypes() == null || params.paramOptionTypes().getClass().getAnnotation(ParamTypes.class) == null) { paramOptionArray = new ParamOptionTypes[0]; } else { paramOptionArray = params.paramOptionTypes().getClass().getAnnotation(ParamTypes.class) .paramOptionTypes(); } TajoDataTypes.Type[] paramTypes = params.paramTypes(); if (paramOptionArray.length > 0) paramTypes = params.paramTypes().clone(); for (int i = 0; i < paramOptionArray.length + 1; i++) { FunctionDesc functionDesc = new FunctionDesc(eachFunctionName, function.getClass(), function.getFunctionType(), CatalogUtil.newSimpleDataType(returnType), paramTypes.length == 0 ? CatalogUtil.newSimpleDataTypeArray() : CatalogUtil.newSimpleDataTypeArray(paramTypes)); functionDesc.setDescription(description); functionDesc.setExample(example); functionDesc.setDetail(detail); sqlFuncs.add(functionDesc); if (i != paramOptionArray.length) { paramTypes = new TajoDataTypes.Type[paramTypes.length + paramOptionArray[i].paramOptionTypes().length]; System.arraycopy(params.paramTypes(), 0, paramTypes, 0, paramTypes.length); System.arraycopy(paramOptionArray[i].paramOptionTypes(), 0, paramTypes, paramTypes.length, paramOptionArray[i].paramOptionTypes().length); } } } } } return sqlFuncs; }
From source file:com.dsj.core.beans.CollectionFactory.java
/** * Create the most approximate map for the given map class. * <p>Tries to create the given map class. If that fails, a TreeMap or * linked Map will be used as fallback for a SortedMap or Map, respectively. * @param mapClass the original map class * @param initialCapacity the initial capacity * @return the new collection instance// w ww .j a v a 2 s.c o m * @see java.util.ArrayList * @see java.util.TreeSet * @see #createLinkedSetIfPossible */ public static Map createApproximateMap(Class mapClass, int initialCapacity) { Assert.notNull(mapClass, "Map class must not be null"); if (!mapClass.isInterface()) { try { return (Map) mapClass.newInstance(); } catch (Exception ex) { logger.debug("Could not instantiate map type [" + mapClass.getName() + "]: " + ex.getMessage()); } } if (SortedMap.class.isAssignableFrom(mapClass)) { return new TreeMap(); } else { return createLinkedMapIfPossible(initialCapacity); } }
From source file:com.streamsets.datacollector.definition.StageDefinitionExtractor.java
public static List<String> getGroups(Class<? extends Stage> klass) { Set<String> set = new LinkedHashSet<>(); addGroupsToList(klass, set);//from ww w . jav a 2s .c o m List<Class<?>> allSuperclasses = ClassUtils.getAllSuperclasses(klass); for (Class<?> superClass : allSuperclasses) { if (!superClass.isInterface() && superClass.isAnnotationPresent(ConfigGroups.class)) { addGroupsToList(superClass, set); } } if (set.isEmpty()) { set.add(""); // the default empty group } return new ArrayList<>(set); }