/*
** Module   : RowExclusion.java
** Abstract : represent a portion line that is to be excluded from comparisons
**
** Copyright (c) 2009, Golden Code Development Corporation.
**
** -#- -I- --Date-- -----------------------Description------------------------
** 001 GES 20090218 Represent a portion of a line that is to be excluded from
**                  comparisons.
*/

/*
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU Affero General Public License as
** published by the Free Software Foundation, either version 3 of the
** License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License
** along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package com.goldencode.harness.test;

/**
 * Represent a portion of a line that is to be excluded from comparisons.
 */
public abstract class RowExclusion
extends ExclusionRegion
{
   /** Flag to control if a difference in the row's size should be ignored. */
   private boolean ignoreSize = false;
   
   /** Row index (0-based). */
   protected int row = -1;
   
   /**
    * Create an instance given explicit starting and ending indexes.
    *
    * @param    row
    *           The row number in which the exclusion should occur.
    * @param    start
    *           Starting index.
    * @param    end
    *           Ending index.
    */
   public RowExclusion(int row, int start, int end)
   {
      super(start, end);
      this.row = row;
   }
   
   /**
    * Get the row index.
    *
    * @return   The index.
    */
   public int getRow()
   {
      return row;
   }
   
   /**
    * Get the flag controlling if any size differences between the baseline
    * and the actual row should be ignored.
    *
    * @return   <code>true</code> to ignore size differences.
    */
   public boolean getIgnoreSize()
   {
      return ignoreSize;
   }
   
   /**
    * Set the flag controlling if any size differences between the baseline
    * and the actual row should be ignored.
    *
    * @param    ignoreSize
    *           <code>true</code> to ignore size differences.
    */
   public void setIgnoreSize(boolean ignoreSize)
   {
      this.ignoreSize = ignoreSize;
   }
   
   /**            
    * Report if the current line is the line that is referenced by this
    * exclusion region.
    * <p>
    * The row number must be matched based on the configuration and type of
    * this instance. All row number processing is 0-based.
    *
    * @param    absNum
    *           Absolute row number as calculated from the beginning of the
    *           file.
    * @param    relNum
    *           Relative row number as calculated from the beginning of the
    *           current page.
    * @param    pageNum
    *           Current page number (0-based).
    * @param    pageSz
    *           Size (in number of lines) of the current page.
    * @param    isLast   
    *           <code>true</code> if the current page is the last page in the
    *           file.
    *
    * @return   <code>true</code> if the given row is the same row as is
    *           excluded by this instance.
    */
   public abstract boolean isRow(int     absNum,
                                 int     relNum,
                                 int     pageNum,
                                 int     pageSz,
                                 boolean isLast);
   
   /**
    * Report if any size differences of the given line should be ignored.
    * <p>
    * The row number must be matched based on the configuration and type of
    * this instance. All row number processing is 0-based.
    *
    * @param    absNum
    *           Absolute row number as calculated from the beginning of the
    *           file.
    * @param    relNum
    *           Relative row number as calculated from the beginning of the
    *           current page.
    * @param    pageNum
    *           Current page number (0-based).
    * @param    pageSz
    *           Size (in number of lines) of the current page.
    * @param    isLast   
    *           <code>true</code> if the current page is the last page in the
    *           file.
    *
    * @return   <code>true</code> if the given row is the same row as is
    *           excluded by this instance and if any size differences should
    *           be ignored.
    */
   public boolean shouldIgnoreSize(int     absNum,
                                   int     relNum,
                                   int     pageNum,
                                   int     pageSz,
                                   boolean isLast)
   {
      return ignoreSize && isRow(absNum, relNum, pageNum, pageSz, isLast);
   }
   
   /**
    * Report if the given character index of the current line is contained in
    * the exclusion region.
    * <p>
    * The row number must be matched based on the configuration and type of
    * this instance. All row number processing is 0-based.
    * <p>
    * The specific starting and ending column indices are considered on an
    * inclusive basis. This means that if the given character index is equal to
    * either the starting or ending character index, it is considered
    * contained.
    *
    * @param    absNum
    *           Absolute row number as calculated from the beginning of the
    *           file.
    * @param    relNum
    *           Relative row number as calculated from the beginning of the
    *           current page.
    * @param    pageNum
    *           Current page number (0-based).
    * @param    pageSz
    *           Size (in number of lines) of the current page.
    * @param    isLast   
    *           <code>true</code> if the current page is the last page in the
    *           file.
    * @param    col
    *           The 0-based index position of the character being checked on
    *           the current line.
    *
    * @return   <code>true</code> if the given row is the same row as is
    *           excluded by this instance and if the given index is between the
    *           starting and ending indices or is equal to either index.
    */
   public boolean contains(int     absNum,
                           int     relNum,
                           int     pageNum,
                           int     pageSz,
                           boolean isLast,
                           int     col)
   {
      return (start <= col && end >= col) && 
             isRow(absNum, relNum, pageNum, pageSz, isLast);
   }
}
