package uk.terhoeven.news.tube.parser;

import com.google.common.base.Joiner;
import uk.terhoeven.news.tube.api.Disruption;
import uk.terhoeven.news.tube.api.LineStatus;
import uk.terhoeven.news.tube.api.StatusResponse;

import java.util.ArrayList;
import java.util.List;

public class NaturalTextParser
{
	public String parse(final LineStatus status)
	{
		final Disruption disruption = status.getDisruption();
		if (disruption == null)
		{
			return status.getSeverity() + " on the " + status.getLine().getName() + " line.";
		}
		else
		{
			return disruption.getCategory() + " disruption on the " + status.getLine().getName() + " line: " + disruption.getDescription();
		}
	}

	public String parse(final StatusResponse statusResponse)
	{
		final List<String> lineStatuses = new ArrayList<>();

		statusResponse.getStatuses().forEach(lineStatus ->
		{
			if (!lineStatus.getValidity().hasExpired())
			{
				lineStatuses.add(parse(lineStatus));
			}
		});

		return Joiner.on(System.lineSeparator()).join(lineStatuses);
	}
}

@@ -825,15 +825,28 @@
 s().
-forEach
+stream()%0A%09%09%09%09.filter
 (lin
@@ -859,20 +859,9 @@
 s -%3E
-%0A%09%09%7B%0A%09%09%09if (
+ 
 !lin
@@ -903,14 +903,32 @@
 %0A%09%09%09
-%7B%0A%09%09%09%09
+%09.forEach(lineStatus -%3E 
 line
@@ -962,18 +962,8 @@
 us))
-;%0A%09%09%09%7D%0A%09%09%7D
 );%0A%0A

replace if statement with filter lambda