org.apache.commons.lang3.ClassUtils Java Examples

The following examples show how to use org.apache.commons.lang3.ClassUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EntityUUID.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
public EntityUUID(final URI entitySetURI, final Class<?> type, final Object key) {
  this.entitySetURI = entitySetURI;
  this.key = key;
  this.tempKey = (int) (Math.random() * 1000000);

  if (type == null || !Serializable.class.isAssignableFrom(type)) {
    throw new IllegalArgumentException("Invalid Entity type class: " + type);
  }
  if (this.type == null) {
    for (Class<?> clazz : ClassUtils.hierarchy(type, ClassUtils.Interfaces.INCLUDE)) {
      if (ArrayUtils.contains(clazz.getInterfaces(), EntityType.class)) {
        this.type = clazz;
      }
    }
  }
}
 
Example #2
Source File: ResponseRootDeserializer.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
public static boolean needConvert(Object obj, JavaType invocationTimeType) {
  if (obj == null || ClassUtils.isPrimitiveOrWrapper(obj.getClass()) || invocationTimeType.isPrimitive()
      || ProtoConst.OBJECT_TYPE.equals(invocationTimeType)) {
    return false;
  }

  if (obj.getClass() == invocationTimeType.getRawClass()) {
    return false;
  }

  if (invocationTimeType.getRawClass().isAssignableFrom(obj.getClass())) {
    if (invocationTimeType.getContentType() == null) {
      return false;
    }
  }

  return true;
}
 
Example #3
Source File: MemberUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #4
Source File: AnnotationUtil.java    From vjtools with Apache License 2.0 6 votes vote down vote up
/**
 * 找出所有标注了该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;
}
 
Example #5
Source File: Script2Class.java    From fastquery with Apache License 2.0 6 votes vote down vote up
/**
 * 处理脚本中的冒号表达式
 * @param script 脚本
 * @param method 脚本的所属方法
 * @return 被处理后的脚本
 */
private static String processParam(String script, Method method) {
	List<String> names = TypeUtil.matches(script, Placeholder.COLON_REG);
	for (String paramName : names) {
		String name = paramName.replace(":", "");
		Class<?> oldC = Judge.getParamType(name, method);
		Class<?> newC = ClassUtils.primitiveToWrapper(oldC);
		if(oldC == newC) {
			// 包装类型 如果后面跟着
			script = script.replaceAll(paramName, "(("+newC.getName()+")this.getParameter(\""+name+"\"))");
			
		} else { // 基本类型 -> 包装类型 那么就要解包
			// 加上解包方法
			script = script.replaceAll(paramName, "(("+newC.getName()+")this.getParameter(\""+name+"\"))." + oldC.getName() + "Value()");
		}
	}
	return script;
}
 
Example #6
Source File: ExternalSearchProviderRegistryImpl.java    From inception with Apache License 2.0 6 votes vote down vote up
void init()
{
    List<ExternalSearchProviderFactory> exts = new ArrayList<>();

    if (providersProxy != null) {
        exts.addAll(providersProxy);
        AnnotationAwareOrderComparator.sort(exts);

        for (ExternalSearchProviderFactory fs : exts) {
            log.info("Found external search provider: {}",
                    ClassUtils.getAbbreviatedName(fs.getClass(), 20));
        }
    }

    providers = Collections.unmodifiableList(exts);
}
 
Example #7
Source File: DynaBeanBuilderSupport.java    From amazon-kinesis-client with Apache License 2.0 6 votes vote down vote up
private void buildProperties() {
    if (builderClass == null) {
        return;
    }
    try {
        builderClass.getMethod(BUILD_METHOD_NAME);
    } catch (NoSuchMethodException e) {
        throw new RuntimeException(e);
    }

    for (Method method : builderClass.getMethods()) {
        if (method.getParameterCount() == 1 && ClassUtils.isAssignable(builderClass, method.getReturnType())) {
            Class<?> paramType = method.getParameterTypes()[0];
            if (Supplier.class.isAssignableFrom(paramType) || Consumer.class.isAssignableFrom(paramType)) {
                continue;
            }
            if (paramType.isEnum()) {
                properties.put(method.getName(), new TypeTag(paramType, true, method));
            } else if (convertUtilsBean.lookup(paramType) == null) {
                properties.put(method.getName(), new TypeTag(paramType, false, method));
            } else {
                properties.put(method.getName(), new TypeTag(paramType, true, method));
            }
        }
    }
}
 
Example #8
Source File: GsonInterfaceAdapter.java    From incubator-gobblin with Apache License 2.0 6 votes vote down vote up
@Override
public <R> TypeAdapter<R> create(Gson gson, TypeToken<R> type) {
  if (ClassUtils.isPrimitiveOrWrapper(type.getRawType()) || type.getType() instanceof GenericArrayType
      || CharSequence.class.isAssignableFrom(type.getRawType())
      || (type.getType() instanceof ParameterizedType && (Collection.class.isAssignableFrom(type.getRawType())
          || Map.class.isAssignableFrom(type.getRawType())))) {
    // delegate primitives, arrays, collections, and maps
    return null;
  }
  if (!this.baseClass.isAssignableFrom(type.getRawType())) {
    // delegate anything not assignable from base class
    return null;
  }
  TypeAdapter<R> adapter = new InterfaceAdapter<>(gson, this, type);
  return adapter;
}
 
Example #9
Source File: MemberUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #10
Source File: AnnotationSidebarRegistryImpl.java    From webanno with Apache License 2.0 6 votes vote down vote up
void init()
{
    List<AnnotationSidebarFactory> exts = new ArrayList<>();

    if (extensionsProxy != null) {
        exts.addAll(extensionsProxy);
        exts.sort(buildComparator());

        for (AnnotationSidebarFactory fs : exts) {
            log.info("Found annotation sidebar extension: {}",
                    ClassUtils.getAbbreviatedName(fs.getClass(), 20));
        }
    }
    
    extensions = Collections.unmodifiableList(exts);
}
 
Example #11
Source File: IndexResource.java    From ctsms with GNU Lesser General Public License v2.1 6 votes vote down vote up
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);
		}
	}
}
 
Example #12
Source File: SystemInputResources.java    From tcases with MIT License 6 votes vote down vote up
/**
 * Returns the {@link SystemInputDef} defined by the given JSON resource.
 */
public SystemInputDef readJson( String resource)
  {
  SystemInputDef  systemInputDef  = null;
  InputStream     stream          = null;
  
  stream = class_.getResourceAsStream( resource);
  if( stream == null)
    {
    throw
      new RuntimeException
      ( "Can't find resource=" + ClassUtils.getPackageName( class_) + "." + resource);
    }

  try( SystemInputJsonReader reader = new SystemInputJsonReader( stream))
    {
    systemInputDef = reader.getSystemInputDef();
    }

  return systemInputDef;
  }
 
Example #13
Source File: KryoSerialization.java    From cuba with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@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 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);
    }
}
 
Example #14
Source File: ConceptLinkingServiceImpl.java    From inception with Apache License 2.0 6 votes vote down vote up
void init()
{
    List<EntityRankingFeatureGenerator> generators = new ArrayList<>();

    if (featureGeneratorsProxy != null) {
        generators.addAll(featureGeneratorsProxy);
        AnnotationAwareOrderComparator.sort(generators);
    
        for (EntityRankingFeatureGenerator generator : generators) {
            log.info("Found entity ranking feature generator: {}",
                    ClassUtils.getAbbreviatedName(generator.getClass(), 20));
        }
    }

    featureGenerators = unmodifiableList(generators);
}
 
Example #15
Source File: ExceptionUtil.java    From vjtools with Apache License 2.0 6 votes vote down vote up
/**
 * 拼装 短异常类名: 异常信息 <-- 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();
}
 
Example #16
Source File: MemberUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Gets 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;
}
 
Example #17
Source File: ExceptionUtil.java    From vjtools with Apache License 2.0 6 votes vote down vote up
/**
 * 拼装 短异常类名: 异常信息 <-- 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();
}
 
Example #18
Source File: Describe.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private List<Class<?>> scanJaxrsClass(String name) throws Exception {
	// String pack = "com." + name.replaceAll("_", ".");
	String pack = "";
	if (StringUtils.startsWith(name, "o2_")) {
		pack = name.replaceAll("_", ".");
	} else {
		pack = "com." + name.replaceAll("_", ".");
	}
	try (ScanResult scanResult = new ClassGraph().whitelistPackages(pack).enableAllInfo().scan()) {
		SetUniqueList<Class<?>> classes = SetUniqueList.setUniqueList(new ArrayList<Class<?>>());
		for (ClassInfo info : scanResult.getClassesWithAnnotation(ApplicationPath.class.getName())) {
			Class<?> applicationPathClass = ClassUtils.getClass(info.getName());
			for (Class<?> o : (Set<Class<?>>) MethodUtils.invokeMethod(applicationPathClass.newInstance(),
					"getClasses")) {
				Path path = o.getAnnotation(Path.class);
				JaxrsDescribe jaxrsDescribe = o.getAnnotation(JaxrsDescribe.class);
				if (null != path && null != jaxrsDescribe) {
					classes.add(o);
				}
			}
		}
		return classes;
	}
}
 
Example #19
Source File: ApiBuilder.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
private List<Class<?>> scanJaxrsClass() throws Exception {
	try (ScanResult scanResult = new ClassGraph().disableJarScanning().enableAnnotationInfo().scan()) {
		SetUniqueList<Class<?>> classes = SetUniqueList.setUniqueList(new ArrayList<Class<?>>());
		for (ClassInfo info : scanResult.getClassesWithAnnotation(ApplicationPath.class.getName())) {
			Class<?> applicationPathClass = ClassUtils.getClass(info.getName());
			for (Class<?> o : (Set<Class<?>>) MethodUtils.invokeMethod(applicationPathClass.newInstance(),
					"getClasses")) {
				Path path = o.getAnnotation(Path.class);
				JaxrsDescribe jaxrsDescribe = o.getAnnotation(JaxrsDescribe.class);
				if (null != path && null != jaxrsDescribe) {
					classes.add(o);
				}
			}
		}
		return classes;
	}
}
 
Example #20
Source File: ReflectionToStringBuilder.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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.excludeFieldNames != null
        && Arrays.binarySearch(this.excludeFieldNames, field.getName()) >= 0) {
        // Reject fields from the getExcludeFieldNames list.
        return false;
    }
    return true;
}
 
Example #21
Source File: ClassUtil.java    From j360-dubbo-app-all with Apache License 2.0 6 votes vote down vote up
/**
 * 找出所有标注了该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;
}
 
Example #22
Source File: IndexResource.java    From ctsms with GNU Lesser General Public License v2.1 6 votes vote down vote up
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;
}
 
Example #23
Source File: ElementProcessor.java    From poi-tl with Apache License 2.0 6 votes vote down vote up
@Override
public void visit(RunTemplate runTemplate) {
    RenderPolicy policy = runTemplate.findPolicy(template.getConfig());
    if (null == policy) {
        throw new RenderException(
                "Cannot find render policy: [" + ((ElementTemplate) runTemplate).getTagName() + "]");
    }
    if (policy instanceof DocxRenderPolicy) {
        return;
    } else {
        LOGGER.info("Start render TemplateName:{}, Sign:{}, policy:{}", runTemplate.getTagName(),
                runTemplate.getSign(), ClassUtils.getShortClassName(policy.getClass()));
        policy.render(((ElementTemplate) runTemplate), renderDataCompute.compute(runTemplate.getTagName()),
                template);
    }

}
 
Example #24
Source File: BusinessObjectBase.java    From rice with Educational Community License v2.0 6 votes vote down vote up
@Override
public String toString() {
       class BusinessObjectToStringBuilder extends ReflectionToStringBuilder {

           private BusinessObjectToStringBuilder(Object object) {
               super(object);
           }

           @Override
           public boolean accept(Field field) {
               return String.class.isAssignableFrom(field.getType())
                       || ClassUtils.isPrimitiveOrWrapper(field.getType());
           }

       }

       return new BusinessObjectToStringBuilder(this).toString();
   }
 
Example #25
Source File: ProjectSettingsPanelRegistryImpl.java    From webanno with Apache License 2.0 6 votes vote down vote up
void init()
{
    List<ProjectSettingsPanelFactory> exts = new ArrayList<>();

    if (extensionsProxy != null) {
        exts.addAll(extensionsProxy);
        AnnotationAwareOrderComparator.sort(exts);
    
        for (ProjectSettingsPanelFactory fs : exts) {
            log.info("Found project setting panel: {}",
                    ClassUtils.getAbbreviatedName(fs.getClass(), 20));
        }
    }
    
    extensions = Collections.unmodifiableList(exts);
}
 
Example #26
Source File: ComparisonUtil.java    From sailfish-core with Apache License 2.0 6 votes vote down vote up
private static void setTypeAndValue(Map<String, Object> map, Object value) {
    map.put("type", ClassUtils.getSimpleName(value, null));

    if(value instanceof IFilter) {
        IFilter filter = (IFilter)value;

        if(filter.hasValue()) {
            map.put("type", ClassUtils.getSimpleName(value = filter.getValue(), null));
        } else {
            value = filter.getCondition();
        }
    } else if(value instanceof LocalDate || value instanceof LocalTime || value instanceof LocalDateTime) {
        value = JsonMessageConverter.formatTemporal((TemporalAccessor)value);
    }

    map.put("value", value);
}
 
Example #27
Source File: EventLoggingListener.java    From inception with Apache License 2.0 6 votes vote down vote up
void init()
{
    List<EventLoggingAdapter<?>> exts = new ArrayList<>();

    if (adapterProxy != null) {
        exts.addAll(adapterProxy);
        AnnotationAwareOrderComparator.sort(exts);

        for (EventLoggingAdapter<?> fs : exts) {
            log.info("Found event logging adapter: {}",
                    ClassUtils.getAbbreviatedName(fs.getClass(), 20));
        }
    }

    adapters = Collections.unmodifiableList(exts);
}
 
Example #28
Source File: ReflectionUtils.java    From poi-tl with Apache License 2.0 5 votes vote down vote up
public static Object getValue(String fieldName, Object obj) {
    Objects.requireNonNull(obj, "Class must not be null");
    Objects.requireNonNull(fieldName, "Name must not be null");
    Field field = findField(obj.getClass(), fieldName);
    if (null == field) {
        throw new ReflectionException(
                "No Such field " + fieldName + " from class" + ClassUtils.getShortClassName(obj.getClass()));
    }
    try {
        field.setAccessible(true);
        return field.get(obj);
    } catch (Exception e) {
        throw new ReflectionException(fieldName, obj.getClass(), e);
    }
}
 
Example #29
Source File: LangTest.java    From java-study with Apache License 2.0 5 votes vote down vote up
public static void test() {
	// 1 合并两个数组: org.apache.commons.lang. ArrayUtils
	String[] s1 = new String[] { "1", "2", "3" };
	String[] s2 = new String[] { "a", "b", "c" };
	String[] s = (String[]) ArrayUtils.addAll(s1, s2);
	for (int i = 0; i < s.length; i++) {
		System.out.println(s[i]);
	}
	String str = ArrayUtils.toString(s);
	str = str.substring(1, str.length() - 1);
	System.out.println(str + ">>" + str.length());

	System.out.println("测试截取:" + StringUtils.substringAfter("SELECT * FROM PERSON ", "FROM"));
	// 3 判断该字符串是不是为数字(0~9)组成,如果是,返回true 但该方法不识别有小数点和 请注意。
	System.out.println("数字判断:" + StringUtils.isNumeric("454534"));
	System.out.println("取得类名:" + ClassUtils.getShortClassName(LangTest.class));
	System.out.println("获取包名:" + ClassUtils.getPackageName(LangTest.class));

	System.out.println("是否是数字:" + NumberUtils.isCreatable("123"));
	System.out.println("随机数字和字母:" + RandomStringUtils.randomAlphanumeric(5));
	System.out.println("<>进行转义" + StringEscapeUtils.escapeHtml("<html>"));

	System.out.println("是否是null字符 :" + StringUtils.isBlank(null));
	System.out.println("是否是空字符 :" + StringUtils.isBlank(""));
	System.out.println("是否是空格字符 :" + StringUtils.isBlank("   "));
	System.out.println("分割数组:" + StringUtils.join(s1, ","));
	System.out.println("添加某个字符,使其长度等于所设置的:" + StringUtils.rightPad("abc", 6, 'T'));
	System.out.println("首字母大写:" + StringUtils.capitalize("abc"));
	System.out.println("去掉空格:" + StringUtils.deleteWhitespace("   ab  c  "));
	System.out.println("是否包含该字符:" + StringUtils.contains("abc", "ba"));
	System.out.println("表示左边的字符:" + StringUtils.left("abc", 2));
}
 
Example #30
Source File: POJOEnricher.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
private PojoUtils.Setter generateSettersForField(Class<?> klass, String outputFieldName)
  throws NoSuchFieldException, SecurityException
{
  Field f = klass.getDeclaredField(outputFieldName);
  Class c = ClassUtils.primitiveToWrapper(f.getType());
  return PojoUtils.createSetter(klass, outputFieldName, c);
}