//
// https://www.ramecera.it/myscrewdriver.html
// e-mail: screwdriver@ramecera.it
//
/* 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 it.ramecera.screwdriver;

import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;

import it.ramecera.salad.everyday.ExactException;

/**
 * <p>
 * The <b>tape</b> object indicates a line of the ele file, therefore of
 * input, consisting of a markup and all the material (called
 * substance), which is next to it; if there is no markup in the
 * immediately following lines, all these lines are an integral part of
 * the substance as if they were a single line.<br>
 * There are 9 public properties, of which the 2 most important are:
 * </p>
 * <ul>
 * <li>n: the markup, expressed with a number because it indicates the
 * position of the markup in the list of markups;</li>
 * <li>substance: it is an Object, because, depending on the content of
 * the row, it is immediately transformed into a Timestamp , String, or
 * Integer;</li>
 * </ul>
 * 
 * <p>
 * Company: Ramecera™<br>
 * Creation date: 2020-04-09<br>
 * Last updated: 2020-06-03<br>
 * </p>
 * <p>
 * Modifications:<br>
 * 2020-04-09: new method <b>corrections</b><br>
 * </p>
 * 
 * @author M. Maglioni */

final public class Train {

	// PUBLIC PROPERTIES

	/** the first segment that makes up the train */
	public Wagon locomotor;

	/** the list of subsequent segments that make up the train */
	public Map<String, Wagon> wagonE = new HashMap<String, Wagon>();

	// CONSTANT

	/** ordinary logger */
	@SuppressWarnings("unused")
	private static final Logger logger = Logger.getLogger(Train.class);

	// constructorS

	/** default constructor */
	public Train() {
	}

	/**
	 * <p>
	 * Useful constructor
	 * </p>
	 * <p>
	 * Creation date: 2020-04-09<br>
	 * Last updated: 2020-04-09<br>
	 * </p>
	 * 
	 * @param v wagon that makes up the fettuccia
	 * @param rigaJ the line of the file affected by the exception
	 * @throws ExactException standard exception */
	public Train(Wagon v, final int rigaJ) throws ExactException {
		ExactException ne = new ExactException();
		if (wagonE.put(v.stub, v) != null) {
			ne.datum = "Too much times I have declared the markup «"
					+ v.stub + "» following a «" + locomotor.stub
					+ "».";
			ne.code = 2200;
			ne.n = rigaJ;
			ne.className = this.getClass().getName();
			throw ne;
		}
	}
}
