com.fastchar.object.FastObjectSetHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fastchar Show documentation
Show all versions of fastchar Show documentation
FastChar is Web+ORM Framework in Java.
package com.fastchar.object;
import com.fastchar.core.FastHandler;
import com.fastchar.utils.FastArrayUtils;
import com.fastchar.utils.FastClassUtils;
import com.fastchar.utils.FastNumberUtils;
import com.fastchar.utils.FastStringUtils;
import java.lang.reflect.Array;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.List;
import java.util.regex.Pattern;
/**
* @author 沈建(Janesen)
* @date 2021/8/31 15:09
*/
public class FastObjectSetHandler {
private static final Pattern NUMBER_PATTERN = Pattern.compile("\\d+");
private transient final Object target;
private transient final Object property;
public FastObjectSetHandler(Object target, Object property) {
this.target = target;
this.property = property;
}
public void set(Object value) {
if (target == null) {
return;
}
if (property == null) {
return;
}
//纯数字,认为提前数组的数据
String propertyStr = property.toString();
if (FastStringUtils.isEmpty(propertyStr)) {
return;
}
if (NUMBER_PATTERN.matcher(propertyStr).matches()) {
int index = FastNumberUtils.formatToInt(property);
if (FastArrayUtils.isArray(target)) {
Array.set(target, index, value);
return;
} else if (target instanceof List) {
@SuppressWarnings("unchecked")
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy