Skip to content

Instantly share code, notes, and snippets.

@qmx
Forked from sergiolopes/Periodo.java
Created May 14, 2010 20:37
Show Gist options
  • Save qmx/401634 to your computer and use it in GitHub Desktop.
Save qmx/401634 to your computer and use it in GitHub Desktop.
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