package innovimax.mixthem.operation;

import java.util.EnumSet;

/**
* <p>Describes the result of an line operation on two files.</p>
* @author Innovimax
* @version 1.0
*/
public class LineResult {
    
    private final EnumSet<ResultType> types;
    private String result;
    private String readLine1;
    private String readLine2;    
    private String keptLine1;
    private String keptLine2;    
    
    /**
    * Creates a line result.    
    */
    public LineResult() {
        this.types = EnumSet.noneOf(ResultType.class);
        this.result = null;
        this.readLine1 = null;
        this.readLine2 = null;
        this.keptLine1 = null;
        this.keptLine2 = null;
    }

    /**
    * Reset the result.
    */
    void reset() {        
        this.types.clear();
        this.result = null;
    }
    
    /**
    * Set the result (maybe null).
    */
    void setResult(String result) {
        this.result = result;
        if (result != null) {
            this.types.add(ResultType.HAS_RESULT);
        }
    }

    /**
    * Returns the result (maybe null).
    */
    String getResult() {
        return this.result;
    }

    /**
    * Has a result ?
    */
    boolean hasResult() {
        return this.types.contains(ResultType.HAS_RESULT);     
    }

    /**
    * Get the first line.
    */
    String getFirstLine() {        
        return this.keptLine1 != null ? this.keptLine1 : this.readLine1;        
    }
       
    /**
    * Has first line?
    */
    boolean hasFirstLine() {
        return getFirstLine() != null;
    }

    /**
    * Set the first line.
    */
    void setFirstLine(String line) {
        if (this.keptLine1 != null) {            
            preserveFirstLine();
            this.keptLine1 = null;
        } else {
            this.readLine1 = line; 
        }
    }

    /**
    * Keep previous first line and set future first line.
    */
    void keepFirstLine(String line) {
        this.keptLine1 = this.readLine1;
        this.readLine1 = line;
    }
    
    /**
    * Get the second line.
    */
    String getSecondLine() {        
        return this.keptLine2 != null ? this.keptLine2 : this.readLine2;        
    }
       
    /**
    * Has second line?
    */
    boolean hasSecondLine() {
        return getSecondLine() != null;
    }

    /**
    * Set the second line.
    */
    void setSecondLine(String line) {
        if (this.keptLine2 != null) {            
            preserveSecondLine();
            this.keptLine2 = null;
        } else {
            this.readLine2 = line; 
        }
    }
    
    /**
    * Keep previous second line and set future second line.
    */
    void keepSecondLine(String line) {
        this.keptLine2 = this.readLine2;
        this.readLine2 = line;
    }
    
    /**
    * Preserves first file from reading (keep line)
    */
    void preserveFirstLine() {        
        this.types.add(ResultType.PRESERVE_FIRST_LINE);
    }

    /**
    * First line preserved ?
    */
    boolean firstLinePreserved() {
        return this.types.contains(ResultType.PRESERVE_FIRST_LINE);
    }
    
    /**
    * Has to read first file ?
    */
    boolean readingFirstFile() {
        return !this.types.contains(ResultType.PRESERVE_FIRST_LINE);
    }

    /**
    * Preserves second file from reading (keep line)
    */
    void preserveSecondLine() {
        this.types.add(ResultType.PRESERVE_SECOND_LINE);        
    }
    
    /**
    * Second line preserved ?
    */
    boolean secondLinePreserved() {
        return this.types.contains(ResultType.PRESERVE_SECOND_LINE);
    }

    /**
    * Has to read second file ?
    */
    boolean readingSecondFile() {
        return !this.types.contains(ResultType.PRESERVE_SECOND_LINE);
    }

}

@@ -891,16 +891,22 @@
 tResult(
+final 
 String r
@@ -910,24 +910,24 @@
 g result) %7B%0A
-
         this
@@ -1628,32 +1628,38 @@
 id setFirstLine(
+final 
 String line) %7B%0A 
@@ -1937,24 +1937,30 @@
 epFirstLine(
+final 
 String line)
@@ -2391,32 +2391,38 @@
 d setSecondLine(
+final 
 String line) %7B%0A 
@@ -2680,32 +2680,32 @@
 nd line.%0A    */%0A
-
     void keepSec
@@ -2712,16 +2712,22 @@
 ondLine(
+final 
 String l

Update LineResult.java