本文整理匯總了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());
}
}
示例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!!");
}
示例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);
}
}
示例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();
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
}
示例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);
}
}
示例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);
}
}
}
示例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;
}
示例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();
}
示例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;
}