Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
youfanx committed Jul 10, 2024
1 parent ffa7b3c commit 9b22dd1
Show file tree
Hide file tree
Showing 28 changed files with 152 additions and 184 deletions.
1 change: 0 additions & 1 deletion rxlib/src/main/java/org/rx/bean/CircularBlockingQueue.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.rx.bean;

import lombok.Getter;
import lombok.Setter;
import org.rx.core.*;
import org.rx.util.function.TripleFunc;

Expand Down
3 changes: 2 additions & 1 deletion rxlib/src/main/java/org/rx/bean/DataTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
import java.util.Iterator;
import java.util.List;

import static org.rx.core.Extends.*;
import static org.rx.core.Extends.as;
import static org.rx.core.Extends.tryAs;
import static org.rx.core.Sys.fromJson;

@Slf4j
Expand Down
3 changes: 0 additions & 3 deletions rxlib/src/main/java/org/rx/bean/DateTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@

import java.text.ParseException;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;
import java.time.temporal.TemporalAdjusters;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

import static org.rx.core.Constants.NON_UNCHECKED;
import static org.rx.core.Extends.ifNull;
import static org.rx.core.Extends.values;

Expand Down
1 change: 0 additions & 1 deletion rxlib/src/main/java/org/rx/codec/CodecUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.rx.third.open.CrcModel;

import java.io.File;
import java.io.Serializable;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
Expand Down
1 change: 0 additions & 1 deletion rxlib/src/main/java/org/rx/core/Cache.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import lombok.NonNull;
import lombok.SneakyThrows;
import org.rx.bean.AbstractMap;
import org.rx.core.cache.DiskCache;
import org.rx.core.cache.MemoryCache;
import org.rx.util.function.BiFunc;

Expand Down
4 changes: 3 additions & 1 deletion rxlib/src/main/java/org/rx/core/ForkJoinPoolWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import org.rx.exception.InvalidException;

import java.util.Properties;
import java.util.concurrent.*;
import java.util.concurrent.Callable;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;
import java.util.function.Function;

@Slf4j
Expand Down
15 changes: 8 additions & 7 deletions rxlib/src/main/java/org/rx/core/IOC.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@

import lombok.NonNull;
import lombok.SneakyThrows;
import org.apache.commons.lang3.ClassUtils;
import org.rx.bean.WeakIdentityMap;
import org.rx.exception.InvalidException;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

import static org.rx.core.Constants.NON_UNCHECKED;
Expand Down Expand Up @@ -52,8 +48,13 @@ static synchronized <T> T innerGet(Class<T> type) {
}

public static <T> void register(@NonNull Class<T> type, @NonNull T bean) {
List<Class<?>> types = ClassUtils.getAllSuperclasses(type);
types.remove(Object.class);
// List<Class<?>> types = ClassUtils.getAllSuperclasses(type); ClassUtils.getAllInterfaces(type);
List<Class<?>> types = new ArrayList<>();
types.add(type);
types.add(type.getSuperclass());
for (Class<?> i : type.getInterfaces()) {
types.add(i);
}
for (Class<?> t : types) {
container.putIfAbsent(t, bean);
}
Expand Down
3 changes: 2 additions & 1 deletion rxlib/src/main/java/org/rx/core/Linq.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ private Collection<T> asCollection() {
}

private <TR> Stream<TR> newStream(Iterable<TR> iterable) {
return StreamSupport.stream(iterable.spliterator(), parallel);
// return StreamSupport.stream(iterable.spliterator(), parallel);
return StreamSupport.stream(iterable.spliterator(), false);
}

private <TR> Linq<TR> me(Iterable<TR> set) {
Expand Down
68 changes: 65 additions & 3 deletions rxlib/src/main/java/org/rx/core/Reflects.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,69 @@ static <TP, TR> SerializedLambda getLambda(BiFunc<TP, TR> func) {
return lambda;
}

static final int APPEND_TO_COLLECTION = 1;

/**
* @param instance
* @param fieldPath
* @param value
* @param flags 1 append to Collection
*/
public static void writeFieldByPath(Object instance, String fieldPath, Object value, int flags) {
final String c = ".";
int wPathOffset = 0, i;
String fieldName;
Object cur = instance;
while ((i = fieldPath.indexOf(c, wPathOffset)) != -1) {
fieldName = fieldPath.substring(wPathOffset, i);
try {
cur = readField(cur, fieldName);
} catch (Throwable e) {
throw new InvalidException("Read field {} fail", fieldPath.substring(0, wPathOffset), e);
}
wPathOffset = i + c.length();
}
if (cur == null) {
throw new InvalidException("Read field {} empty", fieldPath.substring(0, wPathOffset));
}
fieldName = fieldPath.substring(wPathOffset);
try {
Field field = getFieldMap(cur.getClass()).get(fieldName);
if (field == null) {
throw new NoSuchFieldException(fieldName);
}

if (isTypedJson(value)) {
value = fromTypedJson(value);
}
if (Collection.class.isAssignableFrom(field.getType())) {
Collection<Object> col = (Collection<Object>) field.get(cur);
if ((flags & APPEND_TO_COLLECTION) != APPEND_TO_COLLECTION) {
col.clear();
}
if (value != null) {
col.addAll((Collection<Object>) value);
}
} else if (Map.class.isAssignableFrom(field.getType())) {
Map<Object, Object> col = (Map<Object, Object>) field.get(cur);
if ((flags & APPEND_TO_COLLECTION) != APPEND_TO_COLLECTION) {
col.clear();
}
if (value != null) {
col.putAll((Map<Object, Object>) value);
}
} else {
field.set(cur, changeType(value, field.getType()));
}
} catch (Throwable e) {
throw new InvalidException("Write field {} fail", fieldPath, e);
}
}

public static boolean isTypedJson(Object value) {
if (value instanceof String) {
String str = ((String) value).trim();
return str.startsWith("{") && str.endsWith("}") && str.contains(TYPED_JSON_KEY);
return str.startsWith("{") && str.endsWith("}") && str.indexOf(TYPED_JSON_KEY, 1) != -1;
}
Map<String, Object> json = as(value, Map.class);
if (json != null) {
Expand All @@ -219,7 +278,7 @@ public static <T> T fromTypedJson(@NonNull Map<String, Object> json) {
if (td == null) {
throw new InvalidException("Invalid type descriptor");
}
return fromJson(json, Reflects.fromTypeDescriptor(td));
return fromJson(json, fromTypeDescriptor(td));
}

public static <T> JSONObject toTypedJson(@NonNull T obj) {
Expand All @@ -228,7 +287,7 @@ public static <T> JSONObject toTypedJson(@NonNull T obj) {

public static <T> JSONObject toTypedJson(@NonNull T obj, @NonNull Type type) {
JSONObject r = toJsonObject(obj);
r.put(TYPED_JSON_KEY, Reflects.getTypeDescriptor(type));
r.put(TYPED_JSON_KEY, getTypeDescriptor(type));
return r;
}

Expand Down Expand Up @@ -559,6 +618,7 @@ public static void setAccess(AccessibleObject member) {
FieldUtils.removeFinalModifier(field);
}

// member.setAccessible(true);
if (System.getSecurityManager() == null) {
member.setAccessible(true); // <~ Dragons
} else {
Expand Down Expand Up @@ -656,6 +716,8 @@ public static <T> T changeType(Object value, Class<T> toType) {
} else {
throw new InvalidException("Value should be 0 or 1");
}
} else if (toType == Class.class && value instanceof String) {
value = loadClass(value.toString(), false);
} else {
Linq<Method> methods = getMethodMap(toType).get(CHANGE_TYPE_METHOD);
if (methods == null || fromType.isEnum()) {
Expand Down
Loading

0 comments on commit 9b22dd1

Please sign in to comment.