svephoto

PizzaCalories: class ValidatorUtil [Java]

Apr 10th, 2021 (edited)
561
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.01 KB | None | 0 0
  1. package pizzacalories;
  2.  
  3. import java.util.Arrays;
  4.  
  5. public class ValidatorUtil {
  6.     public static void validatePizzaName(String name) {
  7.         if (name == null || name.trim().isEmpty() || name.trim().length() < 1 || name.trim().length() > 15) {
  8.             throw new IllegalArgumentException("Pizza name should be between 1 and 15 symbols.");
  9.         }
  10.     }
  11.  
  12.     public static void validateNumberOfToppings(int numberOfToppings) {
  13.         if (numberOfToppings < 1 || numberOfToppings > 10) {
  14.             throw new IllegalArgumentException("Number of toppings should be in range [0..10].");
  15.         }
  16.     }
  17.  
  18.     public static void validateFlourType(String type) {
  19.         if (!"White".equalsIgnoreCase(type) && !"Wholegrain".equalsIgnoreCase(type)) {
  20.             throw new IllegalArgumentException("Invalid type of dough.");
  21.         }
  22.     }
  23.  
  24.     public static void validateDoughWeight(double weight) {
  25.         if (weight < 1 || weight > 200) {
  26.             throw new IllegalArgumentException("Dough weight should be in the range [1..200].");
  27.         }
  28.     }
  29.  
  30.     public static void validateBakingTechnique(String bakingTechnique) {
  31.         if (!"Crispy".equalsIgnoreCase(bakingTechnique) && !"Chewy".equalsIgnoreCase(bakingTechnique)
  32.                 && !"Homemade".equalsIgnoreCase(bakingTechnique)) {
  33.             throw new IllegalArgumentException("Invalid type of dough.");
  34.         }
  35.     }
  36.  
  37.     public static void validateToppingWeight(String toppingType, double weight) {
  38.         if (weight < 1 || weight > 50) {
  39.             throw new IllegalArgumentException(String.format("%s weight should be in the range [1..50].", toppingType));
  40.         }
  41.     }
  42.  
  43.     public static void validateToppingType(String toppingType) {
  44.         String[] listOfValidToppings = {"Meat", "Veggies", "Cheese", "Sauce"};
  45.         if (!Arrays.asList(listOfValidToppings).contains(toppingType)) {
  46.             throw new IllegalArgumentException(String.format("Cannot place %s on top of your pizza.", toppingType));
  47.         }
  48.     }
  49. }
  50.  
Add Comment
Please, Sign In to add comment