List of usage examples for java.time LocalDateTime now
public static LocalDateTime now()
From source file:fr.landel.utils.assertor.OperatorTest.java
/** * Test method for {@link Operator#and()}. *///from ww w. j ava2s .c om @Test public void testAnd() { final String text = "text"; assertTrue(Assertor.that(text).isNotEmpty().and().isNotBlank().isOK()); assertTrue(Assertor.that(text).isNotEmpty().and(true).isTrue().isOK()); assertFalse(Assertor.that(text).isNotEmpty().and(true).isFalse().isOK()); assertTrue( Assertor.that(text).isNotEmpty().and(text.getClass()).isAssignableFrom(CharSequence.class).isOK()); assertFalse( Assertor.that(text).isNotEmpty().and(text.getClass()).isAssignableFrom(StringBuilder.class).isOK()); assertTrue(Assertor.that(text).isNotEmpty().and(Calendar.getInstance()) .isAfter(DateUtils.getCalendar(new Date(0))).isOK()); assertFalse(Assertor.that(text).isNotEmpty().and(Calendar.getInstance()) .isBefore(DateUtils.getCalendar(new Date(0))).isOK()); assertTrue(Assertor.that(text).isNotEmpty().and(new Date()).isAfter(new Date(0)).isOK()); assertFalse(Assertor.that(text).isNotEmpty().and(new Date()).isBefore(new Date(0)).isOK()); assertTrue(Assertor.that(text).isNotEmpty().and(LocalDateTime.now()).isAfter(LocalDateTime.MIN).isOK()); assertFalse(Assertor.that(text).isNotEmpty().and(LocalDateTime.now()).isAfter(LocalDateTime.MAX).isOK()); assertTrue(Assertor.that(text).isNotEmpty().and(2).isGT(1).isOK()); assertFalse(Assertor.that(text).isNotEmpty().and(2).isLT(1).isOK()); assertTrue(Assertor.that(text).isNotEmpty().and("tt").isNotEmpty().isOK()); assertFalse(Assertor.that(text).isNotEmpty().and("tt").isEmpty().isOK()); assertTrue(Assertor.that(text).isNotEmpty().and(new String[] {}).isEmpty().isOK()); assertFalse(Assertor.that(text).isNotEmpty().and(new String[] {}).isNotEmpty().isOK()); assertTrue(Assertor.that(text).isNotEmpty().and(new String[] {}, EnumAnalysisMode.STREAM).isEmpty().isOK()); assertFalse( Assertor.that(text).isNotEmpty().and(new String[] {}, EnumAnalysisMode.STREAM).isNotEmpty().isOK()); assertTrue( Assertor.that(text).isNotEmpty().and(new String[] {}, EnumAnalysisMode.PARALLEL).isEmpty().isOK()); assertFalse(Assertor.that(text).isNotEmpty().and(new String[] {}, EnumAnalysisMode.PARALLEL).isNotEmpty() .isOK()); assertTrue(Assertor.that(text).isNotEmpty().and(Collections.emptyList()).isEmpty().isOK()); assertFalse(Assertor.that(text).isNotEmpty().and(Collections.emptyList()).isNotEmpty().isOK()); assertTrue(Assertor.that(text).isNotEmpty().and(Collections.emptyList(), EnumAnalysisMode.STREAM).isEmpty() .isOK()); assertFalse(Assertor.that(text).isNotEmpty().and(Collections.emptyList(), EnumAnalysisMode.STREAM) .isNotEmpty().isOK()); assertTrue(Assertor.that(text).isNotEmpty().and(Collections.emptyList(), EnumAnalysisMode.PARALLEL) .isEmpty().isOK()); assertFalse(Assertor.that(text).isNotEmpty().and(Collections.emptyList(), EnumAnalysisMode.PARALLEL) .isNotEmpty().isOK()); assertTrue(Assertor.that(text).isNotEmpty().and(Collections.emptyMap()).isEmpty().isOK()); assertFalse(Assertor.that(text).isNotEmpty().and(Collections.emptyMap()).isNotEmpty().isOK()); assertTrue(Assertor.that(text).isNotEmpty().and(Collections.emptyMap(), EnumAnalysisMode.STREAM).isEmpty() .isOK()); assertFalse(Assertor.that(text).isNotEmpty().and(Collections.emptyMap(), EnumAnalysisMode.STREAM) .isNotEmpty().isOK()); assertTrue(Assertor.that(text).isNotEmpty().and(Collections.emptyMap(), EnumAnalysisMode.PARALLEL).isEmpty() .isOK()); assertFalse(Assertor.that(text).isNotEmpty().and(Collections.emptyMap(), EnumAnalysisMode.PARALLEL) .isNotEmpty().isOK()); assertTrue(Assertor.that(text).isNotEmpty().and((Object) 0).isNotNull().isOK()); assertFalse(Assertor.that(text).isNotEmpty().and((Object) 0).isNull().isOK()); assertTrue(Assertor.that(text).isNotEmpty().and(new Exception()).isNotNull().isOK()); assertFalse(Assertor.that(text).isNotEmpty().and(new Exception()).isNull().isOK()); assertFalse(Assertor.that(Color.BLACK).isNull().and().isEqual(Color.black).isOK()); assertFalse(Assertor.that(Color.BLACK).isNull().and((Object) 0).isNotNull().isOK()); // SUB assertTrue(Assertor.that(true).isTrue().and(Assertor.that("text").isEmpty().or().contains("e")).isOK()); // left part error assertEquals("the boolean should be false", Assertor.that(true).isFalse() .and(Assertor.that("text").isEmpty().or().contains("e")).getErrors().get()); // right part error assertEquals("(the char sequence 'text' should contain 's')", Assertor.that(true).isTrue().and(Assertor.that("text").contains("s")).getErrors().get()); assertFalse(Assertor.that(true).isTrue().and(Assertor.that("text").contains("s")).isOK()); assertTrue(Assertor.that(true).isTrue().or(Assertor.that("text").contains("s")).isOK()); assertFalse(Assertor.that(true).isTrue().or(Assertor.that("text").contains("s")).getErrors().isPresent()); // both parts error assertEquals("the boolean should be false", Assertor.that(true).isFalse() .and(Assertor.that("text").isEmpty().or().contains("s")).getErrors().get()); assertEquals("the combination 'true' and ' NAND ' is invalid", Assertor.that(true).isTrue() .nand(Assertor.that("text").isEmpty().or().contains("s")).getErrors().get()); assertEquals("the boolean should be false OR (the char sequence 'text' should contain 's')", Assertor .that(true).isFalse().or(Assertor.that("text").isNotEmpty().and().contains("s")).getErrors().get()); // precondition error assertEquals("the char sequence cannot be null and the searched substring cannot be null or empty", Assertor.that(true).isTrue().and(Assertor.that("text").contains((String) null)).getErrors().get()); // SUB ASSERTOR assertTrue(Assertor.that(text).isNotEmpty().andAssertor(t -> Assertor.that(t.length()).isGT(3)).isOK()); // left part error assertEquals("the char sequence 'text' should be null or empty", Assertor.that(text).isEmpty() .andAssertor(t -> Assertor.that(t.length()).isGT(4)).getErrors().get()); // right part error assertEquals("(the number '4' should be greater than '4')", Assertor.that(text).isNotEmpty() .andAssertor(t -> Assertor.that(t.length()).isGT(4)).getErrors().get()); // precondition error assertEquals("the char sequence cannot be null and the searched substring cannot be null or empty", Assertor.that(text).isNotEmpty() .andAssertor(t -> Assertor.that(t.substring(0)).contains((String) null)).getErrors().get()); // null assertFalse(Assertor.that((String) null).isEmpty().andAssertor(t -> { if (t != null) { return Assertor.that(t.substring(1)).contains("e"); } else { return Assertor.that((String) null).isNull(); } }).getErrors().isPresent()); assertException( () -> Assertor.that(text).isNotEmpty() .andAssertor((Function<String, StepCharSequence<String>>) null).isOK(), IllegalStateException.class, "sub assertor cannot be null"); // MAPPER assertTrue(Assertor.that(true).isTrue().andObject(b -> b.toString()).hasHashCode(Objects.hashCode("true")) .isOK()); assertTrue(Assertor.that(true).isTrue().andCharSequence(b -> b.toString()).contains("ue").isOK()); assertTrue(Assertor.that("test").isNotEmpty() .andArray(s -> ArrayUtils.toObject(s.getBytes(StandardCharsets.UTF_8))).contains((byte) 'e') .isOK()); assertTrue(Assertor.that(true).isTrue().andBoolean(b -> !b).isFalse().isOK()); assertTrue(Assertor.that(true).isTrue().andClass(b -> b.getClass()).hasSimpleName("Boolean").isOK()); assertTrue(Assertor.that(true).isTrue().andDate(b -> new Date(1464475553641L)) .isAfter(new Date(1464475553640L)).isOK()); assertTrue(Assertor.that(true).isTrue().andCalendar(b -> DateUtils.getCalendar(new Date(1464475553641L))) .isBefore(Calendar.getInstance()).isOK()); assertTrue( Assertor.that(true).isTrue().andTemporal(b -> DateUtils.getLocalDateTime(new Date(1464475553641L))) .isBefore(LocalDateTime.now()).isOK()); assertTrue(Assertor.that(true).isTrue().andEnum(b -> EnumOperator.AND).hasName("AND").isOK()); assertTrue(Assertor.that(true).isTrue().andIterable(b -> Arrays.asList('t', 'r')).contains('t').isOK()); assertTrue(Assertor.that(true).isTrue().andMap(b -> MapUtils2.newHashMap("key", b)).contains("key", true) .isOK()); assertTrue(Assertor.that(true).isTrue().andNumber(b -> b.hashCode()).isGT(0).isOK()); // 1231 assertTrue(Assertor.that(true).isTrue().andThrowable(b -> new IOException(b.toString())) .validates(e -> e.getMessage().contains("true")).isOK()); }
From source file:datainstiller.data.DataPersistence.java
private void initJexlContext() { if (jexlContext != null) { System.out.println("WARNING!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); }//from www. ja v a2s. co m JexlContext jContext = new MapContext(); jContext.set("AddressGen", new AddressGenerator()); jContext.set("AlphaNumericGen", new AlphaNumericGenerator()); jContext.set("ListGen", new CustomListGenerator()); jContext.set("DateGen", new DateGenerator()); jContext.set("HumanNameGen", new HumanNameGenerator()); jContext.set("NumberGen", new NumberGenerator()); jContext.set("WordGen", new WordGenerator()); jContext.set("File2ListGen", new File2ListGenerator()); LocalDateTime now = LocalDateTime.now(); jContext.set("now", now); jContext.set("DateTimeFormatter", DateTimeFormatter.BASIC_ISO_DATE); initJexlContext(jContext); jexlContext = jContext; }
From source file:org.wallride.service.SignupService.java
@CacheEvict(value = WallRideCacheConfiguration.USER_CACHE, allEntries = true) public AuthorizedUser signup(SignupRequest request, User.Role role, String token) throws ServiceException { UserInvitation invitation = null;/*from w w w.j a v a 2s. c om*/ if (token != null) { invitation = userInvitationRepository.findOneForUpdateByToken(token); if (invitation == null) { throw new HttpForbiddenException(); } if (!validateInvitation(invitation)) { throw new HttpForbiddenException(); } } User duplicate; duplicate = userRepository.findOneByLoginId(request.getLoginId()); if (duplicate != null) { throw new DuplicateLoginIdException(request.getLoginId()); } duplicate = userRepository.findOneByEmail(request.getEmail()); if (duplicate != null) { throw new DuplicateEmailException(request.getEmail()); } LocalDateTime now = LocalDateTime.now(); if (invitation != null) { invitation.setAccepted(true); invitation.setAcceptedAt(now); userInvitationRepository.saveAndFlush(invitation); } User user = new User(); user.setLoginId(request.getLoginId()); StandardPasswordEncoder passwordEncoder = new StandardPasswordEncoder(); user.setLoginPassword(passwordEncoder.encode(request.getLoginPassword())); user.getName().setFirstName(request.getName().getFirstName()); user.getName().setLastName(request.getName().getLastName()); user.setEmail(request.getEmail()); user.getRoles().add(role); user.setCreatedAt(now); user.setUpdatedAt(now); user = userRepository.saveAndFlush(user); AuthorizedUser authorizedUser = new AuthorizedUser(user); // Authentication auth = new UsernamePasswordAuthenticationToken(authorizedUser, null, authorizedUser.getAuthorities()); // SecurityContextHolder.getContext().setAuthentication(auth); return authorizedUser; }
From source file:com.serphacker.serposcope.task.proxy.ProxyChecker.java
@Override public void run() { LOG.info("starting proxy checking task, threads = {}, timeout in MS = {}", nThread, timeoutMS); long start = System.currentTimeMillis(); List<Proxy> proxies = db.proxy.list(); if (proxies == null || proxies.isEmpty()) { LOG.debug("no proxy to check"); return;/*from w w w. ja v a 2s .c o m*/ } totalProxies = proxies.size(); ExecutorService executor = Executors.newFixedThreadPool(nThread); db.proxy.updateStatus(Proxy.Status.UNCHECKED, proxies.stream().map((t) -> t.getId()).collect(Collectors.toList())); for (Proxy proxy : proxies) { executor.submit(new Runnable() { @Override public void run() { ScrapClient cli = new ScrapClient(); cli.setTimeout(timeoutMS); ScrapProxy scrapProxy = proxy.toScrapProxy(); cli.setProxy(scrapProxy); LOG.info("checking {}", scrapProxy); Proxy.Status proxyStatus = Proxy.Status.ERROR; // try{Thread.sleep(30000l);}catch(Exception ex){} int httpStatus = cli.get(judgeUrl); if (httpStatus == 200 && cli.getContentAsString() != null) { Matcher matcher = PATTERN_IP.matcher(cli.getContentAsString()); if (matcher.find()) { proxy.setRemoteip(matcher.group(1)); proxyStatus = Proxy.Status.OK; } } proxy.setStatus(proxyStatus); proxy.setLastCheck(LocalDateTime.now()); db.proxy.update(proxy); checked.incrementAndGet(); } }); } executor.shutdown(); try { executor.awaitTermination(1, TimeUnit.HOURS); } catch (InterruptedException ex) { executor.shutdownNow(); } LOG.info("proxy checking finished in {}", DurationFormatUtils.formatDurationHMS(System.currentTimeMillis() - start)); }
From source file:br.ufac.sion.service.retorno.ArquivoRetornoCaixaService.java
private void carregarTitulos(ArquivoRetornoCaixa arquivoRetorno) { Map<Integer, Collection<SegmentoT>> titulosPorOcorrencia = arquivoRetorno .getTransacoesPorCodigoDeOcorrencia(); BigDecimal valorTotal = BigDecimal.ZERO; int totalTitulosPagos = 0; for (SegmentoT t : titulosPorOcorrencia.get(SegmentoU.LIQUIDACAO)) { br.ufac.sion.model.Boleto cobranca = this.boletoFacade.findByNossoNumero(t.getNossoNumero()); if (cobranca != null) { if (t.getSegmentoU().getValorPago().compareTo(cobranca.getValor()) >= 0) { cobranca.getSacado().setStatus(SituacaoInscricao.CONFIRMADA); cobranca.getSacado()/*from ww w. j a v a 2 s . c o m*/ .setJustificativaStatus("Confirmao automtica (via arquivo de retorno)"); cobranca.getSacado().setDataJustificativaStatus(LocalDateTime.now()); cobranca.setSituacao(SituacaoBoleto.PAGO); cobranca.setDataPagamento( DateConversor.convertDateToLocalDate(t.getSegmentoU().getDataOcorrencia())); cobranca.setValorPago(t.getSegmentoU().getValorPago()); cobranca.setArquivo(ar); this.ard.getIncricoesConfirmadas().add(cobranca.getSacado()); totalTitulosPagos++; } } valorTotal.add(t.getValor()); } this.ard.setTotalTitulosPagos(totalTitulosPagos); this.ard.setValorTotalEmCobrancas(valorTotal); }
From source file:com.swcguild.capstoneproject.dao.BlogDaoDbImplTest.java
/** * Test of addPost method, of class BlogDaoDbImpl. *//* w ww . j av a 2 s . c o m*/ @Test public void testAddPost() { System.out.println("addPost"); Post post = new Post("Supergirl", "Clark Kent", "hot new cousin saves city", "super, girl", LocalDateTime.now().toString(), "2015-12-30"); dao.addPost(post); assertEquals(1, dao.getAllPosts().size()); Post post2 = new Post("Supergirl", "Clark Kent", "hot new cousin saves city", "super, girl", LocalDateTime.now().toString(), "2015-12-30"); dao.addPost(post2); assertEquals(2, dao.getAllPosts().size()); }
From source file:nc.noumea.mairie.appock.services.impl.ConfigServiceImpl.java
@Override public void rechargeCache() { this.dateCache = LocalDateTime.now(); this.cacheCleValeur = new HashMap<>(); for (Config config : configRepository.findAll()) { this.cacheCleValeur.put(config.getCle(), config.getValeur()); }//w w w.j a va2 s .c om }
From source file:tibano.service.ParkService.java
@RequestMapping(path = "/getPaymentInfo") PaymentInfo getPaymentInfo(@RequestParam(name = "areaId") Long areaId, @RequestParam(name = "licensePlate") String licensePlate) { ParkingTransaction pt = ptRepository.findOpenTransactionByAreaAndLicensePlate(areaId, licensePlate); if (pt != null) { Duration duration = Duration.between(pt.getStart(), LocalDateTime.now()); Double amount = duration.getSeconds() * SEC_TARIF; BigDecimal bd = new BigDecimal(amount); bd = bd.setScale(2, RoundingMode.HALF_UP); Integer loyaltyPoints = 5 + Integer.valueOf(Double.valueOf(bd.doubleValue()).intValue()); return new PaymentInfo(pt.getEnd(), amount, duration, loyaltyPoints); }//w w w . ja v a 2 s .com return new PaymentInfo(null, Double.valueOf(0), Duration.ZERO, Integer.valueOf(0)); }
From source file:cc.kave.commons.utils.exec.ContextBatchInlining.java
private static void log(String msg, Object... args) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy.MM.dd-HH:mm:ss"); String date = LocalDateTime.now().format(formatter); System.out.printf("\n[%s] %s", date, String.format(msg, args)); }
From source file:net.ljcomputing.ecsr.security.service.impl.JwtTokenServiceImpl.java
/** * Local date and time now.//from w w w. j a v a2 s . co m * * @return the local date time */ @PostConstruct private void localNow() { // NOPMD ldtNow = LocalDateTime.now(); }