<commit_before>package dc.cli;

import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import cli.ArgSet;
import cli.CLC;
import cli.Debugger;
import dc.Connection;
import dc.DCStation;
import dc.KeyHandler;
import dc.testing.DummyConnection;

import java.util.Arrays;


public class MultiStationInterface extends CLC {
<<<<<<< Updated upstream
	private ArrayList<String> stations;
	private Action listAction, noSuchStationAction, connect, create;

	public MultiStationInterface() {
		stations = new ArrayList<String>();
=======
	private Map<String, StationInterface> clientMap, serverMap;
	private Action listAction, forwardAction, connect, create;

	public MultiStationInterface() {
		clientMap = new HashMap<String, StationInterface>();
		serverMap = new HashMap<String, StationInterface>();
>>>>>>> Stashed changes

		listAction = new Action() {
			@Override
			public void execute(ArgSet args) {
				System.out.println(stations);
			}
		};

		noSuchStationAction = new Action() {
			@Override
			public void execute(ArgSet args) {
				String s = args.pop();
				System.out.println("[MultiStationInterface] No command is associated with \"" + s + "\". If you want to create a station with that alias, use \"station make "+s+"\"");
			}
		};

		connect = new Action() {
			@Override
			public void execute(ArgSet args) {
				DCStation s1, s2;
				while(args.hasArg()) {
					s1 = getStation(args);
					s2 = getStation(args);
					if(s1 == null || s2 == null || s1 == s2) {
						System.err.println("[MultiStationInterface] Please provide two different stations");
					} else {
						byte[] key;
						if(args.hasAbbArg() && args.fetchAbbr().equals('k') || args.hasOptionArg() && args.fetchOption().equals("key")) {
							if(!args.hasStringArg()) {
								System.err.println("[StationInterface] No key has been provided although option \"key\" was set.");
								return;
							} else {
								key = args.fetchString().getBytes();
							}
						} else {
							key = new byte[KeyHandler.KEY_SIZE];
							for(int i = 0; i < KeyHandler.KEY_SIZE; i++) {
								key[i] = (byte) (Math.random()*Byte.MAX_VALUE);
							}
						}
						DummyConnection dc = new DummyConnection();
						Connection c1 = new Connection(dc.chA.getInputStream(), dc.chB.getOutputStream());
						Connection c2 = new Connection(dc.chB.getInputStream(), dc.chA.getOutputStream());
						s1.getCB().addConnection(c1, key);
						s2.getCB().addConnection(c2, key);
					}
				}
			}
		};

		create = new Action() {
			@Override
			public void execute(ArgSet args) {
				if(!args.hasArg()) {
					System.out.println("[MultiStationInterface] Please provide a valid command of the form \"(client|c|server|s) <alias>... \"");
				} else {
					String type = args.pop();
					if(type.equals("client") || type.equals("c")) {
						
					} else if(type.equals("server") || type.equals("s")) {
						
					}
				}
				while(args.hasArg()) {
<<<<<<< Updated upstream
					String alias = args.pop();
					if(stations.contains(alias)) {
						System.out.println("[MultiStationInterface] A station with alias " + alias + " already exists.");
					} else {
						stations.add(alias);
						setContext(alias, new StationInterface());
					}
=======

					createStation(args.pop());
>>>>>>> Stashed changes
				}
			}
		};<commit_msg>REBASED FOR COMMAND CONTEXT .. really!<commit_after>package dc.cli;

import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import cli.ArgSet;
import cli.CLC;
import cli.Debugger;
import dc.Connection;
import dc.DCStation;
import dc.KeyHandler;
import dc.testing.DummyConnection;

import java.util.Arrays;


public class MultiStationInterface extends CLC {
	private ArrayList<String> stations;
	private Action listAction, noSuchStationAction, connect, create;

	public MultiStationInterface() {
		stations = new ArrayList<String>();

		listAction = new Action() {
			@Override
			public void execute(ArgSet args) {
				System.out.println(stations);
			}
		};

		noSuchStationAction = new Action() {
			@Override
			public void execute(ArgSet args) {
				String s = args.pop();
				System.out.println("[MultiStationInterface] No command is associated with \"" + s + "\". If you want to create a station with that alias, use \"station make "+s+"\"");
			}
		};

		connect = new Action() {
			@Override
			public void execute(ArgSet args) {
				DCStation s1, s2;
				while(args.hasArg()) {
					s1 = getStation(args);
					s2 = getStation(args);
					if(s1 == null || s2 == null || s1 == s2) {
						System.err.println("[MultiStationInterface] Please provide two different stations");
					} else {
						byte[] key;
						if(args.hasAbbArg() && args.fetchAbbr().equals('k') || args.hasOptionArg() && args.fetchOption().equals("key")) {
							if(!args.hasStringArg()) {
								System.err.println("[StationInterface] No key has been provided although option \"key\" was set.");
								return;
							} else {
								key = args.fetchString().getBytes();
							}
						} else {
							key = new byte[KeyHandler.KEY_SIZE];
							for(int i = 0; i < KeyHandler.KEY_SIZE; i++) {
								key[i] = (byte) (Math.random()*Byte.MAX_VALUE);
							}
						}
						DummyConnection dc = new DummyConnection();
						Connection c1 = new Connection(dc.chA.getInputStream(), dc.chB.getOutputStream());
						Connection c2 = new Connection(dc.chB.getInputStream(), dc.chA.getOutputStream());
						s1.getCB().addConnection(c1, key);
						s2.getCB().addConnection(c2, key);
					}
				}
			}
		};

		create = new Action() {
			@Override
			public void execute(ArgSet args) {
				if(!args.hasArg()) {
					System.out.println("[MultiStationInterface] Please provide a valid command of the form \"(client|c|server|s) <alias>... \"");
				} else {
					String type = args.pop();
					if(type.equals("client") || type.equals("c")) {
						
					} else if(type.equals("server") || type.equals("s")) {
						
					}
				}
				while(args.hasArg()) {
					String alias = args.pop();
					if(stations.contains(alias)) {
						System.out.println("[MultiStationInterface] A station with alias " + alias + " already exists.");
					} else {
						stations.add(alias);
						setContext(alias, new StationInterface());
					}
				}
			}
		};
{'fraction_non_alphanumeric': 0.14658220388921625, 'fraction_numerical': 0.00441956393635828, 'mean_word_length': 3.2914032869785084, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 26, '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': '2217443', 'n_tokens_mistral': 2599, 'n_tokens_neox': 2058, 'n_words': 496}