List of usage examples for java.time ZoneId systemDefault
public static ZoneId systemDefault()
From source file:com.sumzerotrading.eod.trading.strategy.ReportGeneratorTest.java
@Test public void testWriteRoundTrip() throws Exception { Path path = Files.createTempFile("ReportGeneratorUnitTest", ".txt"); reportGenerator.outputFile = path.toString(); String expected = "2016-03-19T07:01:10,Long,ABC,100,100.23,0,2016-03-20T06:01:10,101.23,0,Short,XYZ,50,250.34,0,251.34,0"; Ticker longTicker = new StockTicker("ABC"); Ticker shortTicker = new StockTicker("XYZ"); int longSize = 100; int shortSize = 50; double longEntryFillPrice = 100.23; double longExitFillPrice = 101.23; double shortEntryFillPrice = 250.34; double shortExitFillPrice = 251.34; ZonedDateTime entryTime = ZonedDateTime.of(2016, 3, 19, 7, 1, 10, 0, ZoneId.systemDefault()); ZonedDateTime exitTime = ZonedDateTime.of(2016, 3, 20, 6, 1, 10, 0, ZoneId.systemDefault()); TradeOrder longEntry = new TradeOrder("123", longTicker, longSize, TradeDirection.BUY); longEntry.setFilledPrice(longEntryFillPrice); longEntry.setOrderFilledTime(entryTime); TradeOrder longExit = new TradeOrder("123", longTicker, longSize, TradeDirection.SELL); longExit.setFilledPrice(longExitFillPrice); longExit.setOrderFilledTime(exitTime); TradeOrder shortEntry = new TradeOrder("123", shortTicker, shortSize, TradeDirection.SELL); shortEntry.setFilledPrice(shortEntryFillPrice); shortEntry.setOrderFilledTime(entryTime); TradeOrder shortExit = new TradeOrder("123", shortTicker, shortSize, TradeDirection.BUY); shortExit.setFilledPrice(shortExitFillPrice); shortExit.setOrderFilledTime(exitTime); RoundTrip roundTrip = new RoundTrip(); roundTrip.longEntry = longEntry;//from ww w . j a v a2 s .com roundTrip.longExit = longExit; roundTrip.shortEntry = shortEntry; roundTrip.shortExit = shortExit; System.out.println("Writing out to file: " + path); reportGenerator.writeRoundTripToFile(roundTrip); List<String> lines = Files.readAllLines(path); assertEquals(1, lines.size()); assertEquals(expected, lines.get(0)); Files.deleteIfExists(path); }
From source file:software.reinvent.dependency.parser.service.ArtifactDependencyGraph.java
/** * Adds a non parent {@link Model} as {@link Artifact}. * * @param model the model to parse//from w w w . j a va 2 s . c o m */ private void addArtifact(final Model model) { final Properties properties = model.getProperties(); final List<Dependency> dependencies = model.getDependencies(); setVersionToDepencies(model, dependencies); final Set<ArtifactDependency> artifactDependencies = addDependencies(dependencies); final String groupId = model.getGroupId() == null ? model.getParent().getGroupId() : model.getGroupId(); final ArtifactParent artifactParent = model.getParent() == null ? null : new ArtifactParent(model.getParent()); Artifact artifact = new Artifact( groupId, model.getArtifactId(), model.getVersion(), model.getPackaging(), LocalDateTime .ofInstant(Instant.ofEpochMilli(model.getPomFile().lastModified()), ZoneId.systemDefault()), artifactParent); if (artifacts.contains(artifact)) { artifacts.stream().filter(x -> x.equals(artifact)).findFirst().ifPresent(x -> { if (x.getFileDate().isBefore(artifact.getFileDate())) { artifacts.remove(artifact); } else { x.getDependencies().addAll(artifactDependencies); } }); artifact.getDependencies().addAll(artifactDependencies); artifacts.add(artifact); } else { artifact.getDependencies().addAll(artifactDependencies); artifacts.add(artifact); } }
From source file:org.apdplat.superword.system.AntiRobotFilter.java
public void init(FilterConfig config) throws ServletException { int initialDelay = 24 - LocalDateTime.now().getHour(); scheduledExecutorService.scheduleAtFixedRate(() -> { try {//from w w w . j ava 2 s . c o m LOG.info("clear last day anti-robot counter"); LocalDateTime timePoint = LocalDateTime.now().minusDays(1); String date = SIMPLE_DATE_FORMAT .format(Date.from(timePoint.atZone(ZoneId.systemDefault()).toInstant())); Map<String, Integer> archive = new HashMap<String, Integer>(); Enumeration<String> keys = servletContext.getAttributeNames(); while (keys.hasMoreElements()) { String key = keys.nextElement(); if (key.startsWith("anti-robot-") && key.endsWith(date)) { archive.put(key, ((AtomicInteger) servletContext.getAttribute(key)).intValue()); } } archive.keySet().forEach(servletContext::removeAttribute); File path = new File(servletContext.getRealPath("/WEB-INF/data/anti-robot-archive/")); if (!path.exists()) { path.mkdirs(); } String file = path.getPath() + "/" + date + "__user_agent_invalid_count_" + invalidCount + ".txt"; Files.write(Paths.get(file), archive.entrySet().stream() .map(e -> e.getKey().replace("anti-robot-", "").replace("-", "\t") + "\t" + e.getValue()) .map(line -> { String[] attrs = line.split("\\s+"); String location = ""; if (attrs != null && attrs.length > 1) { String ip = attrs[1]; location = IPUtils.getIPLocation(ip).toString(); } return line + "\t" + location; }).collect(Collectors.toList())); invalidCount = 0; LOG.info("clear last day anti-robot counter finished: " + file); } catch (Exception e) { LOG.error("save anti-robot-archive failed", e); } }, initialDelay, 24, TimeUnit.HOURS); }
From source file:ox.softeng.gel.filereceive.FileReceive.java
public void generateStartupMessage() throws IOException { try {/*w ww . jav a2 s . com*/ StringWriter writer; MessageDTO message = new MessageDTO(); message.setSource("file-receiver"); message.setDetails("Burst Service starting\n" + version()); message.setSeverity(SeverityEnum.INFORMATIONAL); message.setDateTimeCreated(OffsetDateTime.now(ZoneId.of("UTC"))); message.setTitle("File Receiver Startup"); message.addTopic("service"); message.addTopic("startup"); message.addTopic("file-receiver"); message.addMetadata("gmc", "gel"); message.addMetadata("file_receiver_service_version", version()); writer = new StringWriter(); getMarshaller().marshal(message, writer); AMQP.BasicProperties.Builder builder = new AMQP.BasicProperties().builder(); builder.deliveryMode(2); builder.contentType("text/xml"); builder.timestamp(Date.from(OffsetDateTime.now(ZoneId.systemDefault()).toInstant())); Channel channel = factory.newConnection().createChannel(); channel.exchangeDeclare(exchangeName, "topic", true); channel.basicPublish(exchangeName, burstQueue, builder.build(), writer.toString().getBytes()); channel.close(); } catch (JAXBException | TimeoutException ignored) { } }
From source file:org.helioviewer.jhv.plugins.hekplugin.HEKPlugin.java
public void dateTimesChanged(int framecount) { LocalDateTime startDateTime;/*from w w w. j a v a 2 s. c om*/ startDateTime = Plugins.getStartDateTime(); LocalDateTime endDateTime = Plugins.getEndDateTime(); if (startDateTime != null && endDateTime != null) { Date start = Date.from(startDateTime.atZone(ZoneId.systemDefault()).toInstant()); Date end = Date.from(endDateTime.atZone(ZoneId.systemDefault()).toInstant()); Interval<Date> newInterval = new Interval<>(start, end); hekPluginPanel.setCurInterval(newInterval); } }
From source file:org.tightblog.service.WeblogEntryManager.java
/** * Find nearest published blog entry before or after a given target date. Useful for date-based * pagination where it is desired to determine the next or previous time period that * contains a blog entry./*from w w w.ja va 2 s. co m*/ * * @param weblog weblog whose entries to search * @param categoryName Category name that entry must belong to or null if entry may belong to any category * @param targetDate Earliest (if succeeding = true) or latest (succeeding = false) publish time of blog entry * @param succeeding If true, find the first blog entry whose publish time comes after the targetDate, if false, the * entry closest to but before the targetDate. * @return WeblogEntry meeting the above criteria or null if no entry matches */ public WeblogEntry findNearestWeblogEntry(Weblog weblog, String categoryName, LocalDateTime targetDate, boolean succeeding) { WeblogEntry nearestEntry = null; WeblogEntrySearchCriteria wesc = new WeblogEntrySearchCriteria(); wesc.setWeblog(weblog); wesc.setCategoryName(categoryName); wesc.setStatus(WeblogEntry.PubStatus.PUBLISHED); wesc.setMaxResults(1); if (succeeding) { wesc.setStartDate(targetDate.atZone(ZoneId.systemDefault()).toInstant()); wesc.setSortOrder(WeblogEntrySearchCriteria.SortOrder.ASCENDING); } else { wesc.setEndDate(targetDate.atZone(ZoneId.systemDefault()).toInstant()); wesc.setSortOrder(WeblogEntrySearchCriteria.SortOrder.DESCENDING); } List entries = getWeblogEntries(wesc); if (entries.size() > 0) { nearestEntry = (WeblogEntry) entries.get(0); } return nearestEntry; }
From source file:retsys.client.controller.PurchaseOrderConfirmController.java
/** * Initializes the controller class.//from ww w . jav a 2 s. c o m */ @Override public void initialize(URL url, ResourceBundle rb) { po_date.setValue(LocalDate.now()); loc_of_material.setCellValueFactory(new PropertyValueFactory<POItem, String>("location")); material_name.setCellValueFactory(new PropertyValueFactory<POItem, String>("name")); brand_name.setCellValueFactory(new PropertyValueFactory<POItem, String>("brand")); model_code.setCellValueFactory(new PropertyValueFactory<POItem, String>("model")); quantity.setCellValueFactory(new PropertyValueFactory<POItem, Integer>("quantity")); confirm.setCellValueFactory(new PropertyValueFactory<POItem, Boolean>("confirm")); confirm.setCellFactory(CheckBoxTableCell.forTableColumn(confirm)); billNo.setCellValueFactory(new PropertyValueFactory<POItem, String>("billNo")); billNo.setCellFactory(TextFieldTableCell.forTableColumn()); supervisor.setCellValueFactory(new PropertyValueFactory<POItem, String>("supervisor")); supervisor.setCellFactory(TextFieldTableCell.forTableColumn()); receivedDate.setCellValueFactory(new PropertyValueFactory<POItem, LocalDate>("receivedDate")); receivedDate.setCellFactory(new Callback<TableColumn<POItem, LocalDate>, TableCell<POItem, LocalDate>>() { @Override public TableCell<POItem, LocalDate> call(TableColumn<POItem, LocalDate> param) { TableCell<POItem, LocalDate> cell = new TableCell<POItem, LocalDate>() { @Override protected void updateItem(LocalDate item, boolean empty) { super.updateItem(item, empty); //To change body of generated methods, choose Tools | Templates. if (empty || item == null) { setText(null); setGraphic(null); } else { setText(formatter.format(item)); } } @Override public void startEdit() { super.startEdit(); System.out.println("start edit"); DatePicker dateControl = null; if (this.getItem() != null) { dateControl = new DatePicker(this.getItem()); } else { dateControl = new DatePicker(); } dateControl.valueProperty().addListener(new ChangeListener<LocalDate>() { @Override public void changed(ObservableValue<? extends LocalDate> observable, LocalDate oldValue, LocalDate newValue) { if (newValue == null) { cancelEdit(); } else { commitEdit(newValue); } } }); this.setGraphic(dateControl); } @Override public void cancelEdit() { super.cancelEdit(); System.out.println("cancel edit"); setGraphic(null); if (this.getItem() != null) { setText(formatter.format(this.getItem())); } else { setText(null); } } @Override public void commitEdit(LocalDate newValue) { super.commitEdit(newValue); System.out.println("commit edit"); setGraphic(null); setText(formatter.format(newValue)); } }; return cell; } }); poDetail.getColumns().setAll(loc_of_material, material_name, brand_name, model_code, quantity, confirm, receivedDate, billNo, supervisor); AutoCompletionBinding<PurchaseOrder> bindForTxt_name = TextFields.bindAutoCompletion(project, new Callback<AutoCompletionBinding.ISuggestionRequest, Collection<PurchaseOrder>>() { @Override public Collection<PurchaseOrder> call(AutoCompletionBinding.ISuggestionRequest param) { List<PurchaseOrder> list = null; try { LovHandler lovHandler = new LovHandler("purchaseorders", "name"); String response = lovHandler.getSuggestions(param.getUserText()); list = (List<PurchaseOrder>) new JsonHelper().convertJsonStringToObject(response, new TypeReference<List<PurchaseOrder>>() { }); } catch (IOException ex) { Logger.getLogger(ProjectController.class.getName()).log(Level.SEVERE, null, ex); } return list; } }, new StringConverter<PurchaseOrder>() { @Override public String toString(PurchaseOrder object) { System.out.println("here..." + object); String strDate = DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM).format( LocalDateTime.ofInstant(object.getDate().toInstant(), ZoneId.systemDefault())); return "Project:" + object.getProject().getName() + " PO Date:" + strDate + " PO No.:" + object.getId(); } @Override public PurchaseOrder fromString(String string) { throw new UnsupportedOperationException(); } }); bindForTxt_name .setOnAutoCompleted(new EventHandler<AutoCompletionBinding.AutoCompletionEvent<PurchaseOrder>>() { @Override public void handle(AutoCompletionBinding.AutoCompletionEvent<PurchaseOrder> event) { populateData(event.getCompletion()); } }); AutoCompletionBinding<Vendor> bindForVendor = TextFields.bindAutoCompletion(vendor, new Callback<AutoCompletionBinding.ISuggestionRequest, Collection<Vendor>>() { @Override public Collection<Vendor> call(AutoCompletionBinding.ISuggestionRequest param) { List<Vendor> list = null; try { LovHandler lovHandler = new LovHandler("vendors", "name"); String response = lovHandler.getSuggestions(param.getUserText()); list = (List<Vendor>) new JsonHelper().convertJsonStringToObject(response, new TypeReference<List<Vendor>>() { }); } catch (IOException ex) { Logger.getLogger(ProjectController.class.getName()).log(Level.SEVERE, null, ex); } return list; } }, new StringConverter<Vendor>() { @Override public String toString(Vendor object) { return object.getName() + " (ID:" + object.getId() + ")"; } @Override public Vendor fromString(String string) { throw new UnsupportedOperationException(); } }); }
From source file:gov.va.isaac.gui.listview.operations.UscrsExportOperation.java
/** * @see gov.va.isaac.gui.listview.operations.Operation#createTask() */// ww w. ja va 2 s .com @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:gov.va.isaac.gui.preferences.plugins.ViewCoordinatePreferencesPluginViewController.java
private void setCurrentTimePropertyFromDatePicker() { Long dateSelected = null;/* w w w . j a v a 2 s . c om*/ 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.sumzerotrading.reporting.csv.ReportGeneratorTest.java
@Test public void testWriteRoundTrip() throws Exception { Path path = Files.createTempFile("ReportGeneratorUnitTest", ".txt"); reportGenerator.outputFile = path.toString(); String expected = "2016-03-19T07:01:10,Long,ABC,100,100.23,0,2016-03-20T06:01:10,101.23,0,Short,XYZ,50,250.34,0,251.34,0"; Ticker longTicker = new StockTicker("ABC"); Ticker shortTicker = new StockTicker("XYZ"); int longSize = 100; int shortSize = 50; double longEntryFillPrice = 100.23; double longExitFillPrice = 101.23; double shortEntryFillPrice = 250.34; double shortExitFillPrice = 251.34; ZonedDateTime entryTime = ZonedDateTime.of(2016, 3, 19, 7, 1, 10, 0, ZoneId.systemDefault()); ZonedDateTime exitTime = ZonedDateTime.of(2016, 3, 20, 6, 1, 10, 0, ZoneId.systemDefault()); TradeOrder longEntry = new TradeOrder("123", longTicker, longSize, TradeDirection.BUY); longEntry.setFilledPrice(longEntryFillPrice); longEntry.setOrderFilledTime(entryTime); TradeOrder longExit = new TradeOrder("123", longTicker, longSize, TradeDirection.SELL); longExit.setFilledPrice(longExitFillPrice); longExit.setOrderFilledTime(exitTime); TradeOrder shortEntry = new TradeOrder("123", shortTicker, shortSize, TradeDirection.SELL); shortEntry.setFilledPrice(shortEntryFillPrice); shortEntry.setOrderFilledTime(entryTime); TradeOrder shortExit = new TradeOrder("123", shortTicker, shortSize, TradeDirection.BUY); shortExit.setFilledPrice(shortExitFillPrice); shortExit.setOrderFilledTime(exitTime); PairTradeRoundTrip roundTrip = new PairTradeRoundTrip(); roundTrip.longEntry = longEntry;//from w w w . j a va 2 s . c o m roundTrip.longExit = longExit; roundTrip.shortEntry = shortEntry; roundTrip.shortExit = shortExit; System.out.println("Writing out to file: " + path); reportGenerator.writeRoundTripToFile(roundTrip); List<String> lines = Files.readAllLines(path); assertEquals(1, lines.size()); assertEquals(expected, lines.get(0)); Files.deleteIfExists(path); }