package com.sleekbyte.tailor.output;

/**
 * Note: this class has a natural ordering that is inconsistent with equals.
 */
public class ViolationMessage implements Comparable<ViolationMessage> {

    public static final ViolationMessage EMPTY = new ViolationMessage("", 0, 0, "", "");
    private final String filePath;
    private final int lineNumber;
    private final int columnNumber;
    private final String classification;
    private final String violationMessage;

    public ViolationMessage(String filePath, int lineNumber, int columnNumber, String classification,
                            String violationMessage) {
        this.filePath = filePath;
        this.lineNumber = lineNumber;
        this.columnNumber = columnNumber;
        this.classification = classification;
        this.violationMessage = violationMessage;
    }

    @Override
    public int compareTo(final ViolationMessage message) {
        int ret = this.lineNumber - message.lineNumber;
        if (ret == 0) {
            ret = this.columnNumber - message.columnNumber;
        }
        return ret;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || this.getClass() != o.getClass()) { return false; }

        ViolationMessage that = (ViolationMessage) o;

        // Test primitives (int) for equality first, then objects (String)
        if (this.lineNumber != that.lineNumber) { return false; }
        if (this.columnNumber != that.columnNumber) { return false; }
        if (!this.filePath.equals(that.filePath)) { return false; }
        if (!this.classification.equals(that.classification)) { return false; }
        return this.violationMessage.equals(that.violationMessage);
    }

    @Override
    public String toString() {
        // filePath, classification, violationMessage are optional in the output, but at least one must be present
        if (this.filePath.isEmpty() && this.classification.isEmpty() && this.violationMessage.isEmpty()) { return ""; }

        if (this.columnNumber == 0) {
            return String.format("%s:%d: %s: %s", this.filePath, this.lineNumber, this.classification,
                this.violationMessage);
        }
        return String.format("%s:%d:%d: %s: %s", this.filePath, this.lineNumber, this.columnNumber, this.classification,
            this.violationMessage);
    }

}

@@ -1391,26 +1391,30 @@
 ng)%0A        
-if
+return
  (this.lineN
@@ -1415,25 +1415,25 @@
 .lineNumber 
-!
+=
 = that.lineN
@@ -1442,35 +1442,21 @@
 ber)
- %7B return false; %7D%0A
+%0A    
         
 if (
@@ -1443,34 +1443,34 @@
 er)%0A            
-if
+&&
  (this.columnNum
@@ -1473,17 +1473,17 @@
 nNumber 
-!
+=
 = that.c
@@ -1498,35 +1498,20 @@
 ber)
- %7B return false; %7D%0A
+%0A   
         
 if (
@@ -1502,29 +1502,29 @@
 %0A           
-if
+ &&
  (
-!
 this.filePat
@@ -1551,35 +1551,21 @@
 th))
- %7B return false; %7D%0A
+%0A    
         
 if (
@@ -1564,13 +1564,12 @@
     
-if
+&&
  (
-!
 this
@@ -1616,35 +1616,20 @@
 on))
- %7B return false; %7D%0A
+%0A   
         
 retu
@@ -1624,23 +1624,21 @@
         
-return 
+ && (
 this.vio
@@ -1672,32 +1672,33 @@
 iolationMessage)
+)
 ;%0A    %7D%0A%0A    @Ov

Use short-circuit evaluation return statement