/*
 * The Alluxio Open Foundation licenses this work under the Apache License, version 2.0
 * (the "License"). You may not use this work except in compliance with the License, which is
 * available at www.apache.org/licenses/LICENSE-2.0
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied, as more fully set forth in the License.
 *
 * See the NOTICE file distributed with this work for information regarding copyright ownership.
 */

package alluxio.underfs.options;

import alluxio.annotation.PublicApi;
import alluxio.retry.CountingRetry;
import alluxio.retry.RetryPolicy;

import com.google.common.base.Objects;

import javax.annotation.concurrent.NotThreadSafe;

/**
 * Method options for file locations in {@link alluxio.underfs.UnderFileSystem}.
 */
@PublicApi
@NotThreadSafe
public final class OpenOptions {
  private RetryPolicy mRetryPolicy;

  // Offset within file in bytes
  private long mOffset;

  private long mLength;

  /**
   * @return the default {@link OpenOptions}
   */
  public static OpenOptions defaults() {
    return new OpenOptions();
  }

  /**
   * Constructs a default {@link OpenOptions}.
   */
  private OpenOptions() {
    // Default to a single attempt
    mRetryPolicy = new CountingRetry(1);
    mOffset = 0;
    mLength = Long.MAX_VALUE;
  }

  /**
   * @return retry policy
   */
  public RetryPolicy getRetryPolicy() {
    return mRetryPolicy;
  }

  /**
   * @return offset from the start of a file in bytes
   */
  public long getOffset() {
    return mOffset;
  }

  /**
   * @return the maximum length of a file
   */
  public long getLength() {
    return mLength;
  }

  /**
   * Sets the retry policy in case of failures.
   *
   * @param retryPolicy the retry policy
   * @return the updated option object
   */
  public OpenOptions setRetryPolicy(RetryPolicy retryPolicy) {
    mRetryPolicy = retryPolicy;
    return this;
  }

  /**
   * Sets the offset from the start of a file to be opened for reading.
   *
   * @param offset within a file in bytes
   * @return the updated option object
   */
  public OpenOptions setOffset(long offset) {
    mOffset = offset;
    return this;
  }

  /**
   * @param length the maximum length of the file
   * @return the updated option object
   */
  public OpenOptions setLength(long length) {
    mLength = length;
    return this;
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (!(o instanceof OpenOptions)) {
      return false;
    }
    OpenOptions that = (OpenOptions) o;
    return Objects.equal(mOffset, that.mOffset) && Objects.equal(mLength, that.mLength);
  }

  @Override
  public int hashCode() {
    return Objects.hashCode(mOffset, mLength);
  }

  @Override
  public String toString() {
    return Objects.toStringHelper(this)
        .add("offset", mOffset)
        .add("length", mLength)
        .toString();
  }
}

@@ -581,78 +581,8 @@
 Api;
-%0Aimport alluxio.retry.CountingRetry;%0Aimport alluxio.retry.RetryPolicy;
 %0A%0Aim
@@ -822,45 +822,8 @@
 s %7B%0A
-  private RetryPolicy mRetryPolicy;%0A%0A
   //
@@ -1127,721 +1127,275 @@
     
-// Default to a single attempt%0A    mRetryPolicy = new CountingRetry(1);%0A    mOffset = 0;%0A    mLength = Long.MAX_VALUE;%0A  %7D%0A%0A  /**%0A   * @return retry policy%0A   */%0A  public RetryPolicy getRetryPolicy() %7B%0A    return mRetryPolicy;%0A  %7D%0A%0A  /**%0A   * @return offset from the start of a file in bytes%0A   */%0A  public long getOffset() %7B%0A    return mOffset;%0A  %7D%0A%0A  /**%0A   * @return the maximum length of a file%0A   */%0A  public long getLength() %7B%0A    return mLength;%0A  %7D%0A%0A  /**%0A   * Sets the retry policy in case of failures.%0A   *%0A   * @param retryPolicy the retry policy%0A   * @return the updated option object%0A   */%0A  public OpenOptions setRetryPolicy(RetryPolicy retryPolicy) %7B%0A    mRetryPolicy = retryPolicy;%0A    return this
+mOffset = 0;%0A    mLength = Long.MAX_VALUE;%0A  %7D%0A%0A  /**%0A   * @return offset from the start of a file in bytes%0A   */%0A  public long getOffset() %7B%0A    return mOffset;%0A  %7D%0A%0A  /**%0A   * @return the maximum length of a file%0A   */%0A  public long getLength() %7B%0A    return mLength
 ;%0A  

Revert "Add retry policy to open options"