package com.mikea.concrete;

import com.google.common.base.Preconditions;
import com.google.common.collect.Iterables;
import com.google.common.collect.Iterators;

import java.util.Iterator;

/**
 * Stack implementation that appends to other stacks together.
 *
 * Invariant: |left| > 0.
 */
class AppendedStack<T> implements PStack<T> {
  private final PStack<T> left;
  private final PStack<T> right;

  AppendedStack(PStack<T> left, PStack<T> right) {
    Preconditions.checkArgument(!left.isEmpty());
    this.left = left;
    this.right = right;
  }

  @Override
  public PStack<T> pushFront(T value) {
    return new AppendedStack<>(left.pushFront(value), right);
  }

  @Override
  public T peekFront() {
    return left.peekFront();
  }

  @Override
  public PStack<T> popFront() {
    PStack<T> newLeft = left.popFront();
    if (!newLeft.isEmpty()) {
      return new AppendedStack<>(newLeft, right);
    } else {
      return right;
    }
  }

  @Override
  public Iterator<T> iterator() {
    return Iterators.concat(left.iterator(), right.iterator());
  }

  @Override
  public boolean isEmpty() {
    return false;
  }

  @Override
  public int size() {
    return left.size() + right.size();
  }

  @Override
  public PStack<T> clear() {
    return left.clear();
  }

  @Override
  public String toString() {
    return Iterables.toString(this);
  }
}

@@ -26,53 +26,8 @@
 e;%0A%0A
-import com.google.common.base.Preconditions;%0A
 impo
@@ -410,36 +410,15 @@
     
-Preconditions.checkArgument(
+assert 
 !lef
@@ -428,17 +428,16 @@
 sEmpty()
-)
 ;%0A    th

using assert statement because of pitest