From 589c7368cf3348194555044779eaad7826b410d9 Mon Sep 17 00:00:00 2001 From: kamhung <22250530@qq.com> Date: Wed, 11 Nov 2015 17:46:51 +0800 Subject: [PATCH] --- .../wentch/redkale/source/EntityCache.java | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/com/wentch/redkale/source/EntityCache.java b/src/com/wentch/redkale/source/EntityCache.java index b9c322d27..70b136221 100644 --- a/src/com/wentch/redkale/source/EntityCache.java +++ b/src/com/wentch/redkale/source/EntityCache.java @@ -220,19 +220,29 @@ public final class EntityCache { if (filter != null) stream = stream.filter(filter); if (sort != null) stream = stream.sorted(sort); if (selects == null) { - stream.forEach(x -> rs.add(needcopy ? reproduce.copy(creator.create(), x) : x)); + Consumer action = x -> rs.add(needcopy ? reproduce.copy(creator.create(), x) : x); + if (parallel && sort != null) { + stream.forEachOrdered(action); + } else { + stream.forEach(action); + } } else { final List> attrs = new ArrayList<>(); for (Map.Entry> en : this.attributes.entrySet()) { if (selects.validate(en.getKey())) attrs.add(en.getValue()); } - stream.forEach(x -> { + Consumer action = x -> { final T item = creator.create(); for (Attribute attr : attrs) { attr.set(item, attr.get(x)); } rs.add(item); - }); + }; + if (parallel && sort != null) { + stream.forEachOrdered(action); + } else { + stream.forEach(action); + } } return parallel ? (set ? new LinkedHashSet<>(rs) : new ArrayList<>(rs)) : rs; } @@ -259,19 +269,29 @@ public final class EntityCache { boolean parallel = isParallel(); final List rs = parallel ? new CopyOnWriteArrayList<>() : new ArrayList<>(); if (selects == null) { - stream.forEach(x -> rs.add(needcopy ? reproduce.copy(creator.create(), x) : x)); + Consumer action = x -> rs.add(needcopy ? reproduce.copy(creator.create(), x) : x); + if (parallel && sort != null) { + stream.forEachOrdered(action); + } else { + stream.forEach(action); + } } else { final List> attrs = new ArrayList<>(); for (Map.Entry> en : this.attributes.entrySet()) { if (selects.validate(en.getKey())) attrs.add(en.getValue()); } - stream.forEach(x -> { + Consumer action = x -> { final T item = creator.create(); for (Attribute attr : attrs) { attr.set(item, attr.get(x)); } rs.add(item); - }); + }; + if (parallel && sort != null) { + stream.forEachOrdered(action); + } else { + stream.forEach(action); + } } return new Sheet<>(total, parallel ? new ArrayList<>(rs) : rs); }