diff --git a/rxlib/src/main/java/org/rx/bean/NEnum.java b/rxlib/src/main/java/org/rx/bean/NEnum.java index b3db6e0c..a202a102 100644 --- a/rxlib/src/main/java/org/rx/bean/NEnum.java +++ b/rxlib/src/main/java/org/rx/bean/NEnum.java @@ -3,6 +3,7 @@ import lombok.NonNull; import lombok.SneakyThrows; import org.rx.core.Extends; +import org.rx.exception.InvalidException; import java.io.Serializable; @@ -10,11 +11,18 @@ public interface NEnum & NEnum> extends Serializable { static & NEnum> T valueOf(@NonNull Class type, int value) { + return valueOf(type, value, true); + } + + static & NEnum> T valueOf(@NonNull Class type, int value, boolean throwOnEmpty) { for (T nEnum : type.getEnumConstants()) { if (nEnum.getValue() == value) { return nEnum; } } + if (throwOnEmpty) { + throw new InvalidException("Enum {} not contains {}", type, value); + } return null; } diff --git a/rxlib/src/main/java/org/rx/core/Linq.java b/rxlib/src/main/java/org/rx/core/Linq.java index 73bf9201..c02d49d1 100644 --- a/rxlib/src/main/java/org/rx/core/Linq.java +++ b/rxlib/src/main/java/org/rx/core/Linq.java @@ -8,9 +8,12 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.IteratorUtils; +import org.apache.commons.collections4.ListUtils; +import org.apache.commons.lang3.ArrayUtils; import org.rx.annotation.ErrorCode; import org.rx.bean.$; import org.rx.bean.Decimal; +import org.rx.bean.Tuple; import org.rx.exception.ApplicationException; import org.rx.util.function.*; @@ -299,6 +302,19 @@ public Linq union(Iterable set) { return Linq.from(CollectionUtils.union(this, set)); } + //ListUtils.partition() + public Linq> partition(int size) { + List> n = newList(); + List a = toList(); + int f = 0, t = 0; + while (f < a.size()) { + t = Math.min(t + size, a.size()); + n.add(a.subList(f, t)); + f = t; + } + return me(n); + } + public Linq orderByRand() { return me(stream().sorted(getComparator(p -> ThreadLocalRandom.current().nextInt(0, 100), false))); } diff --git a/rxlib/src/main/java/org/rx/net/support/IPSearcher.java b/rxlib/src/main/java/org/rx/net/support/IPSearcher.java index 27f18eba..2e9a5688 100644 --- a/rxlib/src/main/java/org/rx/net/support/IPSearcher.java +++ b/rxlib/src/main/java/org/rx/net/support/IPSearcher.java @@ -13,6 +13,7 @@ static String godaddyDns(String ssoKey, String domain, String name) { static String godaddyDns(String ssoKey, String domain, String name, String ip, AuthenticProxy proxy) { String u = String.format("https://api.godaddy.com/v1/domains/%s/records/A/%s", domain, name); HttpClient c = new HttpClient(); + c.setEnableLog(true); c.setProxy(proxy); c.requestHeaders().add("Authorization", "sso-key " + ssoKey); return c.putJson(u, String.format("[\n" +