So I have created an error message for my code. Currently, my code spits out the error message each time it appears. My code validates and makes sure that an excel file is formatted correctly. After validation, it gives back error/warning messages if they occur. So when I get error messages, each message appears each time it happens. For example, the error message "Error, id must not contain special characters" happens 6 times when validating the excel file. What way is there to simply write to check if the message already occurred, and keep a counter of how many times so I can display that?
I thought about something like if (message = message) { //then create counter}
but that doesn't work since message always equals message. Does anyone have any ways to do it?
EDIT: Here is a snipit of the code for validation. I want to group the messages together and not have them repeat when posting to the API.
// if there are errors, then
if (!errorResponse.getItems().isEmpty()) {
// set error response
Iterator<ErrorMessage> iter = errorResponse.getItems().iterator();
Set<ErrorMessage> summarizedErrorMessages = new HashSet<>();
while (iter.hasNext()) {
ErrorMessage sem = new ErrorMessage();
ErrorMessage em = iter.next();
if (!summarizedErrorMessages.contains(em)) {
sem.setMessage(em.getMessage());
sem.setTotal(1);
} else {
sem.setTotal(sem.getTotal() + 1);
}
summarizedErrorMessages.add(sem);
}
errorResponse.setItems(summarizedErrorMessages);
warningResponse.setItems(new ArrayList<WarningMessage>());