當前位置: 首頁>>代碼示例>>Java>>正文


Java ClassUtils類代碼示例

本文整理匯總了Java中org.apache.commons.lang.ClassUtils的典型用法代碼示例。如果您正苦於以下問題:Java ClassUtils類的具體用法?Java ClassUtils怎麽用?Java ClassUtils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ClassUtils類屬於org.apache.commons.lang包,在下文中一共展示了ClassUtils類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getInterfaces

import org.apache.commons.lang.ClassUtils; //導入依賴的package包/類
/**
 * Get a set of all of the interfaces that the element_class implements
 * 
 * @param element_class
 * @return
 */
@SuppressWarnings("unchecked")
public static Collection<Class<?>> getInterfaces(Class<?> element_class) {
    Set<Class<?>> ret = ClassUtil.CACHE_getInterfaceClasses.get(element_class);
    if (ret == null) {
        // ret = new HashSet<Class<?>>();
        // Queue<Class<?>> queue = new LinkedList<Class<?>>();
        // queue.add(element_class);
        // while (!queue.isEmpty()) {
        // Class<?> current = queue.poll();
        // for (Class<?> i : current.getInterfaces()) {
        // ret.add(i);
        // queue.add(i);
        // } // FOR
        // } // WHILE
        ret = new HashSet<Class<?>>(ClassUtils.getAllInterfaces(element_class));
        if (element_class.isInterface())
            ret.add(element_class);
        ret = Collections.unmodifiableSet(ret);
        ClassUtil.CACHE_getInterfaceClasses.put(element_class, ret);
    }
    return (ret);
}
 
開發者ID:s-store,項目名稱:sstore-soft,代碼行數:29,代碼來源:ClassUtil.java

示例2: TotoroBootStrap

import org.apache.commons.lang.ClassUtils; //導入依賴的package包/類
public TotoroBootStrap(final Properties conf) throws UnknownHostException {

        CanalConf canalConf = getCanalConf(conf);
        EsConf esConf = getEsConf(conf);
        int transThreadNum = getTransThreadNum(conf);
        //totoroSelector需要提前初始化好
        totoroSelector = new CanalEmbedSelector(canalConf);
        //初始化 Channel
        initChannel();
        //初始化 SelectorTask
        SelectorTask selectorTask = initSelectorTask();
        //初始化 TransFormTask
        TransFormTask transFormTask = initTransFormTask(canalConf, transThreadNum);
        //初始化 ConsumerTask
        ConsumerTask consumerTask = initConsumerTask(esConf);

        taskMap.put(ClassUtils.getShortClassName(SelectorTask.class), selectorTask);
        taskMap.put(ClassUtils.getShortClassName(TransFormTask.class), transFormTask);
        taskMap.put(ClassUtils.getShortClassName(ConsumerTask.class), consumerTask);


        logger.info("Totoro init complete .......");
    }
 
開發者ID:zhongchengxcr,項目名稱:canal-elasticsearch,代碼行數:24,代碼來源:TotoroBootStrap.java

示例3: getPrimitivePromotionCost

import org.apache.commons.lang.ClassUtils; //導入依賴的package包/類
/**
 * Get the number of steps required to promote a primitive number to another
 * type.
 * @param srcClass the (primitive) source class
 * @param destClass the (primitive) destination class
 * @return The cost of promoting the primitive
 */
private static float getPrimitivePromotionCost(final Class srcClass, final Class destClass) {
    float cost = 0.0f;
    Class cls = srcClass;
    if (!cls.isPrimitive()) {
        // slight unwrapping penalty
        cost += 0.1f;
        cls = ClassUtils.wrapperToPrimitive(cls);
    }
    for (int i = 0; cls != destClass && i < ORDERED_PRIMITIVE_TYPES.length; i++) {
        if (cls == ORDERED_PRIMITIVE_TYPES[i]) {
            cost += 0.1f;
            if (i < ORDERED_PRIMITIVE_TYPES.length - 1) {
                cls = ORDERED_PRIMITIVE_TYPES[i + 1];
            }
        }
    }
    return cost;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:26,代碼來源:MemberUtils.java

示例4: accept

import org.apache.commons.lang.ClassUtils; //導入依賴的package包/類
/**
 * Returns whether or not to append the given <code>Field</code>.
 * <ul>
 * <li>Transient fields are appended only if {@link #isAppendTransients()} returns <code>true</code>.
 * <li>Static fields are appended only if {@link #isAppendStatics()} returns <code>true</code>.
 * <li>Inner class fields are not appened.</li>
 * </ul>
 * 
 * @param field
 *            The Field to test.
 * @return Whether or not to append the given <code>Field</code>.
 */
protected boolean accept(Field field) {
    if (field.getName().indexOf(ClassUtils.INNER_CLASS_SEPARATOR_CHAR) != -1) {
        // Reject field from inner class.
        return false;
    }
    if (Modifier.isTransient(field.getModifiers()) && !this.isAppendTransients()) {
        // Reject transient fields.
        return false;
    }
    if (Modifier.isStatic(field.getModifiers()) && !this.isAppendStatics()) {
        // Reject static fields.
        return false;
    }
    if (this.getExcludeFieldNames() != null
        && Arrays.binarySearch(this.getExcludeFieldNames(), field.getName()) >= 0) {
        // Reject fields from the getExcludeFieldNames list.
        return false;
    }
    return true;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:33,代碼來源:ReflectionToStringBuilder.java

示例5: dump

import org.apache.commons.lang.ClassUtils; //導入依賴的package包/類
/**
 * 記錄請求信息
 * 
 * @param methodInvocation
 * @param take
 */
private void dump(MethodInvocation methodInvocation, Object result, long take) {
    // 取得日誌打印對象
    Logger log = getLogger(methodInvocation.getMethod().getDeclaringClass());
    Object[] args = methodInvocation.getArguments();
    StringBuffer buffer = getArgsString(args);

    if (log.isInfoEnabled()) {
        String className = ClassUtils.getShortClassName(methodInvocation.getMethod().getDeclaringClass());
        String methodName = methodInvocation.getMethod().getName();
        String resultStr = getResultString(result);

        String now = new SimpleDateFormat(DATA_FORMAT).format(new Date());
        log.info(MessageFormat.format(MESSAGE, new Object[] { className, methodName, now, take, buffer.toString(),
                resultStr }));
    }
}
 
開發者ID:luoyaogui,項目名稱:otter-G,代碼行數:23,代碼來源:LogInterceptor.java

示例6: compareReply

import org.apache.commons.lang.ClassUtils; //導入依賴的package包/類
/**
 * 將當前的符合條件的processIds和當前的reply queue進行校對,剔除不在processIds裏的內容
 */
private synchronized void compareReply(List<Long> processIds, ReplyProcessQueue replyProcessIds) {
    Object[] replyIds = replyProcessIds.toArray();
    for (Object replyId : replyIds) {
        if (processIds.contains((Long) replyId) == false) { // 判斷reply id是否在當前processId列表中
            // 因為存在並發問題,如在執行Listener事件的同時,可能觸發了process的創建,這時新建的processId會進入到reply隊列中
            // 此時接受到的processIds變量為上一個版本的內容,所以會刪除新建的process,導致整個通道被掛住
            if (CollectionUtils.isEmpty(processIds) == false) {
                Long processId = processIds.get(0);
                if (processId > (Long) replyId) { // 如果當前最小的processId都大於replyId, processId都是遞增創建的
                    logger.info("## {} remove reply id [{}]", ClassUtils.getShortClassName(this.getClass()),
                                (Long) replyId);
                    replyProcessIds.remove((Long) replyId);
                    progress.remove((Long) replyId);
                }
            }
        }
    }
}
 
開發者ID:luoyaogui,項目名稱:otter-G,代碼行數:22,代碼來源:RpcStageController.java

示例7: compareReply

import org.apache.commons.lang.ClassUtils; //導入依賴的package包/類
/**
 * 將當前的符合條件的processIds和當前的reply queue進行校對,剔除不在processIds裏的內容
 */
protected synchronized void compareReply(List<Long> processIds) {
    Object[] replyIds = replyProcessIds.toArray();
    for (Object replyId : replyIds) {
        if (processIds.contains((Long) replyId) == false) { // 判斷reply id是否在當前processId列表中
            // 因為存在並發問題,如在執行Listener事件的同時,可能觸發了process的創建,這時新建的processId會進入到reply隊列中
            // 此時接受到的processIds變量為上一個版本的內容,所以會刪除新建的process,導致整個通道被掛住
            if (CollectionUtils.isEmpty(processIds) == false) {
                Long processId = processIds.get(0);
                if (processId > (Long) replyId) { // 如果當前最小的processId都大於replyId, processId都是遞增創建的
                    logger.info("## {} remove reply id [{}]", ClassUtils.getShortClassName(this.getClass()),
                                (Long) replyId);
                    replyProcessIds.remove((Long) replyId);
                }
            }
        }
    }
}
 
開發者ID:luoyaogui,項目名稱:otter-G,代碼行數:21,代碼來源:AbstractProcessListener.java

示例8: getInterfaces

import org.apache.commons.lang.ClassUtils; //導入依賴的package包/類
/**
     * Get a set of all of the interfaces that the element_class implements
     * @param element_class
     * @return
     */
    @SuppressWarnings("unchecked")
    public static Collection<Class<?>> getInterfaces(Class<?> element_class) {
        Set<Class<?>> ret = ClassUtil.CACHE_getInterfaceClasses.get(element_class);
        if (ret == null) {
//            ret = new HashSet<Class<?>>();
//            Queue<Class<?>> queue = new LinkedList<Class<?>>();
//            queue.add(element_class);
//            while (!queue.isEmpty()) {
//                Class<?> current = queue.poll();
//                for (Class<?> i : current.getInterfaces()) {
//                    ret.add(i);
//                    queue.add(i);
//                } // FOR
//            } // WHILE
            ret = new HashSet<Class<?>>(ClassUtils.getAllInterfaces(element_class));
            if (element_class.isInterface()) ret.add(element_class);
            ret = Collections.unmodifiableSet(ret);
            ClassUtil.CACHE_getInterfaceClasses.put(element_class, ret);
        }
        return (ret);
    }
 
開發者ID:faclc4,項目名稱:HTAPBench,代碼行數:27,代碼來源:ClassUtil.java

示例9: RegionServerEnvironment

import org.apache.commons.lang.ClassUtils; //導入依賴的package包/類
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value="BC_UNCONFIRMED_CAST",
    justification="Intentional; FB has trouble detecting isAssignableFrom")
public RegionServerEnvironment(final Class<?> implClass,
    final Coprocessor impl, final int priority, final int seq,
    final Configuration conf, final RegionServerServices services) {
  super(impl, priority, seq, conf);
  this.regionServerServices = services;
  for (Object itf : ClassUtils.getAllInterfaces(implClass)) {
    Class<?> c = (Class<?>) itf;
    if (SingletonCoprocessorService.class.isAssignableFrom(c)) {// FindBugs: BC_UNCONFIRMED_CAST
      this.regionServerServices.registerService(
        ((SingletonCoprocessorService) impl).getService());
      break;
    }
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:17,代碼來源:RegionServerCoprocessorHost.java

示例10: getTickMethod

import org.apache.commons.lang.ClassUtils; //導入依賴的package包/類
private static TickMethod getTickMethod(Class clazz, Method method) {
    // Order of list is from bottom (subclass) to top (superclass).
    List<Class> superclasses = (List<Class>) ClassUtils.getAllSuperclasses(clazz);
    superclasses.add(0, clazz);
    // Loop over clazz and its superclasses
    for (Class superclass : superclasses) {
        // find and iterate over the current class' tick methods, if it has any.
        for (TickMethod tickMethod : CLASS_TICK_METHODS.get(superclass)) {
            // if the superclass TickMethod has the same method as ours, return it.
            if (ReflectionUtils.sameMethodSignature(method, tickMethod.method)) {
                return tickMethod;
            }
        }
    }
    return null;
}
 
開發者ID:BlurEngine,項目名稱:Blur,代碼行數:17,代碼來源:TickMethodsCache.java

示例11: call

import org.apache.commons.lang.ClassUtils; //導入依賴的package包/類
@Override
public Object call(Context context, List args) throws FunctionCallException {
    try {
        String clazzName = (String) (args.get(0));
        String methodName = (String) (args.get(1));
        LOGGER.info("XEditor extension function calling {} {}", clazzName, methodName);

        Class[] argTypes = new Class[args.size() - 2];
        Object[] params = new Object[args.size() - 2];
        for (int i = 0; i < argTypes.length; i++) {
            argTypes[i] = args.get(i + 2).getClass();
            params[i] = args.get(i + 2);
        }

        Class clazz = ClassUtils.getClass(clazzName);
        Method method = MethodUtils.getMatchingAccessibleMethod(clazz, methodName, argTypes);
        return method.invoke(null, params);
    } catch (Exception ex) {
        LOGGER.warn("Exception in call to external java method", ex);
        return ex.getMessage();
    }
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:23,代碼來源:MCRFunctionCallJava.java

示例12: MCRCommand

import org.apache.commons.lang.ClassUtils; //導入依賴的package包/類
public MCRCommand(Method cmd) {
    className = cmd.getDeclaringClass().getName();
    methodName = cmd.getName();
    parameterTypes = cmd.getParameterTypes();
    org.mycore.frontend.cli.annotation.MCRCommand cmdAnnotation = cmd
        .getAnnotation(org.mycore.frontend.cli.annotation.MCRCommand.class);
    help = cmdAnnotation.help();
    messageFormat = new MessageFormat(cmdAnnotation.syntax(), Locale.ROOT);
    setMethod(cmd);

    for (int i = 0; i < parameterTypes.length; i++) {
        Class<?> paramtype = parameterTypes[i];
        if (ClassUtils.isAssignable(paramtype, Integer.class, true)
            || ClassUtils.isAssignable(paramtype, Long.class, true)) {
            messageFormat.setFormat(i, NumberFormat.getIntegerInstance(Locale.ROOT));
        } else if (!String.class.isAssignableFrom(paramtype)) {
            unsupportedArgException(className + "." + methodName, paramtype.getName());
        }
    }

    int pos = cmdAnnotation.syntax().indexOf("{");
    suffix = pos == -1 ? cmdAnnotation.syntax() : cmdAnnotation.syntax().substring(0, pos);
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:24,代碼來源:MCRCommand.java

示例13: populateBean

import org.apache.commons.lang.ClassUtils; //導入依賴的package包/類
private <T> T populateBean(final T resultBean, List<Object> processedColumns, BeanCells cells) {
    for (int i = 0; i < processedColumns.size(); i++) {
        final Object fieldValue = processedColumns.get(i);

        BeanCell cell = cells.getCell(i);
        if (cell == null || cell.getType() == null) {
            continue;
        }

        // ClassUtils handles boxed types
        if (fieldValue != null && ClassUtils.isAssignable(fieldValue.getClass(), cell.getType(), true)) {
            cell.setValue(resultBean, fieldValue);
        } else {
            Class<?> fieldValueClass = fieldValue == null ? Object.class : fieldValue.getClass();
            TypeConverter<Object, Object> converter
                    = (TypeConverter<Object, Object>) typeConverterRegistry.getConverter(fieldValueClass, cell.getType());
            if (converter == null) {
                throw new SuperCsvException(Form.at("No converter registered from type {} to type {}. Add one or fix your CellProcessor-annotations to return the field's type",
                        fieldValueClass.getName(), cell.getType().getName()));
            }
            cell.setValue(resultBean, converter.convert(fieldValue));
        }
    }

    return resultBean;
}
 
開發者ID:dmn1k,項目名稱:super-csv-declarative,代碼行數:27,代碼來源:CsvDeclarativeBeanReader.java

示例14: read

import org.apache.commons.lang.ClassUtils; //導入依賴的package包/類
@Override
public Object read(Kryo kryo, Input input, Class type) {
    try {
        ObjectMap graphContext = kryo.getGraphContext();
        ObjectInputStream objectStream = (ObjectInputStream) graphContext.get(this);
        if (objectStream == null) {
            objectStream = new ObjectInputStream(input) {
                @Override
                protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
                    return ClassUtils.getClass(KryoSerialization.class.getClassLoader(), desc.getName());
                }
            };
            graphContext.put(this, objectStream);
        }
        return objectStream.readObject();
    } catch (Exception ex) {
        throw new KryoException("Error during Java deserialization.", ex);
    }
}
 
開發者ID:cuba-platform,項目名稱:cuba,代碼行數:20,代碼來源:KryoSerialization.java

示例15: propertyBelongsTo

import org.apache.commons.lang.ClassUtils; //導入依賴的package包/類
private boolean propertyBelongsTo(Field field, MetaProperty metaProperty, List<Class> systemInterfaces) {
    String getterName = "get" + StringUtils.capitalize(metaProperty.getName());

    Class<?> aClass = field.getDeclaringClass();
    //noinspection unchecked
    List<Class> allInterfaces = ClassUtils.getAllInterfaces(aClass);
    for (Class intf : allInterfaces) {
        Method[] methods = intf.getDeclaredMethods();
        for (Method method : methods) {
            if (method.getName().equals(getterName) && method.getParameterTypes().length == 0) {
                if (systemInterfaces.contains(intf))
                    return true;
            }
        }
    }
    return false;
}
 
開發者ID:cuba-platform,項目名稱:cuba,代碼行數:18,代碼來源:MetaModelLoader.java


注:本文中的org.apache.commons.lang.ClassUtils類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。