Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use StringBuilder; use Java 5+ Generics #214

Merged
merged 2 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/main/java/nl/nn/testtool/Path.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020, 2022-2023 WeAreFrank!, 2018 Nationale-Nederlanden
Copyright 2020, 2022-2024 WeAreFrank!, 2018 Nationale-Nederlanden

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -53,10 +53,10 @@ public boolean equals(Path path) {
}

public String toString() {
StringBuffer stringBuffer = new StringBuffer();
StringBuilder builder = new StringBuilder();
for (int i = 0; i < names.length; i++) {
stringBuffer.append("/" + names[i] + "[" + counts[i] + "]");
builder.append("/" + names[i] + "[" + counts[i] + "]");
}
return stringBuffer.toString();
return builder.toString();
}
}
90 changes: 45 additions & 45 deletions src/main/java/nl/nn/testtool/Report.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2018-2023 WeAreFrank!
Copyright 2018-2024 WeAreFrank!

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -83,12 +83,12 @@ public class Report implements Serializable {
// https://stackoverflow.com/questions/10531076/serialization-via-objectinputstream-and-transient-fields
private transient String mainThread;
private transient long mainThreadFinishedTime = TIME_NOT_SET_VALUE;
private transient List<String> threads = new ArrayList<String>();
private transient List<String> threadsWithThreadCreatepoint = new ArrayList<String>();
private transient Map<String, Integer> threadCheckpointIndex = new HashMap<String, Integer>();
private transient Map<String, Integer> threadFirstLevel = new HashMap<String, Integer>();
private transient Map<String, Integer> threadLevel = new HashMap<String, Integer>();
private transient Map<String, String> threadParent = new HashMap<String, String>();
private transient List<String> threads = new ArrayList<>();
private transient List<String> threadsWithThreadCreatepoint = new ArrayList<>();
private transient Map<String, Integer> threadCheckpointIndex = new HashMap<>();
private transient Map<String, Integer> threadFirstLevel = new HashMap<>();
private transient Map<String, Integer> threadLevel = new HashMap<>();
private transient Map<String, String> threadParent = new HashMap<>();
private transient int threadsActiveCount = 0;
private transient TestTool testTool;
private transient boolean closed;
Expand Down Expand Up @@ -120,13 +120,13 @@ public class Report implements Serializable {
private transient Report originalReport;
private transient boolean differenceChecked = false;
private transient boolean differenceFound = false;
private transient Map<String, String> truncatedMessageMap = new RefCompareMap<String, String>();
private transient Map<String, String> truncatedMessageMap = new RefCompareMap<>();
private transient boolean reportFilterMatching = true;
private transient boolean logReportFilterMatching = true;
private transient boolean logMaxCheckpoints = true;
private transient boolean logMaxMemoryUsage = true;
private transient Map<Object, Set<Checkpoint>> streamingMessageListeners = new HashMap<Object, Set<Checkpoint>>();
private transient Map<Object, StreamingMessageResult> streamingMessageResults = new HashMap<Object, StreamingMessageResult>();
private transient Map<Object, Set<Checkpoint>> streamingMessageListeners = new HashMap<>();
private transient Map<Object, StreamingMessageResult> streamingMessageResults = new HashMap<>();

@Transient
@JsonIgnore
Expand Down Expand Up @@ -891,80 +891,80 @@ public String toXml() {

public String toXml(ReportRunner reportRunner) {
if (xml == null) {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("<Report");
stringBuffer.append(" Name=\"" + EscapeUtil.escapeXml(name) + "\"");
stringBuffer.append(" Description=\"" + EscapeUtil.escapeXml(description) + "\"");
stringBuffer.append(" Path=\"" + EscapeUtil.escapeXml(path) + "\"");
stringBuffer.append(" CorrelationId=\"" + EscapeUtil.escapeXml(correlationId) + "\"");
stringBuffer.append(" StartTime=\"" + startTime + "\"");
stringBuffer.append(" EndTime=\"" + endTime + "\"");
stringBuffer.append(" NumberOfCheckpoints=\"" + getNumberOfCheckpoints() + "\"");
stringBuffer.append(" EstimatedMemoryUsage=\"" + getEstimatedMemoryUsage() + "\"");
stringBuffer.append(">");
StringBuilder builder = new StringBuilder();
builder.append("<Report");
builder.append(" Name=\"" + EscapeUtil.escapeXml(name) + "\"");
builder.append(" Description=\"" + EscapeUtil.escapeXml(description) + "\"");
builder.append(" Path=\"" + EscapeUtil.escapeXml(path) + "\"");
builder.append(" CorrelationId=\"" + EscapeUtil.escapeXml(correlationId) + "\"");
builder.append(" StartTime=\"" + startTime + "\"");
builder.append(" EndTime=\"" + endTime + "\"");
builder.append(" NumberOfCheckpoints=\"" + getNumberOfCheckpoints() + "\"");
builder.append(" EstimatedMemoryUsage=\"" + getEstimatedMemoryUsage() + "\"");
builder.append(">");
for (Checkpoint checkpoint : checkpoints) {
String message;
if(reportRunner != null && checkpoint.containsVariables()) {
message = checkpoint.getMessageWithResolvedVariables(reportRunner);
} else {
message = checkpoint.getMessage();
}
stringBuffer.append("<Checkpoint");
stringBuffer.append(" Name=\"" + EscapeUtil.escapeXml(checkpoint.getName()) + "\"");
stringBuffer.append(" Type=\"" + EscapeUtil.escapeXml(checkpoint.getTypeAsString()) + "\"");
stringBuffer.append(" Level=\"" + checkpoint.getLevel() + "\"");
builder.append("<Checkpoint");
builder.append(" Name=\"" + EscapeUtil.escapeXml(checkpoint.getName()) + "\"");
builder.append(" Type=\"" + EscapeUtil.escapeXml(checkpoint.getTypeAsString()) + "\"");
builder.append(" Level=\"" + checkpoint.getLevel() + "\"");
if (checkpoint.getSourceClassName() != null) {
stringBuffer.append(" SourceClassName=\"" + EscapeUtil.escapeXml(checkpoint.getSourceClassName()) + "\"");
builder.append(" SourceClassName=\"" + EscapeUtil.escapeXml(checkpoint.getSourceClassName()) + "\"");
}
if (checkpoint.getMessageClassName() != null) {
stringBuffer.append(" MessageClassName=\"" + EscapeUtil.escapeXml(checkpoint.getMessageClassName()) + "\"");
builder.append(" MessageClassName=\"" + EscapeUtil.escapeXml(checkpoint.getMessageClassName()) + "\"");
}
if (checkpoint.getPreTruncatedMessageLength() != -1) {
stringBuffer.append(" PreTruncatedMessageLength=\"" + checkpoint.getPreTruncatedMessageLength() + "\"");
builder.append(" PreTruncatedMessageLength=\"" + checkpoint.getPreTruncatedMessageLength() + "\"");
}
if (checkpoint.getEncoding() != null) {
stringBuffer.append(" Encoding=\"" + EscapeUtil.escapeXml(checkpoint.getEncoding()) + "\"");
builder.append(" Encoding=\"" + EscapeUtil.escapeXml(checkpoint.getEncoding()) + "\"");
}
if (checkpoint.getStreaming() != null) {
stringBuffer.append(" Streaming=\"" + EscapeUtil.escapeXml(checkpoint.getStreaming()) + "\"");
builder.append(" Streaming=\"" + EscapeUtil.escapeXml(checkpoint.getStreaming()) + "\"");
}
if (checkpoint.isWaitingForStream()) {
stringBuffer.append(" WaitingForStream=\"" + checkpoint.isWaitingForStream() + "\"");
builder.append(" WaitingForStream=\"" + checkpoint.isWaitingForStream() + "\"");
}
if (checkpoint.getStub() != Checkpoint.STUB_FOLLOW_REPORT_STRATEGY) {
stringBuffer.append(" Stub=\"" + checkpoint.getStub() + "\"");
builder.append(" Stub=\"" + checkpoint.getStub() + "\"");
}
if (checkpoint.isStubbed()) {
stringBuffer.append(" Stubbed=\"" + checkpoint.isStubbed() + "\"");
builder.append(" Stubbed=\"" + checkpoint.isStubbed() + "\"");
}
if (checkpoint.getStubNotFound() != null) {
stringBuffer.append(" StubNotFound=\"" + checkpoint.getStubNotFound() + "\"");
builder.append(" StubNotFound=\"" + checkpoint.getStubNotFound() + "\"");
}
if (message == null) {
stringBuffer.append(" Null=\"true\"/>");
builder.append(" Null=\"true\"/>");
} else {
if (XmlUtil.isXml(message)) {
String textDecl = null;
if (message.startsWith("<?")) {
int i = message.indexOf("?>") + 2;
textDecl = message.substring(0, i);
stringBuffer.append(" TextDecl=\"");
stringBuffer.append(EscapeUtil.escapeXml(textDecl));
stringBuffer.append("\">");
builder.append(" TextDecl=\"");
builder.append(EscapeUtil.escapeXml(textDecl));
builder.append("\">");
message = message.substring(i);
} else {
stringBuffer.append(">");
builder.append(">");
}
stringBuffer.append(message);
builder.append(message);
} else {
stringBuffer.append(">");
stringBuffer.append(EscapeUtil.escapeXml(message));
builder.append(">");
builder.append(EscapeUtil.escapeXml(message));
}
stringBuffer.append("</Checkpoint>");
builder.append("</Checkpoint>");
}
}
stringBuffer.append("</Report>");
xml = stringBuffer.toString();
builder.append("</Report>");
xml = builder.toString();
if (reportXmlTransformer != null || (transformation != null && transformation.trim().length() > 0)) {
if (reportXmlTransformer == null) {
reportXmlTransformer = new ReportXmlTransformer();
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/nl/nn/testtool/echo2/reports/MessageComponent.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020, 2022-2023 WeAreFrank!, 2018-2019 Nationale-Nederlanden
Copyright 2020, 2022-2024 WeAreFrank!, 2018-2019 Nationale-Nederlanden

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -355,29 +355,29 @@ public static void removeLineNumbers(Column messageColumn) {
}

private static String replaceNonValidXmlCharacters(String string, Row row, boolean differenceFound) {
StringBuffer buffer = new StringBuffer();
StringBuilder builder = new StringBuilder();
int c;
for (int i = 0; i < string.length(); i += Character.charCount(c)) {
c = string.codePointAt(i);
if (isPrintableUnicodeChar(c)) {
buffer.appendCodePoint(c);
builder.appendCodePoint(c);
} else {
String substitute = REPLACE_NON_XML_CHAR + "#" + c + ";";
if (row == null) {
buffer.append(substitute);
builder.append(substitute);
} else {
row.add(createLabel(buffer.toString(), true, differenceFound));
row.add(createLabel(builder.toString(), true, differenceFound));
Label label = createLabel(substitute, true, differenceFound);
label.setBackground(Echo2Application.getButtonRolloverBackgroundColor());
row.add(label);
buffer = new StringBuffer();
builder = new StringBuilder();
}
}
}
if (row != null) {
row.add(createLabel(buffer.toString(), true, differenceFound));
row.add(createLabel(builder.toString(), true, differenceFound));
}
return buffer.toString();
return builder.toString();
}

// Copied from IAF XmlUtils
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/nl/nn/testtool/storage/file/TestStorage.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020-2022 WeAreFrank!, 2018 Nationale-Nederlanden
Copyright 2020-2024 WeAreFrank!, 2018 Nationale-Nederlanden

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -112,7 +112,7 @@ public void setPersistentMetadata(List<String> metadataNames) {
@Autowired
public void setMetadataNames(List<String> metadataNames) {
if (writer[0].getPersistentMetadata() == null) {
metadataNames = new ArrayList<String>();
metadataNames = new ArrayList<>();
metadataNames.add("storageId");
metadataNames.add("storageSize");
metadataNames.add("path");
Expand Down Expand Up @@ -190,7 +190,7 @@ private void update(Report report, boolean delete) throws StorageException {
} else {
byte[] reportBytes = reader[source].getReportBytes(storageId, writer[source].getSynchronizeRotate());
List persistentMetadata = writer[destination].getPersistentMetadata();
List searchValues = new ArrayList();
List<String> searchValues = new ArrayList<>();
searchValues.add("(" + storageId + ")"); // TODO een getMetadata maken die op exacte waarden kan zoeken zodat je er geen reg. expr. van hoeft te maken?
for (int i = 1; i < persistentMetadata.size(); i++) {
searchValues.add(null); // TODO is dit nodig?
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/nl/nn/testtool/storage/file/Writer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020-2023 WeAreFrank!, 2018 Nationale-Nederlanden
Copyright 2020-2024 WeAreFrank!, 2018 Nationale-Nederlanden

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -44,7 +44,7 @@
* @author Jaco de Groot
*/
public class Writer {
private static Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private final String synchronizeStore = "";
private final String synchronizeRotate = "";
private String reportsFilename;
Expand All @@ -57,7 +57,7 @@ public class Writer {
private FileOutputStream reportsFileOutputStream;
private FileOutputStream metadataFileOutputStream;
private OutputStreamWriter metadataOutputStreamWriter;
private List persistentMetadata;
private List<String> persistentMetadata;
private String metadataHeader;
private MetadataExtractor metadataExtractor;
// TODO private maken en via een methode doen?
Expand Down Expand Up @@ -91,12 +91,12 @@ private long getFreeSpaceMinimum() {
return freeSpaceMinimum;
}

protected void setPersistentMetadata(List metadataNames) {
protected void setPersistentMetadata(List<String> metadataNames) {
persistentMetadata = metadataNames;
metadataHeader = EscapeUtil.escapeCsv(persistentMetadata);
}

protected List getPersistentMetadata() {
protected List<String> getPersistentMetadata() {
return persistentMetadata;
}

Expand Down Expand Up @@ -129,15 +129,15 @@ protected void store(Report report, boolean preserveStorageId) throws StorageExc
report.setStorageSize(new Long(reportBytes.length));
List metadataValues = new ArrayList();
for (int i = 0; i < persistentMetadata.size(); i++) {
String metadataName = (String)persistentMetadata.get(i);
String metadataName = persistentMetadata.get(i);
metadataValues.add(metadataExtractor.getMetadata(report,
metadataName, MetadataExtractor.VALUE_TYPE_STRING));
}
store(report.getName(), reportBytes, metadataValues);
}
}

protected void store(String reportName, byte[] reportBytes, List metadataValues) throws StorageException {
protected void store(String reportName, byte[] reportBytes, List<String> metadataValues) throws StorageException {
synchronized(synchronizeStore) {
try {
if (reportsFileOutputStream == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023 WeAreFrank!
Copyright 2023-2024 WeAreFrank!

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -54,15 +54,15 @@ public String transform(Checkpoint checkpoint, String message) {
hide = true;
}
if (hide && message != null) {
StringBuffer buffer = new StringBuffer();
StringBuilder builder = new StringBuilder();
for (int i = 0; i < message.length(); i++) {
if (Character.isWhitespace(message.charAt(i)) && skipeWhitespace) {
buffer.append(message.charAt(i));
builder.append(message.charAt(i));
} else {
buffer.append('*');
builder.append('*');
}
}
message = buffer.toString();
message = builder.toString();
}
return message;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020, 2022 WeAreFrank!, 2018-2019 Nationale-Nederlanden
Copyright 2020-2024 WeAreFrank!, 2018-2019 Nationale-Nederlanden

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -43,7 +43,7 @@

@Singleton
public class ReportXmlTransformer {
private Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private @Setter @Inject @Autowired String xsltResource;
private String xslt;
private Transformer transformer;
Expand All @@ -52,7 +52,7 @@ public class ReportXmlTransformer {

@PostConstruct
public void init() {
StringBuffer result = new StringBuffer();
StringBuilder result = new StringBuilder();
InputStream stream = getClass().getClassLoader().getResourceAsStream(xsltResource);
if (stream == null) {
createTransformerError = "Could not find xslt resource: " + xsltResource;
Expand Down Expand Up @@ -154,7 +154,7 @@ private void printFirstXmlCharacters(String xml, StringWriter stringWriter) {
}

class TransformerFactoryErrorListener implements ErrorListener {
private Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
String errorMessages;

public void error(TransformerException exception) {
Expand Down
Loading
Loading