diff --git a/src/es/markse/Contenedor.java b/src/es/markse/Contenedor.java index de637547daf6d6bde83ae9265de4852d35ea6c80..e0275ce6f1ff58072d96ce07c84d37eda706152d 100644 --- a/src/es/markse/Contenedor.java +++ b/src/es/markse/Contenedor.java @@ -246,10 +246,24 @@ public class Contenedor { /** * Metodo que sirve para anyadir un trayecto al contenedor - * @param t + * @param t El trayecto que se añade al contenedor + * @throws IllegalArgumentException si es trayecto es nulo, si la fecha fin del ultimo trayecto es superior + * a la de inicio del nuevo trayecto, o si el puerto/muelle destinos del ultimo trayecto no son los de origen + * del nuevo. */ public void anyadirTrayecto(Trayecto t) { - //COMPROBAR SI LA FECHA FIN DEL ANTERIOR ES ANTES QUE FECHA INICIO DEL SIGUIENTE - //LO MISMO CON EL MUELLE DESTINO Y MUELLE ORIGEN + if (t == null) throw new IllegalArgumentException("El trayecto no puede ser nulo"); + if (this.trayectos == null) this.trayectos.add(t); + else { + Trayecto ultimoT = this.trayectos.get(this.trayectos.size() -1); + if (ultimoT.getFechaFinTrayecto().getDiasDesdeEpoch() > t.getFechaInicioTrayecto().getDiasDesdeEpoch()) + throw new IllegalArgumentException("La fecha fin del ultimo trayecto no puede ser mayor la fecha de inicio del siguiente"); + if (!(ultimoT.getPuertoDestino().paisDelPuerto().equals(t.getPuertoOrigen().paisDelPuerto()) && + ultimoT.getPuertoDestino().ciudadDelPuerto().equals(t.getPuertoOrigen().ciudadDelPuerto()))) + throw new IllegalArgumentException("El puerto de origen debe ser el mismo que el de destino del ultimo trayecto"); + if(!ultimoT.getMuelleDestino().equals(t.getMuelleOrigen())) + throw new IllegalArgumentException("El Muelle de origen es distinto al muelle de destino del ultimo trayecto"); + this.trayectos.add(t); + } } } \ No newline at end of file diff --git a/src/es/markse/Puerto.java b/src/es/markse/Puerto.java index 24ac1a709410a5dbe0ebc66657076bf02947ed9c..369be2729ce3a071ac60f2cfa6f2030cc6266233 100644 --- a/src/es/markse/Puerto.java +++ b/src/es/markse/Puerto.java @@ -170,4 +170,12 @@ public class Puerto { public String ciudadDelPuerto() { return this.ciudad; } + + /** + * metodo que devuelve el identificador completo del puerto + * @return identificador del puerto completo + */ + public String identificadorPuerto() { + return this.paisDelPuerto()+"-"+this.ciudadDelPuerto(); + } } \ No newline at end of file diff --git a/uses/es/markse/ContenedorTest.java b/uses/es/markse/ContenedorTest.java index 000a1fba48b6da70a805fc45b1520632c4fd01cf..f99fe6aba2663820b132881422b6ca55b793a621 100644 --- a/uses/es/markse/ContenedorTest.java +++ b/uses/es/markse/ContenedorTest.java @@ -148,10 +148,26 @@ public class ContenedorTest { assertEquals(100*2.20462f, c.obtenerPesoLibras(), 0.001f); } - /* @Test public void testAnyadirTrayecto() { - fail("Not yet implemented"); // TODO + Contenedor c = new Contenedor("RTF", 'Z', "065432", 100, 400, 1000, false, true); + Puerto pOrig = new Puerto("ES" , "BAR"); + Puerto pDestino = new Puerto("IT" , "NAP"); + GPSCoordinate c1 = new GPSCoordinate(5d,5d); + GPSCoordinate c2 = new GPSCoordinate(10d,10d); + Muelle m1 = new Muelle("01", c1, true, 1, 1); + Muelle m2 = new Muelle("01", c2, true, 1, 1); + pOrig.anyadirMuelle(m1); + pDestino.anyadirMuelle(m2); + Fecha fInicio = new Fecha (25,11,2024); + Fecha fFin = new Fecha(30,11,2024); + Trayecto t = new Trayecto(m1,pOrig,fInicio,m2,pDestino,fFin); + c.anyadirTrayecto(t); + + Puerto pDestino2 = new Puerto("IT" , "NAP"); + GPSCoordinate c3 = new GPSCoordinate(11d,11d); + Muelle m3 = new Muelle("02", c3, true, 1, 1); + pDestino2.anyadirMuelle(m3); + } - */ }