当前位置: 首页>>代码示例>>Java>>正文


Java ClassUtils类代码示例

本文整理汇总了Java中org.apache.commons.lang3.ClassUtils的典型用法代码示例。如果您正苦于以下问题:Java ClassUtils类的具体用法?Java ClassUtils怎么用?Java ClassUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ClassUtils类属于org.apache.commons.lang3包,在下文中一共展示了ClassUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: newCredentialSelectionPredicate

import org.apache.commons.lang3.ClassUtils; //导入依赖的package包/类
/**
 * Gets credential selection predicate.
 *
 * @param selectionCriteria the selection criteria
 * @return the credential selection predicate
 */
public static Predicate<org.apereo.cas.authentication.Credential> newCredentialSelectionPredicate(final String selectionCriteria) {
    try {
        if (StringUtils.isBlank(selectionCriteria)) {
            return credential -> true;
        }

        if (selectionCriteria.endsWith(".groovy")) {
            final ResourceLoader loader = new DefaultResourceLoader();
            final Resource resource = loader.getResource(selectionCriteria);
            if (resource != null) {
                final String script = IOUtils.toString(resource.getInputStream(), StandardCharsets.UTF_8);
                final GroovyClassLoader classLoader = new GroovyClassLoader(Beans.class.getClassLoader(),
                        new CompilerConfiguration(), true);
                final Class<Predicate> clz = classLoader.parseClass(script);
                return clz.newInstance();
            }
        }

        final Class predicateClazz = ClassUtils.getClass(selectionCriteria);
        return (Predicate<org.apereo.cas.authentication.Credential>) predicateClazz.newInstance();
    } catch (final Exception e) {
        final Predicate<String> predicate = Pattern.compile(selectionCriteria).asPredicate();
        return credential -> predicate.test(credential.getId());
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:32,代码来源:Beans.java

示例2: chooseStrategy

import org.apache.commons.lang3.ClassUtils; //导入依赖的package包/类
private JdbcAnnotatedRepositoryQuery.Strategy chooseStrategy(JdbcQueryMethod method) {
    Class<?> returnType = method.getReturnedObjectType();
    if (returnType.isPrimitive()) {
        returnType = ClassUtils.primitiveToWrapper(returnType);
    }
    // TODO think a better way of handling this by the method name
    if (Number.class.isAssignableFrom(returnType)) {
        return JdbcAnnotatedRepositoryQuery.Strategy.COUNT;
    }
    if (Boolean.class.isAssignableFrom(returnType)) {
        return JdbcAnnotatedRepositoryQuery.Strategy.EXISTS_QUERY;
    }
    if (method.isCollectionQuery()) {
        return JdbcAnnotatedRepositoryQuery.Strategy.COLLECTION_QUERY;
    }
    if (method.isQueryForEntity()) {
        return JdbcAnnotatedRepositoryQuery.Strategy.SINGLE_QUERY;
    }
    if (method.isPageQuery()) {
        return JdbcAnnotatedRepositoryQuery.Strategy.PAGE_QUERY;
    }
    if (void.class.isAssignableFrom(returnType)) {
        return JdbcAnnotatedRepositoryQuery.Strategy.UPDATE_QUERY;
    }
    throw new IllegalArgumentException("Don't know what strategy to follow!!");
}
 
开发者ID:rubasace,项目名称:spring-data-jdbc,代码行数:27,代码来源:JdbcAnnotatedRepositoryQueryCreator.java

示例3: handleUnknownTypeId

import org.apache.commons.lang3.ClassUtils; //导入依赖的package包/类
@Override
public JavaType handleUnknownTypeId(final DeserializationContext ctxt, final JavaType baseType,
                                    final String subTypeId, final TypeIdResolver idResolver,
                                    final String failureMsg) throws IOException {

    try {
        if (subTypeId.contains("org.jasig.")) {
            final String newTypeName = subTypeId.replaceAll("jasig", "apereo");
            LOGGER.warn("Found legacy CAS JSON definition type identified as [{}]. "
                            + "While CAS will attempt to convert the legacy definition to [{}] for the time being, "
                            + "the definition SHOULD manually be upgraded to the new supported syntax",
                    subTypeId, newTypeName);
            final Class newType = ClassUtils.getClass(newTypeName);
            return SimpleType.construct(newType);
        }
        return null;
    } catch (final Exception e) {
        throw Throwables.propagate(e);
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:21,代码来源:JasigRegisteredServiceDeserializationProblemHandler.java

示例4: getMethod

import org.apache.commons.lang3.ClassUtils; //导入依赖的package包/类
private static MethodSpec getMethod(ClassName name, Key key) {
	Class<?> type = parseTypeFormat(key.getType(), key.getFormat());
	if(type.isPrimitive()) {
		type = ClassUtils.primitiveToWrapper(type);
	}
	
	ParameterSpec parameter = ParameterSpec.builder(type, key.getId()).build();
	
	return MethodSpec.methodBuilder(key.getId())
			.addModifiers(Modifier.PUBLIC, Modifier.FINAL)
			.addParameter(parameter)
			.addStatement("this.$N = $N", key.getId(), parameter)
			.addJavadoc(key.getDescription())
			.returns(name)
			.addStatement("return this")
			.build();
}
 
开发者ID:skjolber,项目名称:json-log-domain,代码行数:18,代码来源:MarkerGenerator.java

示例5: byteVectorToByteArray

import org.apache.commons.lang3.ClassUtils; //导入依赖的package包/类
protected byte[] byteVectorToByteArray(Vector<?> _vector) {
    if (_vector == null) {
        return null;
    }
    if (_vector.isEmpty()) {
        return new byte[] {};
    }

    if (!ClassUtils.isAssignable(byte.class, _vector.get(0).getClass())) {
        return null;
    }

    byte[] result = new byte[_vector.size()];
    for (int i = 0; i < _vector.size(); i++) {
        Object x = _vector.get(i);
        result[i] = (byte) x;
    }

    return result;
}
 
开发者ID:hypfvieh,项目名称:bluez-dbus,代码行数:21,代码来源:AbstractBluetoothObject.java

示例6: scanToAutoEnable

import org.apache.commons.lang3.ClassUtils; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
@Override
public void scanToAutoEnable() {
    List<Object> autoEnabled = new ArrayList<>();
    getScriptEngine().getBindings(ScriptContext.ENGINE_SCOPE).forEach((key, value) -> {
        Object evalResult = value != null ? eval(key + ".class") : null;

        if (evalResult != null && evalResult instanceof Class) {
            Class cls = (Class) evalResult;

            if (PROCESSOR_CLASSES.values().stream()
                    .filter(processorClass -> !cls.equals(processorClass) && ClassUtils.isAssignable(cls, processorClass)).findFirst()
                    .isPresent()) {
                if (!isProcessorAbstract(key)) {
                    autoEnabled.add(key);
                    ((NashornKnowledgeBaseEngineOperations) getEngineOperations()).enable(value);
                }
            }
        }
    });

    if (logger.isDebugEnabled() && !autoEnabled.isEmpty()) {
        logger.debug("Auto-enabling: {}", autoEnabled);
    }
}
 
开发者ID:softelnet,项目名称:sponge,代码行数:26,代码来源:NashornKnowledgeBaseInterpreter.java

示例7: scanToAutoEnable

import org.apache.commons.lang3.ClassUtils; //导入依赖的package包/类
@Override
public void scanToAutoEnable() {
    List<String> autoEnabled = new ArrayList<>();
    Stream.of(shell.getClassLoader().getLoadedClasses()).forEachOrdered(cls -> {
        if (PROCESSOR_CLASSES.values().stream().filter(processorClass -> ClassUtils.isAssignable(cls, processorClass)).findFirst()
                .isPresent()) {
            String name = cls.getName();
            if (!isProcessorAbstract(name)) {
                autoEnabled.add(name);
                ((GroovyKnowledgeBaseEngineOperations) getEngineOperations()).enable(cls);
            }
        }
    });

    if (logger.isDebugEnabled() && !autoEnabled.isEmpty()) {
        logger.debug("Auto-enabling: {}", autoEnabled);
    }
}
 
开发者ID:softelnet,项目名称:sponge,代码行数:19,代码来源:GroovyKnowledgeBaseInterpreter.java

示例8: scanToAutoEnable

import org.apache.commons.lang3.ClassUtils; //导入依赖的package包/类
@Override
public void scanToAutoEnable() {
    List<String> autoEnabled = new ArrayList<>();
    JvmClassMappingKt.getKotlinClass(getClass()).getNestedClasses().stream().filter(kclass -> !kclass.isAbstract())
            .forEachOrdered(kclass -> {
                if (KotlinConstants.PROCESSOR_CLASSES.values().stream()
                        .filter(processorClass -> ClassUtils.isAssignable(JvmClassMappingKt.getJavaClass(kclass), processorClass))
                        .findFirst().isPresent()) {
                    autoEnabled.add(KotlinUtils.createProcessorName(kclass));
                    getEngineOperations().enable(kclass);
                }
            });

    if (logger.isDebugEnabled() && !autoEnabled.isEmpty()) {
        logger.debug("Auto-enabling: {}", autoEnabled);
    }
}
 
开发者ID:softelnet,项目名称:sponge,代码行数:18,代码来源:KKnowledgeBase.java

示例9: scanToAutoEnable

import org.apache.commons.lang3.ClassUtils; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void scanToAutoEnable() {
    List<String> autoEnabled = new ArrayList<>();
    Arrays.stream(getClass().getDeclaredClasses()).filter(cls -> !SpongeUtils.isAbstract(cls)).forEachOrdered(cls -> {
        if (JavaConstants.PROCESSOR_CLASSES.values().stream().filter(processorClass -> ClassUtils.isAssignable(cls, processorClass))
                .findFirst().isPresent()) {
            autoEnabled.add(cls.getName());
            getEngineOperations().enableJava((Class<? extends Processor>) cls);
        }
    });

    if (logger.isDebugEnabled() && !autoEnabled.isEmpty()) {
        logger.debug("Auto-enabling: {}", autoEnabled);
    }
}
 
开发者ID:softelnet,项目名称:sponge,代码行数:17,代码来源:JKnowledgeBase.java

示例10: onStartup

import org.apache.commons.lang3.ClassUtils; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void onStartup() {
    if (server == null) {
        logger.info("Creating and starting the Py4J Server.");

        GatewayServerBuilder builder = new GatewayServerBuilder().javaPort(getJavaPort()).entryPoint(getEngine().getOperations());
        if (getSecurity() != null) {
            SSLContext sslContext = createSslContext();
            builder.serverSocketFactory(sslContext.getServerSocketFactory());
        }
        server = build(builder);

        server.start();
    } else {
        logger.info("Using the manually created Py4J Server. Note that the server should have already been started.");
    }

    if (getFacadeInterfaceName() != null) {
        try {
            setFacade((T) server.getPythonServerEntryPoint(new Class[] { ClassUtils.getClass(getFacadeInterfaceName()) }));
        } catch (Exception e) {
            throw SpongeUtils.wrapException(e);
        }
    }
}
 
开发者ID:softelnet,项目名称:sponge,代码行数:27,代码来源:GatewayServerPy4JPlugin.java

示例11: checkCast

import org.apache.commons.lang3.ClassUtils; //导入依赖的package包/类
private void checkCast(Castable castable) {
	String internalNameOfCast = castable.getInternalName();
	if (castable.getType().isPrimitive()) {
		Class<?> wrapperType = ClassUtils.primitiveToWrapper(castable.getType());
		internalNameOfCast = Type.getInternalName(wrapperType);
	}
	mv.visitTypeInsn(CHECKCAST, internalNameOfCast);
	
	if (castable.getType().isPrimitive()) {
		mv.visitMethodInsn(
				INVOKEVIRTUAL,
				internalNameOfCast,
				castable.getType().getName() + "Value",
				"()" + castable.getDescriptor(),
				false);
	}
}
 
开发者ID:Javalbert,项目名称:faster-than-reflection,代码行数:18,代码来源:ClassAccessFactory.java

示例12: createVOInputTypeNode

import org.apache.commons.lang3.ClassUtils; //导入依赖的package包/类
private static JsonElement createVOInputTypeNode(Class inputType, Type genericType) throws Exception {
	// no input maps:
	if (isTerminalType(inputType)) {
		return new JsonPrimitive(ClassUtils.getSimpleName(inputType));
	} else {
		boolean isCollection = Collection.class.isAssignableFrom(inputType);
		if (isCollection) {
			try {
				inputType = (Class) ((ParameterizedType) genericType).getActualTypeArguments()[0];
			} catch (Exception e) {
				inputType = Object.class;
			}
		}
		Collection<Method> fields = AssociationPath.listMethods(inputType, VO_METHOD_TRANSFILTER);
		if (isTerminalType(inputType) || fields.size() == 0) {
			return markMapCollection(new JsonPrimitive(ClassUtils.getSimpleName(inputType)), null, false, isCollection);
		} else {
			return markMapCollection(createVONode(fields, true), null, false, isCollection);
		}
	}
}
 
开发者ID:phoenixctms,项目名称:ctsms,代码行数:22,代码来源:IndexResource.java

示例13: createVONode

import org.apache.commons.lang3.ClassUtils; //导入依赖的package包/类
private static JsonObject createVONode(Collection<Method> fields, boolean recursive) throws Exception {
	JsonObject voNode = new JsonObject();
	if (fields != null) {
		Iterator<Method> it = fields.iterator();
		while (it.hasNext()) {
			Method field = it.next();
			String fieldName = VO_METHOD_TRANSFILTER.transform(field.getName());
			if (recursive) {
				voNode.add(fieldName, createVOReturnTypeNode(field.getReturnType(), field.getGenericReturnType()));
			} else {
				voNode.addProperty(fieldName, ClassUtils.getSimpleName(field.getReturnType()));
			}
		}
	}
	return voNode;
}
 
开发者ID:phoenixctms,项目名称:ctsms,代码行数:17,代码来源:IndexResource.java

示例14: toStringWithRootCause

import org.apache.commons.lang3.ClassUtils; //导入依赖的package包/类
/**
 * 拼装 短异常类名: 异常信息 <-- RootCause的短异常类名: 异常信息
 */
public static String toStringWithRootCause(@Nullable Throwable t) {
	if (t == null) {
		return StringUtils.EMPTY;
	}

	final String clsName = ClassUtils.getShortClassName(t, null);
	final String message = StringUtils.defaultString(t.getMessage());
	Throwable cause = getRootCause(t);

	StringBuilder sb = new StringBuilder(128).append(clsName).append(": ").append(message);
	if (cause != t) {
		sb.append("; <---").append(toStringWithShortName(cause));
	}

	return sb.toString();
}
 
开发者ID:zhangjunfang,项目名称:util,代码行数:20,代码来源:ExceptionUtil.java

示例15: getAnnotatedPublicMethods

import org.apache.commons.lang3.ClassUtils; //导入依赖的package包/类
/**
 * 找出所有标注了该annotation的公共方法(含父类的公共函数),循环其接口.
 * 
 * 暂未支持Spring风格Annotation继承Annotation
 * 
 * 另,如果子类重载父类的公共函数,父类函数上的annotation不会继承,只有接口上的annotation会被继承.
 */
public static <T extends Annotation> Set<Method> getAnnotatedPublicMethods(Class<?> clazz, Class<T> annotation) {
	// 已递归到Objebt.class, 停止递归
	if (Object.class.equals(clazz)) {
		return Collections.emptySet();
	}

	List<Class<?>> ifcs = ClassUtils.getAllInterfaces(clazz);
	Set<Method> annotatedMethods = new HashSet<Method>();

	// 遍历当前类的所有公共方法
	Method[] methods = clazz.getMethods();

	for (Method method : methods) {
		// 如果当前方法有标注,或定义了该方法的所有接口有标注
		if (method.getAnnotation(annotation) != null || searchOnInterfaces(method, annotation, ifcs)) {
			annotatedMethods.add(method);
		}
	}

	return annotatedMethods;
}
 
开发者ID:zhangjunfang,项目名称:util,代码行数:29,代码来源:ClassUtil.java


注:本文中的org.apache.commons.lang3.ClassUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。