List of usage examples for java.util Optional get
public T get()
From source file:com.teradata.benchto.driver.execution.ExecutionDriver.java
private void runOptionalMacros(Optional<List<String>> macros, String kind) { if (macros.isPresent()) { LOG.info("Running {} macros: {}", kind, macros.get()); macroService.runBenchmarkMacros(macros.get()); }//from w w w . ja va2 s. c o m }
From source file:org.lendingclub.mercator.bind.BindScanner.java
@SuppressWarnings("unchecked") private void scanRecordSetByZone() { Instant startTime = Instant.now(); List<String> zones = getBindClient().getZones(); Preconditions.checkNotNull(getProjector().getNeoRxClient(), "neorx client must be set"); zones.forEach(zone -> {/*from w w w . j a va 2 s.com*/ logger.info("Scanning the zone {}", zone); Optional<List> recordsStream = getBindClient().getRecordsbyZone(zone); if (!recordsStream.get().isEmpty()) { logger.info("Found {} records in {} zone", recordsStream.get().size(), zone); recordsStream.get().forEach(record -> { String line = record.toString(); if (!line.startsWith(";")) { ResourceRecordSet<Map<String, Object>> dnsRecord = getRecord(line); ObjectNode recordNode = dnsRecord.toJson(); String cypher = "MATCH (z:BindHostedZone {zoneName:{zone}}) " + "MERGE (m:BindHostedZoneRecord {domainName:{dn}, type:{type}, zoneName:{zone}}) " + "ON CREATE SET m.ttl={ttl}, m.class={class}, m+={props}, m.createTs = timestamp(), m.updateTs=timestamp() " + "ON MATCH SET m+={props}, m.updateTs=timestamp() " + "MERGE (z)-[:CONTAINS]->(m);"; getProjector().getNeoRxClient().execCypher(cypher, "dn", recordNode.get("name").asText(), "type", recordNode.get("type").asText(), "ttl", recordNode.get("ttl").asText(), "class", recordNode.get("class").asText(), "props", recordNode.get("rData"), "zone", zone); } }); } else { logger.error("Failed to obtain any records in {} zone", zone); } }); Instant endTime = Instant.now(); logger.info(" Took {} secs to project Bind records to Neo4j", Duration.between(startTime, endTime).getSeconds()); }
From source file:com.skelril.skree.content.modifier.ModifierNotifier.java
@Listener public void onPlayerJoin(ClientConnectionEvent.Join event) { Optional<ModifierService> optService = Sponge.getServiceManager().provide(ModifierService.class); if (!optService.isPresent()) { return;// w ww.ja v a2 s .c o m } ModifierService service = optService.get(); List<String> messages = new ArrayList<>(); for (Map.Entry<String, Long> entry : service.getActiveModifiers().entrySet()) { String friendlyName = StringUtils.capitalize(entry.getKey().replace("_", " ").toLowerCase()); String friendlyTime = PrettyText.date(entry.getValue()); messages.add(" - " + friendlyName + " till " + friendlyTime); } if (messages.isEmpty()) return; Collections.sort(messages, String.CASE_INSENSITIVE_ORDER); messages.add(0, "\n\nThe following donation perks are enabled:"); Player player = event.getTargetEntity(); Task.builder().execute(() -> { for (String message : messages) { player.sendMessage(Text.of(TextColors.GOLD, message)); } }).delay(1, TimeUnit.SECONDS).submit(SkreePlugin.inst()); }
From source file:mtsar.processors.task.InverseCountAllocatorTest.java
@Test public void testUnequalAllocation() { when(countDAO.getCountsSQL(anyString())).thenReturn(Arrays.asList(Pair.of(1, 1), Pair.of(2, 0))); final TaskAllocator allocator = new InverseCountAllocator(stage, dbi, taskDAO, answerDAO); final Optional<TaskAllocation> optional = allocator.allocate(worker); assertThat(optional.isPresent()).isTrue(); final TaskAllocation allocation = optional.get(); assertThat(allocation.getTask().get().getId()).isEqualTo(2); assertThat(allocation.getTaskRemaining()).isEqualTo(2); assertThat(allocation.getTaskCount()).isEqualTo(2); }
From source file:mtsar.processors.task.InverseCountAllocatorTest.java
@Test public void testEqualAllocation() { when(countDAO.getCountsSQL(anyString())).thenReturn(Arrays.asList(Pair.of(1, 0), Pair.of(2, 0))); final TaskAllocator allocator = new InverseCountAllocator(stage, dbi, taskDAO, answerDAO); final Optional<TaskAllocation> optional = allocator.allocate(worker); assertThat(optional.isPresent()).isTrue(); final TaskAllocation allocation = optional.get(); assertThat(allocation.getTask().get().getId()).isBetween(1, 2); assertThat(allocation.getTaskRemaining()).isEqualTo(2); assertThat(allocation.getTaskCount()).isEqualTo(2); }
From source file:org.ameba.aop.ServiceLayerAspect.java
/** * Called after an exception is thrown by classes of the service layer. <p> Set log level to ERROR to log the root cause. </p> * * @param ex The root exception that is thrown * @return Returns the exception to be thrown *//*from w w w . j av a2s . c o m*/ public Exception translateException(Exception ex) { if (ex instanceof BusinessRuntimeException) { BusinessRuntimeException bre = (BusinessRuntimeException) ex; MDC.put(LoggingCategories.MSGKEY, bre.getMsgKey()); if (bre.getData() != null) { MDC.put(LoggingCategories.MSGDATA, String.join(",", Stream.of(bre.getData()).map(Object::toString).toArray(String[]::new))); } // cleanup of context is done in SLF4JMappedDiagnosticContextFilter return bre; } Optional<Exception> handledException = doTranslateException(ex); if (handledException.isPresent()) { return handledException.get(); } if (ex instanceof ServiceLayerException) { return ex; } return withRootCause ? new ServiceLayerException(ex.getMessage(), ex) : new ServiceLayerException(ex.getMessage()); }
From source file:org.homiefund.api.service.impl.UserServiceImpl.java
@Override @Transactional(readOnly = true)/* w w w. j a v a 2s . c om*/ public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException { Optional<User> user = userDAO.getByUsername(s); if (!user.isPresent()) { throw new UsernameNotFoundException(s); } else { UserDTO result = mapper.map(user.get(), UserDTO.class); result.setHomes(homeDAO.getHomes(user.get()).stream().map(h -> { HomeDTO hdto = new HomeDTO(); hdto.setId(h.getId()); return hdto; }).collect(Collectors.toList())); return result; } }
From source file:org.openmhealth.shim.runkeeper.mapper.RunkeeperCaloriesBurnedDataPointMapper.java
@Override protected Optional<DataPoint<CaloriesBurned>> asDataPoint(JsonNode itemNode) { Optional<CaloriesBurned> caloriesBurned = getMeasure(itemNode); if (caloriesBurned.isPresent()) { return Optional .of(new DataPoint<>(getDataPointHeader(itemNode, caloriesBurned.get()), caloriesBurned.get())); } else {// w w w . j av a 2 s . co m return Optional.empty(); // return empty if there was no calories information to generate a datapoint } }
From source file:com.formkiq.core.form.bean.FormJSONDateFieldInterceptor.java
@Override public boolean isSupported(final Class<?> clazz, final FormJSON form) { Optional<FormJSONField> inserted = FormFinder.findValueByKey(form, "insertedDate"); Optional<FormJSONField> updated = FormFinder.findValueByKey(form, "updatedDate"); return (inserted.isPresent() && isEmpty(inserted.get().getValue()) || updated.isPresent()); }
From source file:com.netflix.spinnaker.orca.clouddriver.tasks.pipeline.MigratePipelineClustersTask.java
private List<Map> getSources(Map<String, Object> pipeline) { List<Map> stages = (List<Map>) pipeline.getOrDefault("stages", new ArrayList<>()); return stages.stream().map(s -> { Optional<PipelineClusterExtractor> extractor = PipelineClusterExtractor.getExtractor(s, extractors); if (extractor.isPresent()) { return extractor.get().extractClusters(s).stream().map(c -> Collections.singletonMap("cluster", c)) .collect(Collectors.toList()); }/*ww w . j a v a 2 s . c om*/ return new ArrayList<Map>(); }).flatMap(Collection::stream).collect(Collectors.toList()); }