/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitee.dorive.proxy;
import org.apache.commons.lang3.StringUtils;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.*;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
/**
* ClassUtils. (Tool, Static, ThreadSafe)
*/
public class ClassUtils {
public static final String CLASS_EXTENSION = ".class";
public static final String JAVA_EXTENSION = ".java";
private static final int JIT_LIMIT = 5 * 1024;
private ClassUtils() {
}
public static Object newInstance(String name) {
try {
return forName(name).newInstance();
} catch (InstantiationException e) {
throw new IllegalStateException(e.getMessage(), e);
} catch (IllegalAccessException e) {
throw new IllegalStateException(e.getMessage(), e);
}
}
public static Class<?> forName(String[] packages, String className) {
try {
return classForName(className);
} catch (ClassNotFoundException e) {
if (packages != null && packages.length > 0) {
for (String pkg : packages) {
try {
return classForName(pkg + "." + className);
} catch (ClassNotFoundException e2) {
}
}
}
throw new IllegalStateException(e.getMessage(), e);
}
}
public static Class<?> forName(String className) {
try {
return classForName(className);
} catch (ClassNotFoundException e) {
throw new IllegalStateException(e.getMessage(), e);
}
}
public static Class<?> classForName(String className) throws ClassNotFoundException {
switch (className) {
case "boolean":
return boolean.class;
case "byte":
return byte.class;
case "char":
return char.class;
case "short":
return short.class;
case "int":
return int.class;
case "long":
return long.class;
case "float":
return float.class;
case "double":
return double.class;
case "boolean[]":
return boolean[].class;
case "byte[]":
return byte[].class;
case "char[]":
return char[].class;
case "short[]":
return short[].class;
case "int[]":
return int[].class;
case "long[]":
return long[].class;
case "float[]":
return float[].class;
case "double[]":
return double[].class;
default:
}
try {
return arrayForName(className);
} catch (ClassNotFoundException e) {
// try to load from java.lang package
if (className.indexOf('.') == -1) {
try {
return arrayForName("java.lang." + className);
} catch (ClassNotFoundException e2) {
// ignore, let the original exception be thrown
}
}
throw e;
}
}
private static Class<?> arrayForName(String className) throws ClassNotFoundException {
return Class.forName(
className.endsWith("[]") ? "[L" + className.substring(0, className.length() - 2) + ";" : className,
true, Thread.currentThread().getContextClassLoader());
}
public static Class<?> getBoxedClass(Class<?> type) {
if (type == boolean.class) {
return Boolean.class;
} else if (type == char.class) {
return Character.class;
} else if (type == byte.class) {
return Byte.class;
} else if (type == short.class) {
return Short.class;
} else if (type == int.class) {
return Integer.class;
} else if (type == long.class) {
return Long.class;
} else if (type == float.class) {
return Float.class;
} else if (type == double.class) {
return Double.class;
} else {
return type;
}
}
public static Boolean boxed(boolean v) {
return Boolean.valueOf(v);
}
public static Character boxed(char v) {
return Character.valueOf(v);
}
public static Byte boxed(byte v) {
return Byte.valueOf(v);
}
public static Short boxed(short v) {
return Short.valueOf(v);
}
public static Integer boxed(int v) {
return Integer.valueOf(v);
}
public static Long boxed(long v) {
return Long.valueOf(v);
}
public static Float boxed(float v) {
return Float.valueOf(v);
}
public static Double boxed(double v) {
return Double.valueOf(v);
}
public static Object boxed(Object v) {
return v;
}
public static boolean unboxed(Boolean v) {
return v == null ? false : v.booleanValue();
}
public static char unboxed(Character v) {
return v == null ? '\0' : v.charValue();
}
public static byte unboxed(Byte v) {
return v == null ? 0 : v.byteValue();
}
public static short unboxed(Short v) {
return v == null ? 0 : v.shortValue();
}
public static int unboxed(Integer v) {
return v == null ? 0 : v.intValue();
}
public static long unboxed(Long v) {
return v == null ? 0 : v.longValue();
}
public static float unboxed(Float v) {
return v == null ? 0 : v.floatValue();
}
public static double unboxed(Double v) {
return v == null ? 0 : v.doubleValue();
}
public static Object unboxed(Object v) {
return v;
}
public static boolean isNotEmpty(Object object) {
return getSize(object) > 0;
}
public static int getSize(Object object) {
if (object == null) {
return 0;
}
if (object instanceof Collection<?>) {
return ((Collection<?>) object).size();
} else if (object instanceof Map<?, ?>) {
return ((Map<?, ?>) object).size();
} else if (object.getClass().isArray()) {
return Array.getLength(object);
} else {
return -1;
}
}
public static URI toURI(String name) {
try {
return new URI(name);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
public static Class<?> getGenericClass(Class<?> cls) {
return getGenericClass(cls, 0);
}
public static Class<?> getGenericClass(Class<?> cls, int i) {
try {
ParameterizedType parameterizedType = ((ParameterizedType) cls.getGenericInterfaces()[0]);
Object genericClass = parameterizedType.getActualTypeArguments()[i];
if (genericClass instanceof ParameterizedType) {
return (Class<?
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
dorive轻量级领域驱动框架,帮助开发者通过建模,快速构建具有可维护性、可拓展性的应用程序 (171个子文件)
spring.factories 259B
spring.factories 129B
spring.factories 121B
spring.factories 119B
.gitignore 281B
org.springframework.boot.autoconfigure.AutoConfiguration.imports 68B
org.springframework.boot.autoconfigure.AutoConfiguration.imports 62B
org.springframework.boot.autoconfigure.AutoConfiguration.imports 54B
org.springframework.boot.autoconfigure.AutoConfiguration.imports 52B
ClassUtils.java 14KB
ClassLoaderUtils.java 12KB
MybatisPlusExecutor.java 12KB
JdkCompiler.java 10KB
MultiEntityHandler.java 10KB
ChainExecutor.java 10KB
AbstractContextRepository.java 9KB
SegmentBuilder.java 9KB
BinderResolver.java 9KB
DefaultExampleBuilder.java 8KB
MybatisPlusRepository.java 7KB
CoatingTypeResolver.java 7KB
UnionEntityHandler.java 6KB
AbstractRepository.java 6KB
MergedRepositoryResolver.java 5KB
FactoryExecutor.java 5KB
AppenderContext.java 5KB
PropProxyFactory.java 5KB
CtClassBuilder.java 5KB
Example.java 4KB
AbstractCoatingRepository.java 4KB
LimitedAutowiredBeanPostProcessor.java 4KB
SQLExampleBuilder.java 4KB
DefaultTypeDomainResolver.java 4KB
EntityType.java 4KB
ProxyRepository.java 4KB
DoriveInjectionConfiguration.java 4KB
AbstractGenericRepository.java 4KB
AliasExecutor.java 4KB
SimpleRepository.java 4KB
RepositoryListener.java 4KB
Repository.java 3KB
AdaptiveEntityHandler.java 3KB
JavassistCompiler.java 3KB
EntityField.java 3KB
CountQuerier.java 3KB
SpecificFields.java 3KB
CommonRepository.java 3KB
NameSelector.java 3KB
CriterionUtils.java 3KB
SelectSegment.java 3KB
RefImpl.java 3KB
OperationFactory.java 3KB
EntityEle.java 3KB
CoatingType.java 3KB
AbstractCompiler.java 3KB
PropChain.java 3KB
RefInjector.java 3KB
AbstractEventRepository.java 3KB
PropertyBinder.java 3KB
LimitedCglibSubclassingInstantiationStrategy.java 3KB
DerivedResolver.java 3KB
AbstractBinder.java 2KB
RepositoryContext.java 2KB
ResourceUtils.java 2KB
DefaultEntityFactory.java 2KB
EventExecutor.java 2KB
RefObjImpl.java 2KB
ReflectUtils.java 2KB
MultiInBuilder.java 2KB
EntityDef.java 2KB
CoatingField.java 2KB
LimitedRootInitializingBean.java 2KB
BatchEntityHandler.java 2KB
BindingDef.java 2KB
CriterionDef.java 2KB
PropChainResolver.java 2KB
AbstractContext.java 2KB
EnvironmentProcessor.java 2KB
Aggregate.java 2KB
PathUtils.java 2KB
EntityResolver.java 2KB
AopUtils.java 2KB
Result.java 2KB
ContextBinder.java 2KB
StringUtils.java 2KB
AliasDef.java 2KB
UnionExample.java 2KB
MybatisPlusConfiguration.java 2KB
MergedRepository.java 2KB
PropertyProcessor.java 2KB
Criterion.java 1KB
RootRepository.java 1KB
EmptySelector.java 1KB
Page.java 1KB
AbstractRefRepository.java 1KB
RootSelector.java 1KB
DefaultProcessor.java 1KB
AllSelector.java 1KB
Query.java 1KB
ExampleDef.java 1KB
共 171 条
- 1
- 2
资源评论
Java程序员-张凯
- 粉丝: 1w+
- 资源: 6834
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功