package innovimax.mixthem.operation;

import innovimax.mixthem.io.Token;

import java.util.ArrayList;
import java.util.List;

/**
* <p>Describes the result of an operation on two or more files.</p>
* @author Innovimax
* @version 1.0
*/
public class TokenResult {
    
    private final int rangeSize;
    private final List<Boolean> lineReadingRange;
    private final List<String> readLineRange;
    private List<Token> result;
    
    /**
    * Creates a token result.    
    */
    public TokenResult(final int rangeSize) {        
        this.rangeSize = rangeSize;
        this.lineReadingRange = new ArrayList<Boolean>();
        this.readLineRange = new ArrayList<String>();
        for (int i=0; i < this.rangeSize; i++) {
            this.lineReadingRange.add(Boolean.TRUE);
            this.readLineRange.add(null);
        }
        this.result = null;
    }

    /**
    * Reset the result (but keep last read lines).
    */
    void reset() {
        this.result = null;
        for (int i=0; i < this.rangeSize; i++) {
            this.lineReadingRange.set(i, Boolean.TRUE);            
        }
    }
    
    /**
    * Set the result (maybe null).
    */
    void setResult(final List<Token> tokens) {
        this.result = tokens;
    }

    /**
    * Set the result (maybe null).
    */
    void setResult(final Token token) {
        this.result = new ArrayList<Token>();
        this.result.add(token);
    }

    /**
    * Returns the result (maybe null).
    */
    List<Token> getResult() {
        return this.result;
    }

    /**
    * Has a non null result ?
    */
    boolean hasResult() {
        return this.result != null;
    }

    /**
    * Get last read line at specified position from current range.
    */
    String getRangeLine(final int index) {
        return this.readLineRange.get(index);
    }

    /**
    * Set last read line at specified position in current range.
    */
    void setRangeLine(final int index, final String line) {
        this.readLineRange.set(index, line);
    }
    
    /**
    * Set if next line reading is necessary at specified position of the current range.
    */
    void setRangeLineReadingStatus(final int index, final boolean reading) {
        this.lineReadingRange.set(index, Boolean.valueOf(reading));
    }
   
    /**
    * Get next line reading range
    */
    List<Boolean> getLineReadingRange() {
        return this.lineReadingRange;
    }

}

@@ -326,21 +326,17 @@
 oolean%3E 
-lineR
+r
 eadingRa
@@ -367,24 +367,20 @@
 ist%3C
-String%3E readLine
+Token%3E token
 Rang
@@ -563,37 +563,33 @@
 e;%0A        this.
-lineR
+r
 eadingRange = ne
@@ -621,32 +621,29 @@
        this.
-readLine
+token
 Range = new 
@@ -652,22 +652,21 @@
 rayList%3C
-String
+Token
 %3E();%0A   
@@ -720,37 +720,33 @@
            this.
-lineR
+r
 eadingRange.add(
@@ -773,32 +773,29 @@
        this.
-readLine
+token
 Range.add(nu
@@ -1015,37 +1015,33 @@
            this.
-lineR
+r
 eadingRange.set(
@@ -1653,36 +1653,37 @@
 * Get last read 
-line
+token
  at specified po
@@ -1720,22 +1720,21 @@
  */%0A    
-String
+Token
  getRang
@@ -1730,28 +1730,29 @@
 ken getRange
-Line
+Token
 (final int i
@@ -1775,32 +1775,29 @@
 return this.
-readLine
+token
 Range.get(in
@@ -1906,20 +1906,21 @@
 setRange
-Line
+Token
 (final i
@@ -1939,19 +1939,19 @@
 nal 
-String line
+Token token
 ) %7B%0A
@@ -1967,16 +1967,13 @@
 his.
-readLine
+token
 Rang
@@ -1985,20 +1985,21 @@
 (index, 
-line
+token
 );%0A    %7D
@@ -2026,29 +2026,24 @@
 Set if next 
-line 
 reading is n
@@ -2123,25 +2123,15 @@
 ange
-Line
 Reading
-Status
 (fin
@@ -2178,29 +2178,25 @@
        this.
-lineR
+r
 eadingRange.
@@ -2266,21 +2266,16 @@
 et next 
-line 
 reading 
@@ -2312,12 +2312,8 @@
  get
-Line
 Read
@@ -2349,13 +2349,9 @@
 his.
-lineR
+r
 eadi

Update token result