3
3
import stroom .data .retention .shared .DataRetentionDeleteSummary ;
4
4
import stroom .data .retention .shared .DataRetentionRule ;
5
5
import stroom .data .retention .shared .FindDataRetentionImpactCriteria ;
6
+ import stroom .util .shared .CompareUtil ;
7
+ import stroom .util .shared .CriteriaFieldSort ;
6
8
import stroom .util .shared .Expander ;
9
+ import stroom .util .shared .GwtNullSafe ;
7
10
import stroom .util .shared .time .TimeUnit ;
8
11
9
12
import java .util .ArrayList ;
15
18
import java .util .Objects ;
16
19
import java .util .Optional ;
17
20
import java .util .Set ;
18
- import java .util .concurrent .atomic .AtomicLong ;
19
21
import java .util .function .Function ;
20
22
import java .util .stream .Collectors ;
21
23
@@ -28,15 +30,15 @@ public class DataRetentionImpactRow {
28
30
public static final String FIELD_NAME_TYPE = "Type" ;
29
31
public static final String FIELD_NAME_DELETE_COUNT = "Stream Delete Count" ;
30
32
31
- public static final Comparator <DataRetentionImpactRow > FEED_COMPARATOR = Comparator . comparing (
33
+ public static final Comparator <DataRetentionImpactRow > FEED_COMPARATOR = CompareUtil . getNullSafeComparator (
32
34
DataRetentionImpactRow ::getFeed );
33
- public static final Comparator <DataRetentionImpactRow > TYPE_COMPARATOR = Comparator . comparing (
35
+ public static final Comparator <DataRetentionImpactRow > TYPE_COMPARATOR = CompareUtil . getNullSafeComparator (
34
36
DataRetentionImpactRow ::getType );
35
37
public static final Comparator <DataRetentionImpactRow > COUNT_COMPARATOR = Comparator .comparingInt (
36
38
DataRetentionImpactRow ::getCount );
37
- public static final Comparator <DataRetentionImpactRow > RULE_NO_COMPARATOR = Comparator . comparingInt (
39
+ public static final Comparator <DataRetentionImpactRow > RULE_NO_COMPARATOR = CompareUtil . getNullSafeComparator (
38
40
DataRetentionImpactRow ::getRuleNumber );
39
- public static final Comparator <DataRetentionImpactRow > RULE_NAME_COMPARATOR = Comparator . comparing (
41
+ public static final Comparator <DataRetentionImpactRow > RULE_NAME_COMPARATOR = CompareUtil . getNullSafeComparator (
40
42
DataRetentionImpactRow ::getRuleName );
41
43
public static final Comparator <DataRetentionImpactRow > RULE_AGE_COMPARATOR =
42
44
Comparator .comparingLong (row ->
@@ -136,21 +138,12 @@ public void setExpander(final Expander expander) {
136
138
this .expander = expander ;
137
139
}
138
140
139
- private Comparator <DataRetentionImpactRow > chainComparators (
140
- final Comparator <DataRetentionImpactRow > first ,
141
- final Comparator <DataRetentionImpactRow > second ) {
142
-
143
- if (first == null ) {
144
- return second ;
145
- } else {
146
- return first .thenComparing (second );
147
- }
148
- }
149
-
150
141
private static Comparator <DataRetentionImpactRow > buildComparator (final FindDataRetentionImpactCriteria criteria ) {
151
142
152
- if (criteria != null && criteria .getSortList () != null ) {
153
- List <Comparator <DataRetentionImpactRow >> comparators = criteria .getSortList ().stream ()
143
+ final List <CriteriaFieldSort > sortList = criteria .getSortList ();
144
+ if (GwtNullSafe .hasItems (sortList )) {
145
+ //noinspection SimplifyStreamApiCallChains // Cos GWT
146
+ List <Comparator <DataRetentionImpactRow >> comparators = sortList .stream ()
154
147
.filter (Objects ::nonNull )
155
148
.map (sort ->
156
149
Optional .ofNullable (FIELD_TO_COMPARATOR_MAP .get (sort .getId ()))
@@ -186,10 +179,9 @@ public static List<DataRetentionImpactRow> buildFlatTable(final List<DataRetenti
186
179
187
180
Map <Integer , DataRetentionRule > ruleNoToRuleMap = rules .stream ()
188
181
.collect (Collectors .toMap (
189
- rule -> Integer . valueOf ( rule . getRuleNumber ()) , // Manual boxing to keep GWT happy
182
+ DataRetentionRule :: getRuleNumber , // Manual boxing to keep GWT happy
190
183
Function .identity ()));
191
184
192
- final AtomicLong rowNumber = new AtomicLong (1 );
193
185
return summaries .stream ()
194
186
.map (summary -> {
195
187
final DataRetentionRule rule = ruleNoToRuleMap .get (summary .getRuleNumber ());
@@ -224,8 +216,6 @@ public static List<DataRetentionImpactRow> buildNestedTable(final List<DataReten
224
216
DataRetentionDeleteSummary ::getRuleNumber ,
225
217
Collectors .toSet ()));
226
218
227
- final AtomicLong rowNumber = new AtomicLong (1 );
228
-
229
219
rules .stream ()
230
220
.map (rule ->
231
221
buildRuleRow (
@@ -274,14 +264,15 @@ public static List<DataRetentionImpactRow> buildNestedTable(final List<DataReten
274
264
summariesByRuleAndType .get (metaTypeRow .getType ());
275
265
276
266
if (isExpanded (treeAction , metaTypeRow , 1 )
277
- && summariesForRuleAndType != null ) {
267
+ && summariesForRuleAndType != null ) {
278
268
279
269
Comparator <DataRetentionImpactRow > feedRowComparator = getComparator (
280
270
criteria ,
281
271
FEED_COMPARATOR ,
282
272
FIELD_NAME_FEED ,
283
273
FIELD_NAME_DELETE_COUNT );
284
274
275
+ //noinspection SimplifyStreamApiCallChains // Cos GWT
285
276
rows .addAll (summariesForRuleAndType .stream ()
286
277
.map (summaryForRuleTypeAndFeed ->
287
278
buildFeedRow (
@@ -305,8 +296,9 @@ private static Comparator<DataRetentionImpactRow> getComparator(
305
296
// If the sort list contains any of the sortableFieldNames then create a
306
297
// comparator for it. Assumes only one sort in the sort list
307
298
308
- if (criteria .getSortList () != null && !criteria .getSortList ().isEmpty ()) {
309
- return criteria .getSortList ().stream ()
299
+ final List <CriteriaFieldSort > sortList = criteria .getSortList ();
300
+ if (GwtNullSafe .hasItems (sortList )) {
301
+ return sortList .stream ()
310
302
.filter (sort ->
311
303
Arrays .stream (sortableFieldNames )
312
304
.anyMatch (fieldName ->
@@ -327,14 +319,9 @@ private static Comparator<DataRetentionImpactRow> getComparator(
327
319
private static DataRetentionImpactRow buildRuleRow (final DataRetentionRule rule ,
328
320
final DataRetentionImpactTreeAction treeAction ,
329
321
final Set <DataRetentionDeleteSummary > summaries ) {
330
- final int totalCount ;
331
- if (summaries != null ) {
332
- totalCount = summaries .stream ()
333
- .mapToInt (DataRetentionDeleteSummary ::getCount )
334
- .sum ();
335
- } else {
336
- totalCount = 0 ;
337
- }
322
+ final int totalCount = GwtNullSafe .stream (summaries )
323
+ .mapToInt (DataRetentionDeleteSummary ::getCount )
324
+ .sum ();
338
325
339
326
// TODO once we have built all the rows we will still have all the source data in memory.
340
327
// We could change this class so it holds a ref to the source summary object and then
@@ -359,7 +346,7 @@ private static DataRetentionImpactRow buildRuleRow(final DataRetentionRule rule,
359
346
totalCount );
360
347
361
348
final int depth = 0 ;
362
- final boolean isLeaf = summaries == null || summaries . isEmpty ( );
349
+ final boolean isLeaf = GwtNullSafe . isEmptyCollection ( summaries );
363
350
364
351
setExpander (treeAction , row , depth , isLeaf );
365
352
@@ -372,14 +359,9 @@ private static DataRetentionImpactRow buildMetaTypeRow(final int ruleNumber,
372
359
final Set <DataRetentionDeleteSummary > summaries ,
373
360
final DataRetentionImpactTreeAction treeAction ) {
374
361
375
- final int countByRuleAndFeed ;
376
- if (summaries != null ) {
377
- countByRuleAndFeed = summaries .stream ()
378
- .mapToInt (DataRetentionDeleteSummary ::getCount )
379
- .sum ();
380
- } else {
381
- countByRuleAndFeed = 0 ;
382
- }
362
+ final int countByRuleAndFeed = GwtNullSafe .stream (summaries )
363
+ .mapToInt (DataRetentionDeleteSummary ::getCount )
364
+ .sum ();
383
365
384
366
final DataRetentionImpactRow row = new DataRetentionImpactRow (
385
367
buildRowKey (ruleNumber , metaType , null ),
@@ -393,7 +375,7 @@ private static DataRetentionImpactRow buildMetaTypeRow(final int ruleNumber,
393
375
countByRuleAndFeed );
394
376
395
377
final int depth = 1 ;
396
- final boolean isLeaf = summaries == null || summaries . isEmpty ( );
378
+ final boolean isLeaf = GwtNullSafe . isEmptyCollection ( summaries );
397
379
398
380
setExpander (treeAction , row , depth , isLeaf );
399
381
@@ -464,12 +446,12 @@ public boolean equals(final Object o) {
464
446
}
465
447
final DataRetentionImpactRow that = (DataRetentionImpactRow ) o ;
466
448
return count == that .count &&
467
- Objects .equals (rowKey , that .rowKey ) &&
468
- Objects .equals (ruleNumber , that .ruleNumber ) &&
469
- Objects .equals (ruleName , that .ruleName ) &&
470
- Objects .equals (ruleAgeStr , that .ruleAgeStr ) &&
471
- Objects .equals (feed , that .feed ) &&
472
- Objects .equals (type , that .type );
449
+ Objects .equals (rowKey , that .rowKey ) &&
450
+ Objects .equals (ruleNumber , that .ruleNumber ) &&
451
+ Objects .equals (ruleName , that .ruleName ) &&
452
+ Objects .equals (ruleAgeStr , that .ruleAgeStr ) &&
453
+ Objects .equals (feed , that .feed ) &&
454
+ Objects .equals (type , that .type );
473
455
}
474
456
475
457
@ Override
@@ -480,15 +462,15 @@ public int hashCode() {
480
462
@ Override
481
463
public String toString () {
482
464
return "DataRetentionImpactRow{" +
483
- "rowKey=" + rowKey +
484
- ", ruleNumber=" + ruleNumber +
485
- ", ruleName='" + ruleName + '\'' +
486
- ", ruleAge='" + ruleAgeStr + '\'' +
487
- ", feedName='" + feed + '\'' +
488
- ", metaType='" + type + '\'' +
489
- ", count=" + count +
490
- ", expander=" + expander +
491
- '}' ;
465
+ "rowKey=" + rowKey +
466
+ ", ruleNumber=" + ruleNumber +
467
+ ", ruleName='" + ruleName + '\'' +
468
+ ", ruleAge='" + ruleAgeStr + '\'' +
469
+ ", feedName='" + feed + '\'' +
470
+ ", metaType='" + type + '\'' +
471
+ ", count=" + count +
472
+ ", expander=" + expander +
473
+ '}' ;
492
474
}
493
475
494
476
/**
0 commit comments