| 280 | } |
| 281 | |
| 282 | public final void sort(Comparator<Map.Entry<Integer, BItem>> comparison) { |
| 283 | if (null == comparison) |
| 284 | comparison = Comparator.comparingLong(x -> x.getValue().getId()); |
| 285 | |
| 286 | @SuppressWarnings("unchecked") |
| 287 | var sort = (Map.Entry<Integer, BItem>[])bean.getItems().entrySet().toArray(new Map.Entry[bean.getItems().size()]); |
| 288 | Arrays.sort(sort, comparison); |
| 289 | for (int i = 0; i < sort.length; ++i) { |
| 290 | BItem copy = sort[i].getValue().copy(); |
| 291 | sort[i] = Map.entry(i, copy); // old item IsManaged. need Copy a new one. |
| 292 | } |
| 293 | bean.getItems().clear(); |
| 294 | var sortMap = new HashMap<Integer, BItem>(); |
| 295 | for (var s : sort) |
| 296 | sortMap.put(s.getKey(), s.getValue()); |
| 297 | bean.getItems().putAll(sortMap); // use AddRange for performance |
| 298 | } |
| 299 | |
| 300 | public static class Module extends AbstractBag { |
| 301 | private final ConcurrentHashMap<String, Bag> bags = new ConcurrentHashMap<>(); |