List of usage examples for java.util Optional of
public static <T> Optional<T> of(T value)
From source file:io.kamax.mxisd.backend.wordpress.WordpressDirectoryProvider.java
protected Optional<UserDirectorySearchResult.Result> processRow(ResultSet rSet) throws SQLException { UserDirectorySearchResult.Result item = new UserDirectorySearchResult.Result(); item.setUserId(rSet.getString(1));/*from www.j a v a 2s . co m*/ item.setDisplayName(rSet.getString(2)); return Optional.of(item); }
From source file:net.sf.jabref.logic.fetcher.SpringerLink.java
@Override public Optional<URL> findFullText(BibEntry entry) throws IOException { Objects.requireNonNull(entry); Optional<URL> pdfLink = Optional.empty(); // Try unique DOI first Optional<DOI> doi = DOI.build(entry.getField("doi")); if (doi.isPresent()) { // Available in catalog? try {/* ww w . j av a2 s .co m*/ HttpResponse<JsonNode> jsonResponse = Unirest.get(API_URL).queryString("api_key", API_KEY) .queryString("q", String.format("doi:%s", doi.get().getDOI())).asJson(); JSONObject json = jsonResponse.getBody().getObject(); int results = json.getJSONArray("result").getJSONObject(0).getInt("total"); if (results > 0) { LOGGER.info("Fulltext PDF found @ Springer."); pdfLink = Optional.of(new URL("http", CONTENT_HOST, String.format("/content/pdf/%s.pdf", doi.get().getDOI()))); } } catch (UnirestException e) { LOGGER.warn("SpringerLink API request failed", e); } } return pdfLink; }
From source file:ai.grakn.migration.base.io.MigrationCLI.java
public static Optional<MigrationCLI> create(String[] args, Options options) { try {/* w w w .j av a2 s . com*/ return Optional.of(new MigrationCLI(args, options)); } catch (IllegalArgumentException e) { return Optional.empty(); } }
From source file:net.pkhsolutions.pecsapp.control.ScalingPictureFileStorage.java
@NotNull public Optional<BufferedImage> loadForLayout(@NotNull PictureDescriptor descriptor, @NotNull PageLayout layout) throws IOException { @NotNull/*from w ww . j a v a2 s . c o m*/ Optional<BufferedImage> image = pictureFileStorage.load(descriptor, Optional.of(layout)); if (!image.isPresent()) { LOGGER.debug("Could not find image for descriptor {} and layout {}, trying to find raw image", descriptor, layout); // Try with the raw image image = pictureFileStorage.load(descriptor, Optional.empty()); if (image.isPresent()) { LOGGER.debug("Found raw image, scaling it to layout {} and storing it", layout); // We don't have a size for this layout, so let's create one image = image.map(img -> pictureTransformer.scaleIfNecessary(img, layout)); pictureFileStorage.store(descriptor, Optional.of(layout), image.get()); } } return image; }
From source file:it.polimi.diceH2020.SPACE4CloudWS.solvers.MINLPSolver.java
public Optional<Double> evaluate(@NonNull Matrix matrix, @NonNull Solution solution) throws MatrixHugeHoleException { try {// w w w.j a va2 s . c o m List<File> filesList = createWorkingFiles(matrix, solution); Pair<List<File>, List<File>> pair = new ImmutablePair<>(filesList, new ArrayList<>()); Pair<Double, Boolean> result = run(pair, "Knapsack solution"); File resultsFile = filesList.get(1); new MINLPSolFileParser().updateResults(solution, matrix, resultsFile); delete(filesList); return Optional.of(result.getLeft()); } catch (IOException | JSchException e) { logger.error("Evaluate Matrix: no result due to an exception", e); return Optional.empty(); } }
From source file:pzalejko.iot.hardware.home.core.service.DefaultTemperatureService.java
@Override public Optional<TemperatureEntity> getTemperatureEntity() { final double temperature = loadTemperatureFromFile(sourceFilePath, fileName); if (!Double.isNaN(temperature)) { LOG.debug(LogMessages.READ_TEMPERATURE, temperature); return Optional.of(new TemperatureEntity(temperature, System.currentTimeMillis())); }/*from ww w . j av a2 s .c om*/ return Optional.empty(); }
From source file:org.openmhealth.shim.runkeeper.mapper.RunkeeperCaloriesBurnedDataPointMapper.java
private Optional<CaloriesBurned> getMeasure(JsonNode itemNode) { Optional<Double> calorieValue = asOptionalDouble(itemNode, "total_calories"); if (!calorieValue.isPresent()) { // Not all activity datapoints have the "total_calories" property return Optional.empty(); }//from w w w .jav a 2 s .co m CaloriesBurned.Builder caloriesBurnedBuilder = new CaloriesBurned.Builder( new KcalUnitValue(KcalUnit.KILOCALORIE, calorieValue.get())); setEffectiveTimeFrameIfPresent(itemNode, caloriesBurnedBuilder); Optional<String> activityType = asOptionalString(itemNode, "type"); activityType.ifPresent(at -> caloriesBurnedBuilder.setActivityName(at)); return Optional.of(caloriesBurnedBuilder.build()); }
From source file:fi.helsinki.opintoni.service.CourseServiceTest.java
@Test public void thatStudentAndTeacherCourseDtosAreFetched() { expectTeacherCourses();/*from w ww .j ava2 s. c o m*/ expectStudentCourses(); Set<CourseDto> courseDtos = courseService.getCourses(Optional.of(TestConstants.STUDENT_NUMBER), Optional.of(TestConstants.TEACHER_NUMBER), Locale.ENGLISH); assertThat(courseDtos).hasSize(3); assertThat(courseDtos, hasCourseWithRealisationId(TestConstants.STUDENT_COURSE_REALISATION_ID)); assertThat(courseDtos, hasCourseWithRealisationId(TestConstants.TEACHER_COURSE_REALISATION_ID)); assertThat(courseDtos, hasCourseWithRealisationId(TestConstants.EXAM_TEACHER_COURSE_REALISATION_ID)); }
From source file:com.ikanow.aleph2.storm.samples.topology.SampleStormStreamTopology1.java
@Override public Tuple2<Object, Map<String, String>> getTopologyAndConfiguration(final DataBucketBean bucket, final IEnrichmentModuleContext context) { final TopologyBuilder builder = new TopologyBuilder(); final Collection<Tuple2<BaseRichSpout, String>> entry_points = context .getTopologyEntryPoints(BaseRichSpout.class, Optional.of(bucket)); entry_points.forEach(spout_name -> builder.setSpout(spout_name._2(), spout_name._1())); entry_points.stream().reduce(builder.setBolt("sample_conversion_bolt", new SampleConversionBolt()), (acc, v) -> acc.localOrShuffleGrouping(v._2()), (acc1, acc2) -> acc1 // (not possible in practice) );/* ww w. j a v a 2 s.co m*/ builder.setBolt("sample_enrichment_bolt", new SampleEnrichmentBolt()) .localOrShuffleGrouping("sample_conversion_bolt"); builder.setBolt("default_aleph2_output_spout", context.getTopologyStorageEndpoint(BaseRichBolt.class, Optional.of(bucket))) .localOrShuffleGrouping("sample_enrichment_bolt"); return Tuples._2T(builder.createTopology(), Collections.emptyMap()); }
From source file:no.asgari.civilization.server.model.Undo.java
/** * All must agree for draw to be performed. * If absent/empty, then all players have not voted *///from w w w . ja va2s . c o m @JsonIgnore public Optional<Boolean> getResultOfVotes() { if (votesRemaining() != 0) return Optional.empty(); if (getVotes().containsValue(Boolean.FALSE)) return Optional.of(Boolean.FALSE); return Optional.of(Boolean.TRUE); }