Skip to content

Commit 7e35abe

Browse files
committed
Clean up some pre-Java 17 smell
Signed-off-by: Mitch Gaffigan <mitch.gaffigan@comcast.net>
1 parent 9240971 commit 7e35abe

5 files changed

Lines changed: 72 additions & 57 deletions

File tree

client/src/com/mirth/connect/client/ui/browsers/message/MessageBrowserAdvancedFilter.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111

1212
import java.awt.Component;
1313
import java.util.ArrayList;
14+
import java.util.Calendar;
1415
import java.util.HashMap;
1516
import java.util.List;
17+
import java.util.Objects;
1618
import java.util.Map;
1719
import java.util.prefs.Preferences;
1820

@@ -29,6 +31,8 @@
2931
import javax.swing.table.TableColumn;
3032
import javax.swing.table.TableModel;
3133

34+
import java.text.SimpleDateFormat;
35+
3236
import org.apache.commons.lang3.StringUtils;
3337
import org.jdesktop.swingx.decorator.HighlighterFactory;
3438

@@ -540,15 +544,15 @@ public void applyFilter(MessageFilter messageFilter) {
540544
}
541545
}
542546

543-
messageIdLowerField.setText((messageFilter.getMinMessageId() == null) ? "" : String.valueOf(messageFilter.getMinMessageId()));
544-
messageIdUpperField.setText((messageFilter.getMaxMessageId() == null) ? "" : String.valueOf(messageFilter.getMaxMessageId()));
545-
originalIdLowerField.setText((messageFilter.getOriginalIdLower() == null) ? "" : String.valueOf(messageFilter.getOriginalIdLower()));
546-
originalIdUpperField.setText((messageFilter.getOriginalIdUpper() == null) ? "" : String.valueOf(messageFilter.getOriginalIdUpper()));
547-
importIdLowerField.setText((messageFilter.getImportIdLower() == null) ? "" : String.valueOf(messageFilter.getImportIdLower()));
548-
importIdUpperField.setText((messageFilter.getImportIdUpper() == null) ? "" : String.valueOf(messageFilter.getImportIdUpper()));
547+
messageIdLowerField.setText(Objects.toString(messageFilter.getMinMessageId(), ""));
548+
messageIdUpperField.setText(Objects.toString(messageFilter.getMaxMessageId(), ""));
549+
originalIdLowerField.setText(Objects.toString(messageFilter.getOriginalIdLower(), ""));
550+
originalIdUpperField.setText(Objects.toString(messageFilter.getOriginalIdUpper(), ""));
551+
importIdLowerField.setText(Objects.toString(messageFilter.getImportIdLower(), ""));
552+
importIdUpperField.setText(Objects.toString(messageFilter.getImportIdUpper(), ""));
549553
serverIdField.setText(StringUtils.defaultString(messageFilter.getServerId()));
550554
sendAttemptsLower.setValue((messageFilter.getSendAttemptsLower() == null) ? 0 : messageFilter.getSendAttemptsLower());
551-
sendAttemptsUpper.setValue((messageFilter.getSendAttemptsUpper() == null) ? "" : String.valueOf(messageFilter.getSendAttemptsUpper()));
555+
sendAttemptsUpper.setValue(Objects.toString(messageFilter.getSendAttemptsUpper(), ""));
552556
attachmentCheckBox.setSelected(Boolean.TRUE.equals(messageFilter.getAttachment()));
553557
errorCheckBox.setSelected(Boolean.TRUE.equals(messageFilter.getError()));
554558

@@ -578,8 +582,8 @@ private String formatMetaDataValue(Object value) {
578582
return "";
579583
}
580584

581-
if (value instanceof java.util.Calendar) {
582-
return new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(((java.util.Calendar) value).getTime());
585+
if (value instanceof Calendar calendar) {
586+
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar.getTime());
583587
}
584588

585589
return String.valueOf(value);
Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
/*
2-
* Copyright (c) Mirth Corporation. All rights reserved.
3-
*
4-
* http://www.mirthcorp.com
5-
*
6-
* The software in this package is published under the terms of the MPL license a copy of which has
7-
* been included with this distribution in the LICENSE.txt file.
8-
*/
1+
// SPDX-License-Identifier: MPL-2.0
2+
// SPDX-FileCopyrightText: 2025 Mitch Gaffigan
93

104
package com.mirth.connect.client.ui.browsers.message;
115

@@ -14,7 +8,8 @@
148
import java.util.Map;
159
import java.util.concurrent.ConcurrentHashMap;
1610

17-
import org.apache.commons.lang3.StringUtils;
11+
import org.apache.logging.log4j.LogManager;
12+
import org.apache.logging.log4j.Logger;
1813

1914
import com.mirth.connect.model.converters.ObjectXMLSerializer;
2015
import com.mirth.connect.model.filters.MessageFilter;
@@ -25,6 +20,7 @@ class MessageBrowserRecentFilterStore {
2520
// TODO: Replace with a cross-session time-limited encrypted store
2621
// (In-memory assuming text searches represent PHI)
2722
private static final Map<String, String> RECENT_FILTERS_BY_CHANNEL = new ConcurrentHashMap<>();
23+
private Logger logger = LogManager.getLogger(this.getClass());
2824

2925
private final String prefKey;
3026

@@ -35,15 +31,15 @@ public MessageBrowserRecentFilterStore(String channelId) {
3531
public List<MessageFilter> getRecentFilters() {
3632
try {
3733
String serialized = RECENT_FILTERS_BY_CHANNEL.getOrDefault(prefKey, "");
38-
if (StringUtils.isBlank(serialized)) return List.of();
34+
if (serialized.isBlank()) return List.of();
3935

40-
var result = ObjectXMLSerializer.getInstance().deserialize(serialized, List.class);
36+
var result = ObjectXMLSerializer.getInstance().deserializeList(serialized, MessageFilter.class);
4137
if (result == null) return List.of();
4238

43-
return (List<MessageFilter>) result;
39+
return result;
4440
} catch (Exception e) {
4541
// Fail quietly if the stored filters cannot be deserialized for any reason.
46-
e.printStackTrace();
42+
logger.warn("Failed to deserialize recent message filters for key {}.", prefKey, e);
4743
return List.of();
4844
}
4945
}
@@ -53,7 +49,7 @@ public void addRecentFilter(MessageFilter filter) {
5349
throw new IllegalArgumentException("Filter cannot be null");
5450
}
5551

56-
var filters = new ArrayList<MessageFilter>(getRecentFilters());
52+
var filters = new ArrayList<>(getRecentFilters());
5753

5854
// Remove then re-add to avoid duplicates
5955
filters.remove(filter);
@@ -67,7 +63,7 @@ public void addRecentFilter(MessageFilter filter) {
6763
try {
6864
RECENT_FILTERS_BY_CHANNEL.put(prefKey, ObjectXMLSerializer.getInstance().serialize(filters));
6965
} catch (Exception e) {
70-
e.printStackTrace();
66+
logger.warn("Failed to serialize recent message filters for key {}.", prefKey, e);
7167
}
7268
}
7369
}

server/src/com/mirth/connect/model/filters/MessageFilter.java

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,7 @@ public void setError(Boolean error) {
238238

239239
@Override
240240
public boolean equals(Object obj) {
241-
return obj instanceof MessageFilter
242-
&& equals((MessageFilter) obj);
241+
return obj instanceof MessageFilter filter && equals(filter);
243242
}
244243

245244
/** Check if the filter has logically identical criteria */
@@ -308,15 +307,15 @@ public String toDisplayString(Map<Integer, String> connectors, String padding, b
308307
}
309308

310309
if (minMessageId != null) {
311-
if (text.length() > 0) text.append(padding);
310+
if (!text.isEmpty()) text.append(padding);
312311
text.append("Min Message Id: ");
313312
text.append(minMessageId);
314313
}
315314

316315
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
317316

318317
if (includeEmptyCriteria || startDate != null || endDate != null) {
319-
if (text.length() > 0) text.append(padding);
318+
if (!text.isEmpty()) text.append(padding);
320319
text.append("Date Range: ");
321320

322321
if (startDate == null) {
@@ -335,7 +334,7 @@ public String toDisplayString(Map<Integer, String> connectors, String padding, b
335334
}
336335

337336
if (includeEmptyCriteria || (statuses != null && !statuses.isEmpty())) {
338-
if (text.length() > 0) text.append(padding);
337+
if (!text.isEmpty()) text.append(padding);
339338
text.append("Statuses: ");
340339

341340
if (statuses == null) {
@@ -346,47 +345,60 @@ public String toDisplayString(Map<Integer, String> connectors, String padding, b
346345
}
347346

348347
if (textSearch != null) {
349-
if (text.length() > 0) text.append(padding);
350-
text.append("Text Search: " + textSearch);
348+
if (!text.isEmpty()) text.append(padding);
349+
text.append("Text Search: ");
350+
text.append(textSearch);
351351
}
352352

353353
if (includeEmptyCriteria
354354
|| (includedMetaDataIds != null && !includedMetaDataIds.isEmpty())
355-
|| (excludedMetaDataIds != null && !excludedMetaDataIds.isEmpty())) {
355+
|| (excludedMetaDataIds != null && !excludedMetaDataIds.isEmpty())
356+
) {
356357
getConnectorSearchCriteriaText(text, padding, connectors);
357358
}
358359

359360
if (originalIdLower != null || originalIdUpper != null) {
360-
if (text.length() > 0) text.append(padding);
361+
if (!text.isEmpty()) text.append(padding);
361362
text.append("Original Id: ");
362363
if (originalIdUpper == null) {
363-
text.append("Greater than " + originalIdLower);
364+
text.append("Greater than ");
365+
text.append(originalIdLower);
364366
} else if (originalIdLower == null) {
365-
text.append("Less than " + originalIdUpper);
367+
text.append("Less than ");
368+
text.append(originalIdUpper);
366369
} else {
367-
text.append("Between " + originalIdLower + " and " + originalIdUpper);
370+
text.append("Between ");
371+
text.append(originalIdLower);
372+
text.append(" and ");
373+
text.append(originalIdUpper);
368374
}
369375
}
370376

371377
if (importIdLower != null || importIdUpper != null) {
372-
if (text.length() > 0) text.append(padding);
378+
if (!text.isEmpty()) text.append(padding);
373379
text.append("Import Id: ");
374380
if (importIdUpper == null) {
375-
text.append("Greater than " + importIdLower);
381+
text.append("Greater than ");
382+
text.append(importIdLower);
376383
} else if (importIdLower == null) {
377-
text.append("Less than " + importIdUpper);
384+
text.append("Less than ");
385+
text.append(importIdUpper);
378386
} else {
379-
text.append("Between " + importIdLower + " and " + importIdUpper);
387+
text.append("Between ");
388+
text.append(importIdLower);
389+
text.append(" and ");
390+
text.append(importIdUpper);
380391
}
381392
}
382393

383394
if (serverId != null) {
384-
if (text.length() > 0) text.append(padding);
385-
text.append("Server Id: " + serverId);
395+
if (!text.isEmpty()) text.append(padding);
396+
text.append("Server Id: ");
397+
text.append(serverId);
386398
}
387399

388400
if (sendAttemptsLower != null || sendAttemptsUpper != null) {
389-
if (text.length() > 0) text.append(padding);
401+
if (!text.isEmpty()) text.append(padding);
390402
text.append("# of Send Attempts: ");
391403

392404
if (sendAttemptsLower != null) {
@@ -407,19 +419,24 @@ public String toDisplayString(Map<Integer, String> connectors, String padding, b
407419
if (contentSearch != null) {
408420
for (ContentSearchElement element : contentSearch) {
409421
for (String value : element.getSearches()) {
410-
if (text.length() > 0) text.append(padding);
411-
text.append(ContentType.fromCode(element.getContentCode()) + " contains \"" + value + "\"");
422+
if (!text.isEmpty()) text.append(padding);
423+
text.append(ContentType.fromCode(element.getContentCode()));
424+
text.append(" contains \"");
425+
text.append(value);
426+
text.append("\"");
412427
}
413428
}
414429
}
415430

416431
if (metaDataSearch != null) {
417432
for (MetaDataSearchElement element : metaDataSearch) {
418-
if (text.length() > 0) text.append(padding);
419-
text.append(element.getColumnName() + " " + MetaDataSearchOperator.fromString(element.getOperator()).toString() + " ");
420-
if (element.getValue() instanceof Calendar) {
421-
Calendar date = (Calendar) element.getValue();
422-
text.append(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date.getTime()));
433+
if (!text.isEmpty()) text.append(padding);
434+
text.append(element.getColumnName());
435+
text.append(" ");
436+
text.append(MetaDataSearchOperator.fromString(element.getOperator()).toString());
437+
text.append(" ");
438+
if (element.getValue() instanceof Calendar calendar) {
439+
text.append(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar.getTime()));
423440
} else {
424441
text.append(element.getValue());
425442
}
@@ -430,12 +447,12 @@ public String toDisplayString(Map<Integer, String> connectors, String padding, b
430447
}
431448

432449
if (Boolean.TRUE.equals(attachment)) {
433-
if (text.length() > 0) text.append(padding);
450+
if (!text.isEmpty()) text.append(padding);
434451
text.append("Has Attachment");
435452
}
436453

437454
if (Boolean.TRUE.equals(error)) {
438-
if (text.length() > 0) text.append(padding);
455+
if (!text.isEmpty()) text.append(padding);
439456
text.append("Has Error");
440457
}
441458

@@ -447,7 +464,7 @@ public String toDisplayString(Map<Integer, String> connectors, String padding, b
447464
}
448465

449466
private void getConnectorSearchCriteriaText(StringBuilder text, String padding, Map<Integer, String> connectors) {
450-
if (text.length() > 0) text.append(padding);
467+
if (!text.isEmpty()) text.append(padding);
451468
text.append("Connectors: ");
452469

453470
if (includedMetaDataIds == null) {

server/src/com/mirth/connect/model/filters/elements/ContentSearchElement.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ public String toString() {
4545

4646
@Override
4747
public boolean equals(Object obj) {
48-
return obj instanceof ContentSearchElement
49-
&& equals((ContentSearchElement) obj);
48+
return obj instanceof ContentSearchElement element && equals(element);
5049
}
5150

5251
/** Check if the element has logically identical criteria */

server/src/com/mirth/connect/model/filters/elements/MetaDataSearchElement.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ public String toString() {
6565

6666
@Override
6767
public boolean equals(Object obj) {
68-
return obj instanceof MetaDataSearchElement
69-
&& equals((MetaDataSearchElement) obj);
68+
return obj instanceof MetaDataSearchElement element && equals(element);
7069
}
7170

7271
/** Check if the element has logically identical criteria */

0 commit comments

Comments
 (0)