Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
youfanx committed Apr 26, 2024
1 parent 2050778 commit 16a18a7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions rxlib/src/main/java/org/rx/bean/NEnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,26 @@
import lombok.NonNull;
import lombok.SneakyThrows;
import org.rx.core.Extends;
import org.rx.exception.InvalidException;

import java.io.Serializable;

import static org.rx.core.Constants.NON_UNCHECKED;

public interface NEnum<T extends Enum<T> & NEnum<T>> extends Serializable {
static <T extends Enum<T> & NEnum<T>> T valueOf(@NonNull Class<T> type, int value) {
return valueOf(type, value, true);
}

static <T extends Enum<T> & NEnum<T>> T valueOf(@NonNull Class<T> 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;
}

Expand Down
16 changes: 16 additions & 0 deletions rxlib/src/main/java/org/rx/core/Linq.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

Expand Down Expand Up @@ -299,6 +302,19 @@ public Linq<T> union(Iterable<T> set) {
return Linq.from(CollectionUtils.union(this, set));
}

//ListUtils.partition()
public Linq<List<T>> partition(int size) {
List<List<T>> n = newList();
List<T> 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<T> orderByRand() {
return me(stream().sorted(getComparator(p -> ThreadLocalRandom.current().nextInt(0, 100), false)));
}
Expand Down

0 comments on commit 16a18a7

Please sign in to comment.