Maybe two classes RelativeTime and AbsoluteTime so your
problem could be one RelativeTime with 1 HOUR and one
AbsoluteTime with HOUR X (where X is now hour minus one).
Illustration:
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
public class TimeManipulation {
public static interface TimeUpdate {
public void applyTo(Calendar cal);
}
public static class AbsoluteTimeUpdate implements TimeUpdate {
private int value;
private int field;
public AbsoluteTimeUpdate(int value, int field) {
this.value = value;
this.field = field;
}
@Override
public void applyTo(Calendar cal) {
cal.set(field, value);
}
}
public static class RelativeTimeUpdate implements TimeUpdate {
private int value;
private int field;
public RelativeTimeUpdate(int value, int field) {
super();
this.value = value;
this.field = field;
}
@Override
public void applyTo(Calendar cal) {
cal.add(field, value);
}
}
private List<TimeUpdate> upds;
public TimeManipulation(TimeUpdate... upds) {
this.upds = new ArrayList<TimeUpdate>();
for(TimeUpdate upd : upds) this.upds.add(upd);
}
public void applyTo(Calendar cal) {
for(TimeUpdate upd : upds) {
upd.applyTo(cal);
}
}
public static void main(String[] args) {
TimeManipulation tm = new TimeManipulation(new RelativeTimeUpdate(1,
Calendar.DAY_OF_MONTH),
new RelativeTimeUpdate(-1,
Calendar.HOUR_OF_DAY));
Calendar cal = Calendar.getInstance();
System.out.println(cal.getTime());
tm.applyTo(cal);
System.out.println(cal.getTime());
}
}
Arne