Example #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()));
  }
 @Override
 public Year deserialize(JsonParser parser, DeserializationContext context) throws IOException {
   if (formatter == null) {
     return Year.of(parser.getValueAsInt());
   }
   return Year.parse(parser.getValueAsString(), formatter);
 }
Example #3
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;
 }
 @Test(
     dataProvider = "prolepticYear",
     groups = {"tck"})
 public void test_prolepticYear(
     int eraValue, Era era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear) {
   Era eraObj = JapaneseChronology.INSTANCE.eraOf(eraValue);
   assertTrue(JapaneseChronology.INSTANCE.eras().contains(eraObj));
   assertEquals(eraObj, era);
   assertEquals(JapaneseChronology.INSTANCE.prolepticYear(era, yearOfEra), expectedProlepticYear);
   assertEquals(JapaneseChronology.INSTANCE.isLeapYear(expectedProlepticYear), isLeapYear);
   assertEquals(
       JapaneseChronology.INSTANCE.isLeapYear(expectedProlepticYear),
       Year.of(expectedProlepticYear).isLeap());
 }
  @Autowired
  public PaymentInitializer(CreditCardRepository repository) {

    if (repository.count() > 0) {
      return;
    }

    CreditCardNumber number = new CreditCardNumber("1234123412341234");
    CreditCard creditCard = new CreditCard(number, "Oliver Gierke", Month.DECEMBER, Year.of(2099));

    creditCard = repository.save(creditCard);

    LOG.info("Credit card {} created!", creditCard);
  }
Example #6
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;
 }
  public PaymentOrderNumberRange findByDecreeSequenceAndYear(
      final DecreeSequence decreeSequence, Year year) {
    CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
    CriteriaQuery<PaymentOrderNumberRange> cq = cb.createQuery(PaymentOrderNumberRange.class);
    Root<PaymentOrderNumberRange> range = cq.from(PaymentOrderNumberRange.class);
    Predicate predicate =
        cb.equal(range.get(PaymentOrderNumberRange_.decreeSequence), decreeSequence);
    predicate = cb.and(predicate, cb.equal(range.get(PaymentOrderNumberRange_.year), year));
    cq.select(range).where(predicate);

    try {
      return getEntityManager().createQuery(cq).getSingleResult();
    } catch (NoResultException ex) {
      throw new PaymentOrderNumberRangeNotFoundBoundsException(
          String.format("%s %d", decreeSequence.getCode(), year.getValue()));
    } catch (NonUniqueResultException ex) {
      return getEntityManager().createQuery(cq).getResultList().iterator().next();
    }
  }
  @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;
  }
Example #9
0
  @Test
  public void returnsTheYearOfbeginDate() {

    assertEquals(Year.of(2015), timeInterval.getBeginYear());
  }
Example #10
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;
  }
}