Add condiment expiry functionality

This commit is contained in:
Trophonix
2017-06-21 08:58:25 -05:00
parent 03a616b83e
commit 5b6db03bbd
2 changed files with 20 additions and 2 deletions

View File

@@ -6,6 +6,7 @@ package org.drtshock;
public enum NotDeliciousReason {
NOT_BAKED,
NOT_DELICIOUS_CONDIMENT
NOT_DELICIOUS_CONDIMENT,
EXPIRED_CONDIMENT
}

View File

@@ -5,6 +5,7 @@ import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
/**
* A delicious tuber that is eaten by various peoples all over the world.
@@ -54,6 +55,7 @@ public class Potato implements Tuber {
for (String condimentName : names) {
Condiment condiment = new Condiment(condimentName, true);
if (!condiment.isDelicious()) throw new NotDeliciousException(NotDeliciousReason.NOT_DELICIOUS_CONDIMENT);
if (condiment.isExpired()) throw new NotDeliciousException(NotDeliciousReason.EXPIRED_CONDIMENT);
this.getCondiments().add(condiment);
}
}
@@ -158,10 +160,16 @@ public class Potato implements Tuber {
private class Condiment {
private final String name;
private final boolean delicious;
private final boolean expired;
public Condiment(String name, boolean delicious) {
public Condiment(String name, boolean delicious, boolean expired) {
this.name = name;
this.delicious = delicious;
this.expired = expired;
}
public Condiment(String name, boolean delicious) {
this(name, delicious, ThreadLocalRandom.current().nextInt(100) < 3);
}
/**
@@ -173,6 +181,15 @@ public class Potato implements Tuber {
return this.delicious;
}
/**
* Returns if this condiment is expired or not.
*
* @return true if expired, false if otherwise
*/
public boolean isExpired() {
return expired;
}
/**
* Gets the name of this condiment.
*