Created
February 11, 2017 13:00
-
-
Save tomkoptel/2be92c5eaa09f5ba98afa7e829a31128 to your computer and use it in GitHub Desktop.
Unit 3 - Demonstration of ADT
This file contains 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
class Job { | |
private final long interval; | |
private final String tag; | |
Job(Builder builder) { | |
this.interval = builder.interval; | |
this.tag = builder.tag; | |
} | |
@Retention(RetentionPolicy.SOURCE) | |
@interface Interval { | |
long WEEKLY = TimeUnit.DAYS.toMillis(7); | |
} | |
static class Builder { | |
private long interval; | |
private String tag; | |
public Builder repeat(long interval) { | |
this.interval = interval; | |
return this; | |
} | |
public Builder tag(String tag) { | |
this.tag = tag; | |
return this; | |
} | |
public Job build() { | |
return new Job(this); | |
} | |
} | |
} | |
abstract class Scheduler { | |
abstract long enqueue(Job job); | |
} | |
class PrepareJobAction { | |
private final Scheduler scheduler; | |
PrepareJobAction(Scheduler scheduler) { | |
this.scheduler = scheduler; | |
} | |
public int prepare() { | |
Job job = new Job.Builder() | |
.tag("By milk") | |
.repeat(Job.Interval.WEEKLY) | |
.build(); | |
long jobId = scheduler.enqueue(job); | |
return jobId; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment