List of usage examples for java.util Date from
public static Date from(Instant instant)
From source file:com.vmware.photon.controller.api.client.resource.TenantsRestApiTest.java
@Test public void testCreate() throws IOException { Task responseTask = new Task(); responseTask.setId("12345"); responseTask.setState("QUEUED"); responseTask.setQueuedTime(Date.from(Instant.now())); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(responseTask); setupMocks(serializedTask, HttpStatus.SC_CREATED); TenantsApi tenantsApi = new TenantsRestApi(restClient); Task task = tenantsApi.create("foo"); assertEquals(task, responseTask);/*from www .j ava 2s. c o m*/ }
From source file:org.ng200.openolympus.TestUtilities.java
public User createTestUser(String name, String password) throws MessagingException, EmailException { User user = this.userService.getUserByUsername(name); if (user != null) { return user; }//from ww w. ja v a2s.c o m user = new User(name, this.passwordEncoder.encode(password), "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", Date.from(Instant.now()), UUID.randomUUID().toString()); user.setRoles(new HashSet<Role>()); user = this.userService.saveUser(user); this.approveUserRegistrationController.approveUser(user); return user; }
From source file:io.coala.enterprise.persist.FactDao.java
public static FactDao create(final EntityManager em, final Fact fact) { final Transaction<?> tx = Objects.requireNonNull(fact.transaction()); final Date offset = Date.from(tx.offset()); final Unit<?> unit = tx.timeUnit(); final Instant occur = Objects.requireNonNull(fact.occur()); final Instant expire = fact.expire(); final ID causeRef = fact.causeRef(); final FactDao dao = new FactDao(); dao.id = Objects.requireNonNull(fact.id().unwrap()); dao.tid = Objects.requireNonNull(tx.id().unwrap()); dao.type = Objects.requireNonNull(tx.kind()); dao.kind = Objects.requireNonNull(fact.kind()); dao.initiatorRef = Objects.requireNonNull(tx.initiatorRef()).persist(em); dao.executorRef = Objects.requireNonNull(tx.executorRef()).persist(em); dao.creatorRef = Objects.requireNonNull(fact.creatorRef()).persist(em); dao.cause = causeRef == null ? null : find(em, causeRef); dao.causeRef = causeRef == null ? null : Objects.requireNonNull(causeRef.unwrap()); dao.causeTranRef = causeRef == null ? null : Objects.requireNonNull(causeRef.parentRef()).unwrap(); dao.occur = InstantDao.of(occur, offset, unit); dao.expire = InstantDao.of(expire, offset, unit); dao.properties = JsonUtil.toTree(fact.properties()); // em.persist( result ); return dao;//from w w w .j a v a 2 s. c om }
From source file:org.eclipse.hawkbit.mgmt.rest.resource.MgmtTargetMapper.java
static void addPollStatus(final Target target, final MgmtTarget targetRest) { final PollStatus pollStatus = target.getPollStatus(); if (pollStatus != null) { final MgmtPollStatus pollStatusRest = new MgmtPollStatus(); pollStatusRest.setLastRequestAt( Date.from(pollStatus.getLastPollDate().atZone(ZoneId.systemDefault()).toInstant()).getTime()); pollStatusRest.setNextExpectedRequestAt( Date.from(pollStatus.getNextPollDate().atZone(ZoneId.systemDefault()).toInstant()).getTime()); pollStatusRest.setOverdue(pollStatus.isOverdue()); targetRest.setPollStatus(pollStatusRest); }/*from w ww. j a v a 2s .c o m*/ }
From source file:com.vmware.photon.controller.api.client.resource.FlavorApiTest.java
@Test public void testCreateAsync() throws Exception { final Task responseTask = new Task(); responseTask.setId("12345"); responseTask.setState("QUEUED"); responseTask.setQueuedTime(Date.from(Instant.now())); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(responseTask); setupMocks(serializedTask, HttpStatus.SC_CREATED); FlavorApi flavorApi = new FlavorApi(restClient); final CountDownLatch latch = new CountDownLatch(1); flavorApi.createAsync(new FlavorCreateSpec(), new FutureCallback<Task>() { @Override// www . jav a2 s . com public void onSuccess(@Nullable Task result) { assertEquals(result, responseTask); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }
From source file:at.becast.youploader.youtube.GuiUploadEvent.java
@Override public void onInit() { this.starttime = System.currentTimeMillis(); this.lastdata = 0; this.lasttime = this.starttime; this.lastdb = this.starttime; Date in = new Date(this.starttime); LocalDateTime ldt = LocalDateTime.ofInstant(in.toInstant(), ZoneId.systemDefault()); Date out = Date.from(ldt.atZone(ZoneId.systemDefault()).toInstant()); DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Locale.getDefault()); frame.getlblStart().setText(formatter.format(out)); frame.getProgressBar().setString("0,00 %"); frame.getProgressBar().setValue(0);// w w w .j a v a 2 s.c om frame.getProgressBar().revalidate(); frame.getBtnCancel().setEnabled(true); frame.getBtnEdit().setEnabled(true); frame.getBtnDelete().setEnabled(false); frame.revalidate(); frame.repaint(); }
From source file:com.devicehive.handler.notification.NotificationInsertHandlerTest.java
@Test public void testInsertNotification() throws ExecutionException, InterruptedException, TimeoutException { final String guid = UUID.randomUUID().toString(); final long id = System.nanoTime(); DeviceNotification originalNotification = new DeviceNotification(); originalNotification.setTimestamp(Date.from(Instant.now())); originalNotification.setId(id);// w w w. j a va 2 s. co m originalNotification.setDeviceGuid(guid); originalNotification.setNotification("SOME TEST DATA"); originalNotification.setParameters(new JsonStringWrapper("{\"param1\":\"value1\",\"param2\":\"value2\"}")); NotificationInsertRequest nir = new NotificationInsertRequest(originalNotification); Response response = handler.handle(Request.newBuilder().withBody(nir).build()); assertTrue(hazelcastService.find(id, guid, DeviceNotification.class) .filter(notification -> notification.equals(originalNotification)).isPresent()); ArgumentCaptor<NotificationEvent> eventCaptor = ArgumentCaptor.forClass(NotificationEvent.class); verify(eventBus).publish(eventCaptor.capture()); NotificationEvent event = eventCaptor.getValue(); assertEquals(event.getNotification(), originalNotification); assertNotNull(response); assertNotNull(response.getBody()); assertTrue(response.getBody() instanceof NotificationInsertResponse); NotificationInsertResponse body = (NotificationInsertResponse) response.getBody(); assertEquals(body.getDeviceNotification(), originalNotification); }
From source file:com.vmware.photon.controller.api.client.resource.FlavorRestApiTest.java
@Test public void testCreateAsync() throws Exception { final Task responseTask = new Task(); responseTask.setId("12345"); responseTask.setState("QUEUED"); responseTask.setQueuedTime(Date.from(Instant.now())); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(responseTask); setupMocks(serializedTask, HttpStatus.SC_CREATED); FlavorApi flavorApi = new FlavorRestApi(restClient); final CountDownLatch latch = new CountDownLatch(1); flavorApi.createAsync(new FlavorCreateSpec(), new FutureCallback<Task>() { @Override//from ww w . j a v a 2 s. c o m public void onSuccess(@Nullable Task result) { assertEquals(result, responseTask); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }
From source file:fr.ffremont.caching.CacheControlService.java
/** * Utilisation du If-Modified-Since/*from w ww . j a va 2 s.c om*/ * Ma ressource est mise en cache pendant 10sec puis une revalidation lieu pour renouveler les 10sec. * * * @param httpRequest * @return */ @GET @Path("validationtps") public Response validationTps(@Context HttpServletRequest httpRequest) { javax.ws.rs.core.CacheControl cache = new javax.ws.rs.core.CacheControl(); cache.setMaxAge(10); cache.setMustRevalidate(true); cache.setPrivate(false); Instant updated = Instant.parse("2011-12-03T10:15:30Z"); LOG.info("Cache par validation de temps"); Response.ResponseBuilder builder = request.evaluatePreconditions(Date.from(updated)); if (builder == null) { builder = Response.ok("Ma petite donne").lastModified(Date.from(updated)); } builder.cacheControl(cache); return builder.build(); }
From source file:ta4jexamples.analysis.BuyAndSellSignalsToChart.java
/** * Runs a strategy over a time series and adds the value markers * corresponding to buy/sell signals to the plot. * @param series a time series/*ww w.ja v a2s. c om*/ * @param strategy a trading strategy * @param plot the plot */ private static void addBuySellSignals(TimeSeries series, Strategy strategy, XYPlot plot) { // Running the strategy TimeSeriesManager seriesManager = new TimeSeriesManager(series); List<Trade> trades = seriesManager.run(strategy).getTrades(); // Adding markers to plot for (Trade trade : trades) { // Buy signal double buySignalTickTime = new Minute( Date.from(series.getTick(trade.getEntry().getIndex()).getEndTime().toInstant())) .getFirstMillisecond(); Marker buyMarker = new ValueMarker(buySignalTickTime); buyMarker.setPaint(Color.GREEN); buyMarker.setLabel("B"); plot.addDomainMarker(buyMarker); // Sell signal double sellSignalTickTime = new Minute( Date.from(series.getTick(trade.getExit().getIndex()).getEndTime().toInstant())) .getFirstMillisecond(); Marker sellMarker = new ValueMarker(sellSignalTickTime); sellMarker.setPaint(Color.RED); sellMarker.setLabel("S"); plot.addDomainMarker(sellMarker); } }