package com.hubspot.jinjava.lib.exptest;

import java.util.Iterator;
import java.util.Objects;
import java.util.Optional;

import com.hubspot.jinjava.interpret.JinjavaInterpreter;
import com.hubspot.jinjava.util.ForLoop;
import com.hubspot.jinjava.util.ObjectIterator;

public class ContainsAllExpTest implements ExpTest {

  @Override
  public boolean evaluate(Object var, JinjavaInterpreter interpreter, Object... args) {

    if (null == var || args.length == 0) {
      return false;
    }

    ForLoop loop = ObjectIterator.getLoop(args[0]);
    while (loop.hasNext()) {
      Object matchValue = loop.next();
      ForLoop varLoop = ObjectIterator.getLoop(var);
      boolean matches = false;
      while (varLoop.hasNext()) {
        if (Objects.equals(matchValue, args[0])) {
          matches = true;
          break;
        }
      }
      if (!matches) {
        return false;
      }
    }

    return true;
  }

  private Optional<Iterator<?>> getIterator(Object var) {

    if (Iterator.class.isAssignableFrom(var.getClass())) {
      return Optional.of((Iterator<?>) var);
    }

    if (Iterable.class.isAssignableFrom(var.getClass())) {
      return Optional.of(((Iterable<?>) var).iterator());
    }

    return Optional.empty();
  }

  @Override
  public String getName() {
    return "containsall";
  }
}

@@ -56,69 +56,15 @@
 til.
-Iterator;%0Aimport java.util.Objects;%0Aimport java.util.Optional
+Objects
 ;%0A%0Ai
@@ -869,336 +869,8 @@
  %7D%0A%0A
-  private Optional%3CIterator%3C?%3E%3E getIterator(Object var) %7B%0A%0A    if (Iterator.class.isAssignableFrom(var.getClass())) %7B%0A      return Optional.of((Iterator%3C?%3E) var);%0A    %7D%0A%0A    if (Iterable.class.isAssignableFrom(var.getClass())) %7B%0A      return Optional.of(((Iterable%3C?%3E) var).iterator());%0A    %7D%0A%0A    return Optional.empty();%0A  %7D%0A%0A
   @O

Remove function.