List of usage examples for java.util Date from
public static Date from(Instant instant)
From source file:no.imr.stox.functions.acoustic.PgNapesIO.java
public static void convertPgNapesToLuf20(String path, String fileName, String outFileName) { try {/*from ww w . j a v a2 s . c om*/ List<String> acList = Files.readAllLines(Paths.get(path + "/" + fileName + ".txt")); List<String> acVList = Files.readAllLines(Paths.get(path + "/" + fileName + "Values.txt")); if (acList.isEmpty() || acVList.isEmpty()) { return; } acList.remove(0); acVList.remove(0); List<DistanceBO> dList = acList.stream().map(s -> { DistanceBO d = new DistanceBO(); String[] str = s.split("\t", 14); d.setNation(str[0]); d.setPlatform(str[1]); d.setCruise(str[2]); d.setLog_start(Conversion.safeStringtoDoubleNULL(str[3])); d.setStart_time(Date.from(LocalDateTime.of(Conversion.safeStringtoIntegerNULL(str[4]), Conversion.safeStringtoIntegerNULL(str[5]), Conversion.safeStringtoIntegerNULL(str[6]), Conversion.safeStringtoIntegerNULL(str[7]), Conversion.safeStringtoIntegerNULL(str[8]), 0) .toInstant(ZoneOffset.UTC))); d.setLat_start(Conversion.safeStringtoDoubleNULL(str[9])); d.setLon_start(Conversion.safeStringtoDoubleNULL(str[10])); d.setIntegrator_dist(Conversion.safeStringtoDoubleNULL(str[11])); FrequencyBO freq = new FrequencyBO(); d.getFrequencies().add(freq); freq.setTranceiver(1); // implicit in pgnapes freq.setUpper_interpret_depth(0d); freq.setUpper_integrator_depth(0d); freq.setDistance(d); freq.setFreq(Conversion.safeStringtoIntegerNULL(str[12])); freq.setThreshold(Conversion.safeStringtoDoubleNULL(str[13])); return d; }).collect(Collectors.toList()); // Fill in sa values acVList.forEach(s -> { String[] str = s.split("\t", 11); String cruise = str[2]; Double log = Conversion.safeStringtoDoubleNULL(str[3]); Integer year = Conversion.safeStringtoIntegerNULL(str[4]); Integer month = Conversion.safeStringtoIntegerNULL(str[5]); Integer day = Conversion.safeStringtoIntegerNULL(str[6]); if (log == null || year == null || month == null || day == null) { return; } DistanceBO d = dList.parallelStream().filter(di -> { if (di.getCruise() == null || di.getLog_start() == null || di.getStart_time() == null) { return false; } LocalDate ld = di.getStart_time().toInstant().atZone(ZoneOffset.UTC).toLocalDate(); return cruise.equals(di.getCruise()) && log.equals(di.getLog_start()) && year.equals(ld.getYear()) && month.equals(ld.getMonthValue()) && day.equals(ld.getDayOfMonth()); }).findFirst().orElse(null); if (d == null) { return; } FrequencyBO freq = d.getFrequencies().get(0); String species = str[7]; Integer acocat = PgNapesEchoConvert.getAcoCatFromPgNapesSpecies(species); Double chUppDepth = Conversion.safeStringtoDoubleNULL(str[8]); Double chLowDepth = Conversion.safeStringtoDoubleNULL(str[9]); Double sa = Conversion.safeStringtoDoubleNULL(str[10]); if (acocat == null || sa == null || sa == 0d || chLowDepth == null || chUppDepth == null) { return; } if (d.getPel_ch_thickness() == null) { d.setPel_ch_thickness(chLowDepth - chUppDepth); } Integer ch = (int) (chLowDepth / d.getPel_ch_thickness() + 0.5); SABO sabo = new SABO(); sabo.setFrequency(freq); freq.getSa().add(sabo); sabo.setAcoustic_category(acocat + ""); sabo.setCh_type("P"); sabo.setCh(ch); sabo.setSa(sa); }); // Calculate number of pelagic channels /*dList.stream().forEach(d -> { FrequencyBO f = d.getFrequencies().get(0); Integer minCh = f.getSa().stream().map(SABO::getCh).min(Integer::compare).orElse(null); Integer maxCh = f.getSa().stream().map(SABO::getCh).max(Integer::compare).orElse(null); if (maxCh != null && minCh != null) { f.setNum_pel_ch(maxCh - minCh + 1); } });*/ if (dList.isEmpty()) { return; } DistanceBO d = dList.get(0); String cruise = d.getCruise(); String nation = d.getNation(); String pl = d.getPlatform(); ListUser20Writer.export(cruise, nation, pl, path + "/" + cruise + outFileName + ".xml", dList); } catch (IOException ex) { Logger.getLogger(PgNapesIO.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.vmware.photon.controller.api.client.resource.ProjectRestApiTest.java
@Test public void testCreatePersistentDisk() 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); ProjectApi projectApi = new ProjectRestApi(restClient); Task task = projectApi.createDisk("foo", new DiskCreateSpec()); assertEquals(task, responseTask);//from w w w. ja v a2 s . c om }
From source file:com.vmware.photon.controller.api.client.resource.VmApiTest.java
@Test public void testAddTagToVmAsync() throws IOException, InterruptedException { 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); VmApi vmApi = new VmApi(restClient); final CountDownLatch latch = new CountDownLatch(1); vmApi.addTagToVmAsync("foo", new Tag("tagValue"), new FutureCallback<Task>() { @Override/*from w w w.jav a 2s . 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:com.vmware.photon.controller.api.client.resource.VmRestApiTest.java
@Test public void testAddTagToVmAsync() throws IOException, InterruptedException { 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); VmApi vmApi = new VmRestApi(restClient); final CountDownLatch latch = new CountDownLatch(1); vmApi.addTagToVmAsync("foo", new Tag("tagValue"), new FutureCallback<Task>() { @Override/*from www . j a v a 2 s . c om*/ 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:gov.va.isaac.gui.listview.operations.UscrsExportOperation.java
/** * @see gov.va.isaac.gui.listview.operations.Operation#createTask() *//*from w w w . ja va 2s.c om*/ @Override public CustomTask<OperationResult> createTask() { return new CustomTask<OperationResult>(UscrsExportOperation.this) { @Override protected OperationResult call() throws Exception { IntStream nidStream = conceptList_.stream().mapToInt(c -> c.getNid()); int count = 0; ExportTaskHandlerI uscrsExporter = LookupService.getService(ExportTaskHandlerI.class, SharedServiceNames.USCRS); if (uscrsExporter != null) { updateMessage("Beginning USCRS Export "); if (cancelRequested_) { return new OperationResult(UscrsExportOperation.this.getTitle(), cancelRequested_); } if (!skipFilterCheckbox.isSelected() && datePicker.getValue() != null) { Properties options = new Properties(); Instant instant = Instant.from(datePicker.getValue().atStartOfDay(ZoneId.systemDefault())); Long dateSelected = Date.from(instant).getTime(); updateMessage("USCRS Export - Date filter selected: " + dateSelected.toString()); options.setProperty("date", Long.toString(dateSelected)); uscrsExporter.setOptions(options); } if (cancelRequested_) { return new OperationResult(UscrsExportOperation.this.getTitle(), cancelRequested_); } updateMessage("Beginning USCRS Export Handler Task"); try { Task<Integer> task = uscrsExporter.createTask(nidStream, file.toPath()); Utility.execute(task); count = task.get(); } catch (FileNotFoundException fnfe) { String errorMsg = "File is being used by another application. Close the other application to continue."; updateMessage(errorMsg); throw new RuntimeException(errorMsg); } return new OperationResult( "The USCRS Content request was succesfully generated in: " + file.getPath(), new HashSet<SimpleDisplayConcept>(), "The concepts were succesfully exported"); } else { throw new RuntimeException( "The USCRS Content Request Handler is not available on the class path"); } } }; }
From source file:retsys.client.controller.DeliveryChallanReturnController.java
@Override Object buildRequestMsg() {// ww w . j a v a 2s . c o m DeliveryChallan dc = new DeliveryChallan(); dc.setChallanDate(Date.from(Instant.now())); Project proj = new Project(); proj.setId(getId(project.getText())); dc.setProject(proj); dc.setIsDelivery(false); dc.setDeliveryMode(deliverymode.getText()); dc.setConcernPerson(concernperson.getText()); DeliveryChallan originalChallanDetail = new DeliveryChallan(); originalChallanDetail.setId(Integer.parseInt(dc_no.getText())); dc.setOriginalDeliveryChallan(originalChallanDetail); Iterator<DCItem> items = dcDetail.getItems().iterator(); List<DeliveryChallanDetail> dcDetails = new ArrayList<>(); while (items.hasNext()) { DCItem dcItem = items.next(); DeliveryChallanDetail dcDetail = new DeliveryChallanDetail(); Item item = new Item(); item.setId(dcItem.getId().get()); dcDetail.setItem(item); dcDetail.setQuantity(dcItem.getQuantity().get()); dcDetail.setUnits(dcItem.getUnits().get()); dcDetail.setAmount(dcItem.getAmount().get()); dcDetails.add(dcDetail); } dc.setDeliveryChallanDetail(dcDetails); return dc; }
From source file:gov.va.isaac.gui.preferences.plugins.ViewCoordinatePreferencesPluginViewController.java
private void setCurrentTimePropertyFromDatePicker() { Long dateSelected = null;//from ww w . ja v a 2s . c o m if (datePicker.getValue() != null) { Instant instant = Instant.from(datePicker.getValue().atStartOfDay(ZoneId.systemDefault())); dateSelected = getStartOfNextDay(Date.from(instant)).getTime(); } else { dateSelected = Long.MAX_VALUE; } currentTimeProperty.set(dateSelected); }
From source file:com.vmware.photon.controller.api.client.resource.TenantsApiTest.java
@Test public void testCreateResourceTicket() 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 TenantsApi(restClient); Task task = tenantsApi.createResourceTicket("foo", new ResourceTicketCreateSpec()); assertEquals(task, responseTask);//w w w. j a va2 s. c o m }
From source file:com.vmware.photon.controller.api.client.resource.TenantsRestApiTest.java
@Test public void testCreateResourceTicket() 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.createResourceTicket("foo", new ResourceTicketCreateSpec()); assertEquals(task, responseTask);/*from www . j a va 2 s .c o m*/ }
From source file:org.helioviewer.jhv.plugins.hekplugin.HEKPlugin.java
public void mouseMoved(MouseEvent e, Vector3d point) { HEKEvent lastHEKEvent = mouseOverHEKEvent; LocalDateTime in = Plugins.SINGLETON.getCurrentDateTime(); if (in != null) { Date currentDate = Date.from(in.atZone(ZoneId.systemDefault()).toInstant()); mouseOverHEKEvent = null;//from w ww.j a v a 2 s .com mouseOverPosition = null; List<HEKEvent> toDraw = HEKCache.getSingletonInstance().getModel().getActiveEvents(currentDate); if (toDraw.size() > 0) { for (HEKEvent evt : toDraw) { SphericalCoord stony = evt.getStony(currentDate); Vector3d coords = HEKEvent.convertToSceneCoordinates(stony, currentDate); double deltaX = Math.abs(point.x - coords.x); double deltaY = Math.abs(-point.y - coords.y); double deltaZ = Math.abs(point.z - coords.z); if (deltaX < 10000000 && deltaZ < 10000000 && deltaY < 10000000) { mouseOverHEKEvent = evt; mouseOverPosition = new Point(e.getX(), e.getY()); } } if (lastHEKEvent == null && mouseOverHEKEvent != null) { lastCursor = Plugins.getCursor(); Plugins.setCursor(CURSOR_HELP); } else if (lastHEKEvent != null && mouseOverHEKEvent == null) { Plugins.setCursor(lastCursor); } } } }