Beispiel #1
0
  @Test
  public void testBasic() {
    System.out.println(Year.now());
    System.out.println(Year.of(2015));
    System.out.println(Year.isLeap(2016));

    Locale locale = Locale.getDefault();
    System.out.println(Month.DECEMBER.getDisplayName(TextStyle.FULL, locale));
    System.out.println(Month.DECEMBER.getDisplayName(TextStyle.SHORT, locale));
    System.out.println(Month.DECEMBER.getDisplayName(TextStyle.NARROW, locale));
    System.out.println(Month.DECEMBER.getDisplayName(TextStyle.FULL_STANDALONE, locale));
    System.out.println(Month.of(8).ordinal());
    System.out.println(Month.AUGUST.minus(2));

    System.out.println(YearMonth.now());
    System.out.println(MonthDay.now());

    System.out.println(DayOfWeek.FRIDAY.plus(2));
    System.out.println(DayOfWeek.of(1));
    System.out.println(
        DayOfWeek.from(LocalDateTime.ofInstant(Instant.now(), ZoneId.systemDefault())));

    System.out.println(Period.between(Year.now().atDay(1), LocalDate.now()));
    System.out.println(ChronoUnit.DAYS.between(Year.now().atDay(1), LocalDate.now()));
  }
Beispiel #2
0
 public static boolean getGrantAccess() {
   final User user = Authenticate.getUser();
   if (user != null) {
     final int year = Year.now().getValue();
     final CgdCard card = findCardFor(user, year, false);
     return card != null && card.getAllowSendDetails();
   }
   return false;
 }
Beispiel #3
0
 @Atomic
 public static CgdCard setGrantAccess(final boolean allowAccess) {
   final User user = Authenticate.getUser();
   if (user != null) {
     final int year = Year.now().getValue();
     final CgdCard card = findCardFor(user, year, allowAccess);
     if (card != null) {
       card.setAllowSendDetails(allowAccess);
       if (allowAccess) {
         return card;
       }
     }
   }
   return null;
 }
  @Override
  public List<FoodViolationSummary> getEstablishmentWithAtLeastNViolations(int n) {

    LocalDateTime currentYear = Year.now().atDay(1).atTime(0, 0);
    long currentYearMilli = currentYear.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
    Date currentYearMidnight = new java.sql.Date(currentYearMilli);

    Object[] queryParams = new Object[] {currentYearMidnight, n};
    List<FoodViolationSummary> summaries;

    try {
      summaries =
          jdbcTemplate.query(countViolationSql, queryParams, new FoodViolationSummaryRowMapper());
    } catch (EmptyResultDataAccessException e) {
      summaries = new ArrayList<FoodViolationSummary>(0);
    }

    // TODO Auto-generated method stub
    return summaries;
  }
Beispiel #5
0
 public static boolean hasCGDAccessResponse() {
   final User user = Authenticate.getUser();
   final int year = Year.now().getValue();
   return user != null
       && user.getCgdCardSet().stream().anyMatch(c -> c.getCgdCardCounter().getYear() == year);
 }
public class CalculationServiceImpl implements CalculationService {
  private static final Logger logger = LoggerFactory.getLogger(CalculationServiceImpl.class);
  private Bill bill = new Bill();
  private LocalDate hollidayChristmas = Year.now().atMonth(Month.JANUARY).atDay(7);
  private LocalDate hollidayIndepenanceDay = Year.now().atMonth(Month.AUGUST).atDay(24);
  private LocalDate hollidayProgrammerDay = Year.now().atDay(256);
  private Locale locale;
  private ResourceBundle resourceBundle;

  private void setDiscount(boolean discount, Data data) {
    double totalPrice = bill.getTotalPrice();
    LocalDate date = data.getDate();
    if ((date.equals(hollidayChristmas))
        || (date.equals(hollidayIndepenanceDay))
        || (date.equals(hollidayProgrammerDay))) {
      totalPrice *= 0.5;
      bill.setTotalPrice(totalPrice);
      discount = false;
      logger.info(resourceBundle.getString("economyHollidays") + bill.getTotalPrice());
      bill.setHollidays(
          resourceBundle.getString("economyHollidays")
              + String.format(" %.2f ", bill.getTotalPrice()));
    } else {
      logger.info(resourceBundle.getString("noEconomy"));
      bill.setHollidays(resourceBundle.getString("noEconomy"));
    }

    if (discount == true) {
      double discountPay = bill.getTotalPrice() * 0.1;
      totalPrice *= 0.9;
      bill.setTotalPrice(totalPrice);
      logger.info(resourceBundle.getString("yourDiscount") + discountPay);
      bill.setDiscount(
          resourceBundle.getString("yourDiscount") + " " + String.format(" %.2f ", discountPay));
    } else if (discount == false) {
      totalPrice *= 1;
      bill.setTotalPrice(totalPrice);
      logger.info(resourceBundle.getString("noDiscount"));
      bill.setDiscount(resourceBundle.getString("noDiscount"));
    }
  }

  private void check(Data data) {
    LocalDate date = data.getDate();
    double price = bill.getTotalPrice();
    if (date.getYear() > 2015
        && date.getMonth().equals(Month.SEPTEMBER)
        && date.getDayOfMonth() < 8
        && date.getDayOfWeek().equals(DayOfWeek.SATURDAY)) {
      price *= 1;
      bill.setTotalPrice(price);
      logger.info(resourceBundle.getString("noTips"));
      bill.setTips(resourceBundle.getString("noTips"));
    } else {
      double tips = 0.05 * bill.getTotalPrice();
      price *= 1.05;
      bill.setTotalPrice(price);
      logger.info(resourceBundle.getString("payForTips") + tips);
      bill.setTips(resourceBundle.getString("payForTips") + " " + String.format(" %.2f ", tips));
    }
  }

  private void weekends(Data data) {
    LocalDate date = data.getDate();
    double price = bill.getTotalPrice();
    if (date.getDayOfWeek().equals(DayOfWeek.FRIDAY)
        || date.getDayOfWeek().equals(DayOfWeek.SATURDAY)
        || date.getDayOfWeek().equals(DayOfWeek.SUNDAY)) {
      double weekendsPay = 0.05 * bill.getTotalPrice();
      price *= 1.05;
      bill.setTotalPrice(price);
      logger.info(resourceBundle.getString("payForWeekends") + weekendsPay);
      bill.setWeekends(
          resourceBundle.getString("payForWeekends") + " " + String.format(" %.2f", weekendsPay));
    }
  }

  private void storeInfo(Data data) {
    locale = data.getLocale();
    resourceBundle = ResourceBundle.getBundle("Bundle", locale);
    pizzaCost(data);
    drinksCost(data);
    bill.setTotalPrice(bill.getDrinksPrice() + bill.getPizzaPrice());
    if (bill.getTotalPrice() == 0) {
      logger.error(
          resourceBundle.getString("orderFor")
              + bill.getTotalPrice()
              + resourceBundle.getString("thankYouForVisit"));
      System.out.println(
          resourceBundle.getString("orderFor")
              + bill.getTotalPrice()
              + resourceBundle.getString("thankYouForVisit"));
    } else {
      bill.setOrder(resourceBundle.getString("yourOrder"));
      check(data);
      weekends(data);
      setDiscount(data.getDiscount(), data);
      logger.info(resourceBundle.getString("finalPrice") + bill.getTotalPrice());
      bill.setFinalPriceToString(
          resourceBundle.getString("finalPrice")
              + " "
              + String.format(" %.2f ", bill.getTotalPrice()));
    }
  }

  private void pizzaCost(Data data) {
    bill.setPizzas(data.getPizzas());
    double pizzaTotalPrice = 0;
    try {
      for (int i = 0; i < data.getPizzas().size(); i++) {
        pizzaTotalPrice += data.getPizzas().get(i).getPrice();
      }
      bill.setPizzaPrice(pizzaTotalPrice);
    } catch (IndexOutOfBoundsException e) {
      logger.error(resourceBundle.getString("pizzaError"));
    }
  }

  private void drinksCost(Data data) {
    bill.setDrinks(data.getDrinks());
    double drinksTotalPrice = 0;
    try {
      for (int i = 0; i < data.getDrinks().size(); i++) {
        drinksTotalPrice += data.getDrinks().get(i).getPrice();
      }
      bill.setDrinksPrice(drinksTotalPrice);
    } catch (IndexOutOfBoundsException e) {
      logger.error(resourceBundle.getString("drinksError"));
    }
  }

  public Bill buildBill(Data data) {
    storeInfo(data);
    return bill;
  }
}