From 9c36681d1dc947c29d4a1b5a3d12dea08d9129c8 Mon Sep 17 00:00:00 2001
From: Victor Martinez Rodriguez
 <victor.martinez.rodriguez22@estudiantes.uva.es>
Date: Fri, 20 Dec 2024 20:55:13 +0100
Subject: [PATCH] Tipos de Contenedores y Contenedor

---
 src/es/markse/Contenedor.java      | 42 +++++++++++++++---------------
 src/es/markse/Estandar.java        | 14 ++++++++++
 src/es/markse/FlatRack.java        | 24 ++++++++++++++++-
 src/es/markse/Refrigerado.java     | 29 +++++++++++++++++++--
 uses/es/markse/ContenedorTest.java |  2 +-
 5 files changed, 86 insertions(+), 25 deletions(-)

diff --git a/src/es/markse/Contenedor.java b/src/es/markse/Contenedor.java
index bf92b05..0b89465 100644
--- a/src/es/markse/Contenedor.java
+++ b/src/es/markse/Contenedor.java
@@ -11,7 +11,7 @@ import java.util.List;
  * @author victorm 
  */
 public abstract class Contenedor {
-	private final List<Trayecto> trayectos = new ArrayList<>();
+	protected final List<Trayecto> trayectos = new ArrayList<>();
 	
 	private ISO6346 codigo;
 	private float pesoTara;
@@ -117,12 +117,12 @@ public abstract class Contenedor {
 	 * @param costePorMilla El coste por milla recorrida en un trayecto
 	 * @return el precio total del transporte del contenedor
 	 */
-	public double precioTransporteTotalContenedor(double costeDiarioTrayecto, double costePorMilla) {
+	public double precioTransporteTotalContenedor() {
 		if (this.trayectos.isEmpty())
 			return 0.0;
 		double precioTotal = 0.0;
 		for (Trayecto t : this.trayectos) {
-			precioTotal += t.precioTrayectoEnEuros(costeDiarioTrayecto, costePorMilla);
+			precioTotal += t.precioTrayectoEnEuros();
 		}
 		return precioTotal;
 	}
@@ -138,26 +138,26 @@ public abstract class Contenedor {
 	 * @throws IllegalStateException si la fecha fin del ultimo trayecto es superior a la de inicio del nuevo trayecto
 	 * @throws IllegalStateException si el puerto/muelle destinos del ultimo trayecto no son los de origen del nuevo.
 	 */
-	public void anyadirTrayecto(Trayecto t) {
-		if (t == null) 
-			throw new IllegalArgumentException("El trayecto no puede ser nulo");
-		if (this.trayectos.isEmpty()) 
-			this.trayectos.add(t);
-		else {
-			Trayecto ultimoT = this.trayectos.get(this.trayectos.size() -1);
-			//Si la fecha fin es mayor a la de inicio del nuevo
-			if (ultimoT.getFechaFinTrayecto().getDiasDesdeEpoch() > t.getFechaInicioTrayecto().getDiasDesdeEpoch())
-				throw new IllegalStateException("La fecha fin del ultimo trayecto no puede ser mayor la fecha de inicio del siguiente");
-			//Si el puerto destino no es el origen del nuevo
-			if (!ultimoT.getPuertoDestino().identificadorPuerto().equals(t.getPuertoOrigen().identificadorPuerto()))
-				throw new IllegalStateException("El puerto de origen debe ser el mismo que el de destino del ultimo trayecto");
-			//Si el muelle de destino no es el de origen del nuevo
-			if (!ultimoT.getMuelleDestino().getIdentificador().equals(t.getMuelleOrigen().getIdentificador()))
-				throw new IllegalStateException("El Muelle de origen debe de ser igual al de destino de su ultimo trayecto");
-			this.trayectos.add(t);
-		}
+	public abstract void anyadirTrayecto(Trayecto t);
+
+	
+	
+	
+	protected void comprobarDatosContenedor(Trayecto t) {
+		Trayecto ultimoT = this.trayectos.get(this.trayectos.size() -1);
+		//Si la fecha fin es mayor a la de inicio del nuevo
+		if (ultimoT.getFechaFinTrayecto().getDiasDesdeEpoch() > t.getFechaInicioTrayecto().getDiasDesdeEpoch())
+			throw new IllegalStateException("La fecha fin del ultimo trayecto no puede ser mayor la fecha de inicio del siguiente");
+		//Si el puerto destino no es el origen del nuevo
+		if (!ultimoT.getPuertoDestino().identificadorPuerto().equals(t.getPuertoOrigen().identificadorPuerto()))
+			throw new IllegalStateException("El puerto de origen debe ser el mismo que el de destino del ultimo trayecto");
+		//Si el muelle de destino no es el de origen del nuevo
+		if (!ultimoT.getMuelleDestino().getIdentificador().equals(t.getMuelleOrigen().getIdentificador()))
+			throw new IllegalStateException("El Muelle de origen debe de ser igual al de destino de su ultimo trayecto");
+		this.trayectos.add(t);	
 	}
 	
+	
 	/**
 	 * Metodo que devuelve si un contenedor tiene techo
 	 * @return si tiene techo (true) o si no lo tiene (false)
diff --git a/src/es/markse/Estandar.java b/src/es/markse/Estandar.java
index eaaa93d..f63909c 100644
--- a/src/es/markse/Estandar.java
+++ b/src/es/markse/Estandar.java
@@ -6,5 +6,19 @@ public class Estandar extends Contenedor {
 			pesos pesoSeleccionado, volumenes volumenSeleccionado, boolean techo) {
 		super(codigo, pesoTara, maximaCargaUtil, volumen, estadoActual, pesoSeleccionado, volumenSeleccionado, techo);	
 	}
+	@Override
+	public void anyadirTrayecto(Trayecto t) {
+		if (t==null) {
+			throw new IllegalArgumentException("h");
+		}
+		if (this.trayectos.isEmpty()) {
+			this.anyadirTrayecto(t);
+		}
+		else {
+			comprobarDatosContenedor(t);
+		}
 	
+	}
+	
+
 }
diff --git a/src/es/markse/FlatRack.java b/src/es/markse/FlatRack.java
index 56ceaf8..b854019 100644
--- a/src/es/markse/FlatRack.java
+++ b/src/es/markse/FlatRack.java
@@ -5,7 +5,29 @@ public class FlatRack extends Contenedor{
 	public FlatRack(ISO6346 codigo, float pesoTara, float maximaCargaUtil, float volumen, estados estadoActual,
 			pesos pesoSeleccionado, volumenes volumenSeleccionado, boolean techo) {
 		super(codigo, pesoTara, maximaCargaUtil, volumen, estadoActual, pesoSeleccionado, volumenSeleccionado, techo);
-		// TODO Auto-generated constructor stub
+		
 	}
 
+	@Override
+	public void anyadirTrayecto(Trayecto t) {
+		if (t==null) {
+			throw new IllegalArgumentException("h");
+		}
+	
+		if (t instanceof TCamion) {
+			throw new IllegalArgumentException("No");
+		}
+	
+		if (t instanceof TPackCamionBarco) {
+			throw new IllegalArgumentException("No");
+		}
+		
+		if (t instanceof TPackCamionTren) {
+			throw new IllegalArgumentException("No");
+		}
+		
+		comprobarDatosContenedor(t);
+	}
+		
+
 }
diff --git a/src/es/markse/Refrigerado.java b/src/es/markse/Refrigerado.java
index 4eaa62b..fbf514e 100644
--- a/src/es/markse/Refrigerado.java
+++ b/src/es/markse/Refrigerado.java
@@ -5,7 +5,32 @@ public class Refrigerado extends Contenedor{
 	public Refrigerado(ISO6346 codigo, float pesoTara, float maximaCargaUtil, float volumen, estados estadoActual,
 			pesos pesoSeleccionado, volumenes volumenSeleccionado, boolean techo) {
 		super(codigo, pesoTara, maximaCargaUtil, volumen, estadoActual, pesoSeleccionado, volumenSeleccionado, techo);
-		
 	}
 
-}
+	@Override
+	public void anyadirTrayecto(Trayecto t) {
+		if (t==null) {
+			throw new IllegalArgumentException("h");
+		}
+		
+		if (t instanceof TTren) {
+			throw new IllegalArgumentException("No");
+		}
+		
+		if (t instanceof TPackCamionBarco) {
+			throw new IllegalArgumentException("No");
+		}
+	
+		if (t instanceof TPackCamionTren) {
+			throw new IllegalArgumentException("No");
+		}
+		comprobarDatosContenedor(t);
+		
+		
+	}
+	
+	
+	
+	
+	
+}
\ No newline at end of file
diff --git a/uses/es/markse/ContenedorTest.java b/uses/es/markse/ContenedorTest.java
index 573f76f..f892997 100644
--- a/uses/es/markse/ContenedorTest.java
+++ b/uses/es/markse/ContenedorTest.java
@@ -21,7 +21,7 @@ public class ContenedorTest {
 	@Test
 	public void testContenedor() {
 		ISO6346 i1 = new ISO6346("ZRE", 'J', 56731);
-		Contenedor c1 = new Contenedor(i1, 100, 400, 500, estados.REGOGIDA, pesos.KILOS, volumenes.METROS, true);
+		Contenedor c1 = new Estandar(i1, 100, 400, 500, estados.REGOGIDA, pesos.KILOS, volumenes.METROS, true);
 		assertEquals("ZREJ0567310", c1.getCodigo());
 		assertEquals(100.0f, c1.obtenerPesoKilos(), 0.001f);
 		assertEquals(400.0f, c1.cargaUtilContenedorKilos(), 0.001f);
-- 
GitLab