package au.com.southsky.jfreesane;

import com.google.common.base.MoreObjects;

/**
 * Represents the parameters returned by the SANE server when it is about to acquire a new frame.
 *
 * <p>
 * All parameter values are determined in advance of frame acquisition, with the exception of
 * {@code lineCount}. The value of this parameter may not be known in advance, for example when the
 * scanner is a hand scanner or supports page height detection. JFreeSane will populate this value
 * after frame acquisition.
 */
public class SaneParameters {
  private final FrameType frameType;
  private final boolean lastFrame;
  private final int bytesPerLine;
  private final int pixelsPerLine;
  private int lineCount;
  private final int depthPerPixel;

  SaneParameters(
      int frame, boolean lastFrame, int bytesPerLine, int pixelsPerLine, int lines, int depth) {
    this.frameType = SaneEnums.valueOf(FrameType.class, frame);
    this.lastFrame = lastFrame;
    this.bytesPerLine = bytesPerLine;
    this.pixelsPerLine = pixelsPerLine;
    this.lineCount = lines;
    this.depthPerPixel = depth;
  }

  /**
   * Returns the type of frame being acquired.
   */
  public FrameType getFrameType() {
    return frameType;
  }

  /**
   * Returns if no more frames are expected.
   */
  public boolean isLastFrame() {
    return lastFrame;
  }

  /**
   * Returns the number of bytes per scan line.
   */
  public int getBytesPerLine() {
    return bytesPerLine;
  }

  /**
   * Returns the number of pixels per scan line.
   */
  public int getPixelsPerLine() {
    return pixelsPerLine;
  }

  /**
   * Returns the number of scan lines, or {@code -1} if this cannot be determined in advance. Once
   * frame acquisition succeeds, this value will be populated with the observed line count.
   */
  public int getLineCount() {
    return lineCount;
  }

  void setLineCount(int lineCount) {
    this.lineCount = lineCount;
  }

  /**
   * Returns the number of bits used to indicate the color of each pixel.
   */
  public int getDepthPerPixel() {
    return depthPerPixel;
  }

  @Override
  public String toString() {
    return MoreObjects.toStringHelper(SaneParameters.class)
        .add("frameType", frameType)
        .add("isLastFrame", lastFrame)
        .add("bytesPerLine", bytesPerLine)
        .add("pixelsPerLine", pixelsPerLine)
        .add("lineCount", lineCount)
        .add("depthPerPixel", depthPerPixel)
        .toString();
  }
}

@@ -33,52 +33,8 @@
 e;%0A%0A
-import com.google.common.base.MoreObjects;%0A%0A
 /**%0A
@@ -2081,35 +2081,9 @@
 urn 
-MoreObjects.toStringHelper(
+%22
 Sane
@@ -2096,15 +2096,10 @@
 ters
-.class)
+%7B%22
 %0A   
@@ -2103,21 +2103,18 @@
         
-.add(
++ 
 %22frameTy
@@ -2115,18 +2115,28 @@
 rameType
-%22,
+=%22%0A        +
  frameTy
@@ -2137,17 +2137,16 @@
 rameType
-)
 %0A       
@@ -2150,27 +2150,34 @@
     
-.add(%22isLastFrame%22,
++ %22, lastFrame=%22%0A        +
  las
@@ -2182,17 +2182,16 @@
 astFrame
-)
 %0A       
@@ -2191,22 +2191,21 @@
         
-.add(%22
++ %22, 
 bytesPer
@@ -2208,18 +2208,28 @@
 sPerLine
-%22,
+=%22%0A        +
  bytesPe
@@ -2225,33 +2225,32 @@
   + bytesPerLine
-)
 %0A        .add(%22p
@@ -2242,22 +2242,21 @@
         
-.add(%22
++ %22, 
 pixelsPe
@@ -2260,18 +2260,28 @@
 sPerLine
-%22,
+=%22%0A        +
  pixelsP
@@ -2286,17 +2286,16 @@
 sPerLine
-)
 %0A       
@@ -2295,22 +2295,21 @@
         
-.add(%22
++ %22, 
 lineCoun
@@ -2309,18 +2309,28 @@
 ineCount
-%22,
+=%22%0A        +
  lineCou
@@ -2331,17 +2331,16 @@
 ineCount
-)
 %0A       
@@ -2344,14 +2344,13 @@
     
-.add(%22
++ %22, 
 dept
@@ -2358,18 +2358,28 @@
 PerPixel
-%22,
+=%22%0A        +
  depthPe
@@ -2384,17 +2384,16 @@
 PerPixel
-)
 %0A       
@@ -2397,19 +2397,13 @@
     
-.toString()
++ '%7D'
 ;%0A  

remove guava MoreObjects.toStringHelper from SaneParameters