<commit_before>package TerminalFahrplan;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.fusesource.jansi.Ansi;
import org.json.JSONArray;
import org.json.JSONException;

public class StationView extends Thread {

	private JSONArray stationboard;
	private boolean autoUpdate;

	final static int NUM_SHOW_ROWS = 20;
	final static SimpleDateFormat SDF = new SimpleDateFormat("YYYY-MM-dd'T'HH:mm:ssZZZZZ"); //Given from the API

	public StationView(JSONArray stationboard, boolean autoUpdate) {
		this.stationboard = stationboard;
		this.autoUpdate = autoUpdate;
	}

	@Override
	public void run() {
		do {
			try {
				Ansi ansi = Ansi.ansi();
				TerminalTable tt = new TerminalTable(new Row("Bezeichnung", "Von", "Nach", "Abfahrt", "Versp."));
				int numRows = NUM_SHOW_ROWS > stationboard.length() ? stationboard.length() : NUM_SHOW_ROWS;
				for (int i = 0; i < numRows; i++) {
					Row nextRow = new Row();
					//Bezeichnung
					nextRow.addData(new RowEntry(stationboard.getJSONObject(i).get("name")));
					//Von
					nextRow.addData(new RowEntry(stationboard.getJSONObject(i).getJSONObject("stop").getJSONObject("station").getString("name")));
					//Nach
					nextRow.addData(new RowEntry(stationboard.getJSONObject(i).get("to")));
					//Abfahrtszeit
					Date departure = dateFromString(stationboard.getJSONObject(i).getJSONObject("stop").get("departure").toString(), SDF);
					SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
					nextRow.addData(new RowEntry(sdf.format(departure)));
					//Verspätung
					String dateString = stationboard.getJSONObject(i).getJSONObject("stop").getJSONObject("prognosis").get("departure")
							.toString();
					if (dateString == "null")
						nextRow.addData(new RowEntry(""));
					else {
						long tooLateTimeInMillis = dateFromString(dateString, SDF).getTime() - departure.getTime();
						nextRow.addData(new RowEntry(tooLateTimeInMillis / 60000 + "'"));
						nextRow.setImportant(true);
					}
					//Next

					tt.addEntry(nextRow);
				}
				System.out.println(ansi.eraseScreen());
				tt.print();
				Thread.sleep(3000);
			} catch (JSONException e) {
				e.printStackTrace();
			} catch (InterruptedException e) {
				e.printStackTrace();
			} catch (RowException e) {
				e.printStackTrace();
			}
		} while (autoUpdate);
	}

	private Date dateFromString(String s, SimpleDateFormat df) {
		Date date = null;
		try {
			date = df.parse(s);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return date;
	}<commit_msg>Code optimitation for delay and general stationView<commit_after>package TerminalFahrplan;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.fusesource.jansi.Ansi;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class StationView extends Thread {

	private JSONArray stationboard;
	private boolean autoUpdate;

	final static int NUM_SHOW_ROWS = 20;
	final static SimpleDateFormat SDF = new SimpleDateFormat("YYYY-MM-dd'T'HH:mm:ssZZZZZ"); //Given from the API

	public StationView(JSONArray stationboard, boolean autoUpdate) {
		this.stationboard = stationboard;
		this.autoUpdate = autoUpdate;
	}

	@Override
	public void run() {
		do {
			try {
				Ansi ansi = Ansi.ansi();
				TerminalTable tt = new TerminalTable(new Row("Bezeichnung", "Von", "Nach", "Abfahrt", "Versp."));
				int numRows = NUM_SHOW_ROWS > stationboard.length() ? stationboard.length() : NUM_SHOW_ROWS;
				for (int i = 0; i < numRows; i++) {
					JSONObject current = stationboard.getJSONObject(i);
					
					Row nextRow = new Row();
					//Bezeichnung
					nextRow.addData(new RowEntry(current.get("name")));
					//Von
					nextRow.addData(new RowEntry(current.getJSONObject("stop").getJSONObject("station").getString("name")));
					//Nach
					nextRow.addData(new RowEntry(current.get("to")));
					//Abfahrtszeit
					Date departure = dateFromString(current.getJSONObject("stop").get("departure").toString(), SDF);
					SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
					nextRow.addData(new RowEntry(sdf.format(departure)));
					//Verspätung
					String delay = current.getJSONObject("stop").get("delay").toString();
					if (delay == "null")
						delay = "";
					else
						delay += "'";
					nextRow.addData(new RowEntry(delay));
					//Next

					tt.addEntry(nextRow);
				}
				System.out.println(ansi.eraseScreen());
				tt.print();
				Thread.sleep(3000);
			} catch (JSONException e) {
				e.printStackTrace();
			} catch (InterruptedException e) {
				e.printStackTrace();
			} catch (RowException e) {
				e.printStackTrace();
			}
		} while (autoUpdate);
	}

	private Date dateFromString(String s, SimpleDateFormat df) {
		Date date = null;
		try {
			date = df.parse(s);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return date;
	}
{'fraction_non_alphanumeric': 0.13620584031039412, 'fraction_numerical': 0.003879926485603431, 'mean_word_length': 3.8931068931068933, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '521583', 'n_tokens_mistral': 1903, 'n_tokens_neox': 1579, 'n_words': 325}