// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static int checkElementIndex(int index, int size) {
//   return checkElementIndex(index, size, "index");
// }
// 
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static <T> T checkNotNull(T reference) {
//   if (reference == null) {
//     throw new NullPointerException();
//   }
//   return reference;
// }
// 
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static int checkPositionIndex(int index, int size) {
//   return checkPositionIndex(index, size, "index");
// }
// 
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static void checkPositionIndexes(int start, int end, int size) {
//   // Carefully optimized for execution by hotspot (explanatory comment above)
//   if (start < 0 || end < start || end > size) {
//     throw new IndexOutOfBoundsException(badPositionIndexes(start, end, size));
//   }
// }
// 
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static void checkState(boolean expression) {
//   if (!expression) {
//     throw new IllegalStateException();
//   }
// }


import java.util.AbstractList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.NoSuchElementException;
import org.jetbrains.annotations.Nullable;
import static com.fernandocejas.arrow.checks.Preconditions.checkElementIndex;
import static com.fernandocejas.arrow.checks.Preconditions.checkNotNull;
import static com.fernandocejas.arrow.checks.Preconditions.checkPositionIndex;
import static com.fernandocejas.arrow.checks.Preconditions.checkPositionIndexes;
import static com.fernandocejas.arrow.checks.Preconditions.checkState;
/**
 * Copyright (C) 2007 The Guava Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.fernandocejas.arrow.collections;



class ReverseList<T> extends AbstractList<T> {
  private final List<T> forwardList;

  ReverseList(List<T> forwardList) {
    this.forwardList = checkNotNull(forwardList);
  }

  List<T> getForwardList() {
    return forwardList;
  }

  private int reverseIndex(int index) {
    int size = size();
    checkElementIndex(index, size);
    return size - 1 - index;
  }

  private int reversePosition(int index) {
    int size = size();
    checkPositionIndex(index, size);
    return size - index;
  }

  @Override
  public void add(int index, @Nullable T element) {
    forwardList.add(reversePosition(index), element);
  }

// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static int checkElementIndex(int index, int size) {
//   return checkElementIndex(index, size, "index");
// }
// 
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static <T> T checkNotNull(T reference) {
//   if (reference == null) {
//     throw new NullPointerException();
//   }
//   return reference;
// }
// 
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static int checkPositionIndex(int index, int size) {
//   return checkPositionIndex(index, size, "index");
// }
// 
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static void checkPositionIndexes(int start, int end, int size) {
//   // Carefully optimized for execution by hotspot (explanatory comment above)
//   if (start < 0 || end < start || end > size) {
//     throw new IndexOutOfBoundsException(badPositionIndexes(start, end, size));
//   }
// }
// 
// Path: src/main/java/com/fernandocejas/arrow/checks/Preconditions.java
// public static void checkState(boolean expression) {
//   if (!expression) {
//     throw new IllegalStateException();
//   }
// }


// Path: src/main/java/com/fernandocejas/arrow/collections/ReverseList.java
import java.util.AbstractList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.NoSuchElementException;
import org.jetbrains.annotations.Nullable;
import static com.fernandocejas.arrow.checks.Preconditions.checkElementIndex;
import static com.fernandocejas.arrow.checks.Preconditions.checkNotNull;
import static com.fernandocejas.arrow.checks.Preconditions.checkPositionIndex;
import static com.fernandocejas.arrow.checks.Preconditions.checkPositionIndexes;
import static com.fernandocejas.arrow.checks.Preconditions.checkState;

/**
 * Copyright (C) 2007 The Guava Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.fernandocejas.arrow.collections;



class ReverseList<T> extends AbstractList<T> {
  private final List<T> forwardList;

  ReverseList(List<T> forwardList) {
    this.forwardList = checkNotNull(forwardList);
  }

  List<T> getForwardList() {
    return forwardList;
  }

  private int reverseIndex(int index) {
    int size = size();
    checkElementIndex(index, size);
    return size - 1 - index;
  }

  private int reversePosition(int index) {
    int size = size();
    checkPositionIndex(index, size);
    return size - index;
  }

  @Override
  public void add(int index, @Nullable T element) {
    forwardList.add(reversePosition(index), element);
  }

  @Override