package org.minimallycorrect.javatransformer.internal.util;

import java.util.function.*;
import java.util.stream.*;

public interface Splitter {
	Splitter commaSplitter = on(',');

	static Splitter on(char c) {
		return s -> CollectionUtil.stream(new Supplier<String>() {
			int base = -1;

			@Override
			public String get() {
				while (base != 0) {
					int base = this.base;
					if (base == -1)
						base = 0;

					int next = s.indexOf(c, base);

					int nextBase = next + 1;

					if (next == -1)
						next = s.length();

					String part = s.substring(base, next).trim();

					this.base = nextBase;

					if (!part.isEmpty())
						return part;
				}

				return null;
			}
		});
	}

	Stream<String> split(String s);

	default Iterable<String> splitIterable(String s) {
		return () -> split(s).iterator();
	}
}

@@ -789,14 +789,8 @@
 turn
- () -%3E
  spl
@@ -798,17 +798,18 @@
 t(s)
-.
+::
 iterator
 ();%0A
@@ -804,17 +804,15 @@
 iterator
-()
 ;%0A%09%7D%0A%7D%0A

Simplify Splitter.splitIterable to use method reference instead of lambda