Skip to content

Instantly share code, notes, and snippets.

@Jire
Created July 24, 2011 04:12
Show Gist options
  • Save Jire/1102232 to your computer and use it in GitHub Desktop.
Save Jire/1102232 to your computer and use it in GitHub Desktop.
A job which creates and displays a virtual cake.
package us.ironbase.job.examples;
import static java.lang.System.out;
import us.ironbase.job.Job;
/**
* A job which creates and displays a virtual cake.
*
* @author Thomas Nappo
*/
public class CakeJob implements Job {
/**
* A type of cake.
*
* @author Thomas Nappo
*/
public static enum CakeType {
/**
* A muffin cake. This type of cake refers to the
* American muffin, which is of a small-portioned
* size and generally lacks the sweetness offered
* by {@link CakeType#CUPCAKE}s.
*/
MUFFIN(1),
/**
* A wedding cake is the traditional cake served to
* the guests at a wedding reception after a wedding.
*
* <p>
* In modern Western culture, it is usually a large cake,
* multi-layered or tiered, and heavily decorated with
* icing, usually over a layer of marzipan or fondant.
* </p>
*/
WEDDING(5),
/**
* A small cake designed to serve one person, frequently
* baked in a small, thin paper or aluminum cup. As with
* larger cakes, frosting and other cake decorations,
* such as sprinkles, are common on cupcakes.
*/
CUPCAKE(2);
/**
* The amount of time (in seconds) a cake of the
* type takes to create.
*/
private final int timeToCreate;
/**
* Constructs a new cake type.
* @param timeToCreate The amount of time (in seconds)
* a cake of the type takes to create.
*/
CakeType(int timeToCreate) {
this.timeToCreate = timeToCreate;
}
}
/**
* The name of the cake.
*/
private final String cakeName;
/**
* The name of the baker who created the cake.
*/
private final String baker;
/**
* The type of cake the job will create.
*/
private final CakeType cakeType;
/**
* Constructs a new cake job.
* @param cakeName The name of the cake.
* @param baker The name of the baker who created the cake.
* @param cakeType The type of cake the job will create.
*/
public CakeJob(String cakeName, String baker, CakeType cakeType) {
this.cakeName = cakeName;
this.baker = baker;
this.cakeType = cakeType;
}
@Override
public void execute() {
try {
Thread.sleep(cakeType.timeToCreate * 1000);
out.println("Yes! It's time to eat that " + cakeType.name().toLowerCase() + " "
+ cakeName + " created by the wonderful baker " + baker + "!");
} catch (InterruptedException e) {
out.println("The cake job was interrupted!");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment