This commit is contained in:
@@ -213,6 +213,14 @@ public final class EntityCache<T> {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Set<T> querySet(final SelectColumn selects, final Predicate<T> filter, final Comparator<T> sort) {
|
||||||
|
return (Set<T>) queryCollection(true, selects, filter, sort);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<T> queryList(final SelectColumn selects, final Predicate<T> filter, final Comparator<T> sort) {
|
||||||
|
return (List<T>) queryCollection(false, selects, filter, sort);
|
||||||
|
}
|
||||||
|
|
||||||
public Collection<T> queryCollection(final boolean set, final SelectColumn selects, final Predicate<T> filter, final Comparator<T> sort) {
|
public Collection<T> queryCollection(final boolean set, final SelectColumn selects, final Predicate<T> filter, final Comparator<T> sort) {
|
||||||
final boolean parallel = isParallel();
|
final boolean parallel = isParallel();
|
||||||
final Collection<T> rs = parallel ? (set ? new CopyOnWriteArraySet<>() : new CopyOnWriteArrayList<>()) : (set ? new LinkedHashSet<>() : new ArrayList<>());
|
final Collection<T> rs = parallel ? (set ? new CopyOnWriteArraySet<>() : new CopyOnWriteArrayList<>()) : (set ? new LinkedHashSet<>() : new ArrayList<>());
|
||||||
@@ -221,7 +229,7 @@ public final class EntityCache<T> {
|
|||||||
if (sort != null) stream = stream.sorted(sort);
|
if (sort != null) stream = stream.sorted(sort);
|
||||||
if (selects == null) {
|
if (selects == null) {
|
||||||
Consumer<? super T> action = x -> rs.add(needcopy ? reproduce.copy(creator.create(), x) : x);
|
Consumer<? super T> action = x -> rs.add(needcopy ? reproduce.copy(creator.create(), x) : x);
|
||||||
if (parallel && sort != null) {
|
if (sort != null) {
|
||||||
stream.forEachOrdered(action);
|
stream.forEachOrdered(action);
|
||||||
} else {
|
} else {
|
||||||
stream.forEach(action);
|
stream.forEach(action);
|
||||||
@@ -238,7 +246,7 @@ public final class EntityCache<T> {
|
|||||||
}
|
}
|
||||||
rs.add(item);
|
rs.add(item);
|
||||||
};
|
};
|
||||||
if (parallel && sort != null) {
|
if (sort != null) {
|
||||||
stream.forEachOrdered(action);
|
stream.forEachOrdered(action);
|
||||||
} else {
|
} else {
|
||||||
stream.forEach(action);
|
stream.forEach(action);
|
||||||
@@ -247,14 +255,6 @@ public final class EntityCache<T> {
|
|||||||
return parallel ? (set ? new LinkedHashSet<>(rs) : new ArrayList<>(rs)) : rs;
|
return parallel ? (set ? new LinkedHashSet<>(rs) : new ArrayList<>(rs)) : rs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<T> querySet(final SelectColumn selects, final Predicate<T> filter, final Comparator<T> sort) {
|
|
||||||
return (Set<T>) queryCollection(true, selects, filter, sort);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<T> queryList(final SelectColumn selects, final Predicate<T> filter, final Comparator<T> sort) {
|
|
||||||
return (List<T>) queryCollection(false, selects, filter, sort);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Sheet<T> querySheet(final SelectColumn selects, final Predicate<T> filter, final Flipper flipper, final Comparator<T> sort) {
|
public Sheet<T> querySheet(final SelectColumn selects, final Predicate<T> filter, final Flipper flipper, final Comparator<T> sort) {
|
||||||
Stream<T> stream = listStream();
|
Stream<T> stream = listStream();
|
||||||
if (filter != null) stream = stream.filter(filter);
|
if (filter != null) stream = stream.filter(filter);
|
||||||
@@ -270,7 +270,7 @@ public final class EntityCache<T> {
|
|||||||
final List<T> rs = parallel ? new CopyOnWriteArrayList<>() : new ArrayList<>();
|
final List<T> rs = parallel ? new CopyOnWriteArrayList<>() : new ArrayList<>();
|
||||||
if (selects == null) {
|
if (selects == null) {
|
||||||
Consumer<? super T> action = x -> rs.add(needcopy ? reproduce.copy(creator.create(), x) : x);
|
Consumer<? super T> action = x -> rs.add(needcopy ? reproduce.copy(creator.create(), x) : x);
|
||||||
if (parallel && sort != null) {
|
if (sort != null) {
|
||||||
stream.forEachOrdered(action);
|
stream.forEachOrdered(action);
|
||||||
} else {
|
} else {
|
||||||
stream.forEach(action);
|
stream.forEach(action);
|
||||||
@@ -287,7 +287,7 @@ public final class EntityCache<T> {
|
|||||||
}
|
}
|
||||||
rs.add(item);
|
rs.add(item);
|
||||||
};
|
};
|
||||||
if (parallel && sort != null) {
|
if (sort != null) {
|
||||||
stream.forEachOrdered(action);
|
stream.forEachOrdered(action);
|
||||||
} else {
|
} else {
|
||||||
stream.forEach(action);
|
stream.forEach(action);
|
||||||
@@ -394,7 +394,7 @@ public final class EntityCache<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isParallel() {
|
public boolean isParallel() {
|
||||||
return this.list.size() > 1024 * 1024;
|
return this.list.size() > 1024 * 64;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Stream<T> listStream() {
|
private Stream<T> listStream() {
|
||||||
|
|||||||
Reference in New Issue
Block a user