/*
 * Copyright 2015 the original author or authors.
 *
 * All rights reserved. This program and the accompanying materials are
 * made available under the terms of the Eclipse Public License v1.0 which
 * accompanies this distribution and is available at
 *
 * http://www.eclipse.org/legal/epl-v10.html
 */

package org.junit.gen5.launcher;

import static java.util.Arrays.*;
import static java.util.Collections.*;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;

import org.junit.gen5.engine.TestDescriptor;
import org.junit.gen5.engine.TestEngine;

/**
 * @since 5.0
 */
final class TestPlan {

	private static enum State {
		NEW, ACTIVE, PAUSED, STOPPED, COMPLETED;
	}


	/**
	 * List of all TestDescriptors, including children.
	 */
	private final Collection<TestDescriptor> testDescriptors = new LinkedList<>();

	private State state = State.NEW;


	TestPlan() {
		/* no-op */
	}

	public boolean isActive() {
		return this.state == State.ACTIVE;
	}

	public boolean isPaused() {
		return this.state == State.PAUSED;
	}

	public boolean isStopped() {
		return this.state == State.STOPPED;
	}

	public boolean isCompleted() {
		return this.state == State.COMPLETED;
	}

	public void addTest(TestDescriptor testDescriptor) {
		addTests(singleton(testDescriptor));
	}

	public void addTests(TestDescriptor... testDescriptors) {
		addTests(asList(testDescriptors));
	}

	public void addTests(Collection<TestDescriptor> testDescriptors) {
		this.testDescriptors.addAll(testDescriptors);
	}

	public Collection<TestDescriptor> getTests() {
		return Collections.unmodifiableCollection(testDescriptors);
	}

	public List<TestDescriptor> getAllTestsForTestEngine(TestEngine testEngine) {
		return this.testDescriptors.stream().filter(testEngine::supports).collect(Collectors.toList());
	}

	public void start() {
		System.out.println("Starting test plan");
		this.state = State.ACTIVE;
	}

	public void stop() {
		System.out.println("Stopping test plan");
		this.state = State.STOPPED;
	}

	public void pause() {
		System.out.println("Pausing test plan");
		this.state = State.PAUSED;
	}

	public void restart() {
		System.out.println("Restarting test plan");
		this.state = State.ACTIVE;
	}

}

@@ -367,17 +367,22 @@
 .Arrays.
-*
+asList
 ;%0Aimport
@@ -411,17 +411,25 @@
 ections.
-*
+singleton
 ;%0A%0Aimpor
@@ -708,85 +708,8 @@
  %7B%0A%0A
-%09private static enum State %7B%0A%09%09NEW, ACTIVE, PAUSED, STOPPED, COMPLETED;%0A%09%7D%0A%0A%0A
 %09/**
@@ -852,359 +852,36 @@
 );%0A%0A
-%09private State state = State.NEW;%0A%0A%0A%09TestPlan() %7B%0A%09%09/* no-op */%0A%09%7D%0A%0A%09public boolean isActive() %7B%0A%09%09return this.state == State.ACTIVE;%0A%09%7D%0A%0A%09public boolean isPaused() %7B%0A%09%09return this.state == State.PAUSED;%0A%09%7D%0A%0A%09public boolean isStopped() %7B%0A%09%09return this.state == State.STOPPED;%0A%09%7D%0A%0A%09public boolean isCompleted() %7B%0A%09%09return this.state == State.COMPLETED;
+%0A%09TestPlan() %7B%0A%09%09/* no-op */
 %0A%09%7D%0A
@@ -1497,409 +1497,6 @@
 %09%7D%0A%0A
-%09public void start() %7B%0A%09%09System.out.println(%22Starting test plan%22);%0A%09%09this.state = State.ACTIVE;%0A%09%7D%0A%0A%09public void stop() %7B%0A%09%09System.out.println(%22Stopping test plan%22);%0A%09%09this.state = State.STOPPED;%0A%09%7D%0A%0A%09public void pause() %7B%0A%09%09System.out.println(%22Pausing test plan%22);%0A%09%09this.state = State.PAUSED;%0A%09%7D%0A%0A%09public void restart() %7B%0A%09%09System.out.println(%22Restarting test plan%22);%0A%09%09this.state = State.ACTIVE;%0A%09%7D%0A%0A
 %7D%0A

Remove state in TestPlan for now