-
-
Save qmx/401634 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Calendar; | |
public final class Periodo { | |
private final Calendar inicio; | |
private final Calendar fim; | |
public Periodo(Calendar inicio, Calendar fim) { | |
this((Calendar) inicio.clone(), (Calendar) fim.clone(), false); | |
} | |
private Periodo(Calendar inicio, Calendar fim, boolean nada) { | |
this.inicio = inicio; | |
this.fim = fim; | |
} | |
public Calendar getInicio() { | |
// copia defensiva | |
return (Calendar) inicio.clone(); | |
} | |
public Calendar getFim() { | |
// copia defensiva | |
return (Calendar) fim.clone(); | |
} | |
public Periodo adiaUmaSemana() { | |
Calendar novoFim = (Calendar) this.fim.clone(); | |
novoFim.add(Calendar.DAY_OF_MONTH, 7); | |
return new Periodo(this.inicio, novoFim, true); // flyweight | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment