List of usage examples for java.util Optional of
public static <T> Optional<T> of(T value)
From source file:com.bekwam.resignator.model.ConfigurationJSONAdapter.java
@Override public Configuration deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { if (logger.isDebugEnabled()) { logger.debug("[DESERIALIZE]"); }/*from w w w .j ava 2s . co m*/ JsonObject obj = (JsonObject) jsonElement; JsonElement apElement = obj.get("activeProfile"); String ap = ""; if (apElement != null) { ap = apElement.getAsString(); } JsonElement jdkElem = obj.get("jdkHome"); String jdkHome = ""; if (jdkElem != null) { jdkHome = jdkElem.getAsString(); } JsonElement hpElem = obj.get("hashedPassword"); String hp = ""; if (hpElem != null) { hp = hpElem.getAsString(); } JsonElement ludElem = obj.get("lastUpdatedDate"); String lud = ""; LocalDateTime lastUpdatedDate = null; if (ludElem != null) { lud = ludElem.getAsString(); if (StringUtils.isNotEmpty(lud)) { lastUpdatedDate = LocalDateTime.parse(lud, DateTimeFormatter.ISO_LOCAL_DATE_TIME); } } JsonArray recentProfiles = obj.getAsJsonArray("recentProfiles"); JsonArray profiles = obj.getAsJsonArray("profiles"); if (logger.isDebugEnabled()) { logger.debug("[DESERIALIZE] rp={}, ap={}, jdkHome={}, keytool={}, profiles={}", recentProfiles.toString(), ap, jdkHome, profiles.toString()); } Configuration conf = new Configuration(); conf.setActiveProfile(Optional.of(ap)); conf.setJDKHome(Optional.of(jdkHome)); conf.getRecentProfiles().addAll(deserializeRecentProfiles(recentProfiles)); conf.getProfiles().addAll(deserializeProfiles(profiles)); conf.setHashedPassword(Optional.of(hp)); conf.setLastUpdatedDateTime(Optional.ofNullable(lastUpdatedDate)); return conf; }
From source file:org.zalando.logbook.httpclient.Request.java
@Override public Charset getCharset() { return Optional.of(request).map(request -> request.getFirstHeader("Content-Type")).map(Header::getValue) .map(ContentType::parse).map(ContentType::getCharset).orElse(StandardCharsets.UTF_8); }
From source file:org.dswarm.graph.gdm.test.GDMResource3Test.java
@Test public void csvVersioningTest() throws IOException { final ObjectNode requestJson = objectMapper.createObjectNode(); requestJson.put("record_identifier_attribute_path", "http://data.slub-dresden.de/resources/1/schema#EBL+ID"); readGDMFromDBThatWasWrittenAsGDM(Optional.of(requestJson), "versioning/Testtitel_MDunitz-US-TitleSummaryReport132968_01.csv.gson", "versioning/Testtitel_MDunitz-US-TitleSummaryReport132968_02.csv.gson", "http://data.slub-dresden.de/resources/2", "http://data.slub-dresden.de/resources/1/schema#RecordType", 36, 35, false, Optional.empty()); }
From source file:com.comphenix.protocol.events.PacketMetadata.java
public static <T> Optional<T> remove(Object packet, String key) { Validate.notNull(key, "Null keys are not permitted!"); if (META_CACHE == null) { return Optional.empty(); }//w w w . j av a2s. c o m List<MetaObject> packetMeta = META_CACHE.getIfPresent(packet); if (packetMeta == null) { return Optional.empty(); } Optional<T> value = Optional.empty(); Iterator<MetaObject> iter = packetMeta.iterator(); while (iter.hasNext()) { MetaObject meta = iter.next(); if (meta.key.equals(key)) { value = Optional.of((T) meta.value); iter.remove(); } } return value; }
From source file:it.polimi.diceH2020.SPACE4Cloud.shared.inputData.old.InstanceData_old.java
public InstanceData_old() { this.scenario = Optional.of(Scenarios.PublicPeakWorkload); this.privateCloudParameters = Optional.empty(); this.mapVMConfigurations = Optional.empty(); this.mapTypeVMs = Optional.empty(); }
From source file:it.polimi.diceH2020.SPACE4Cloud.shared.inputDataMultiProvider.InstanceDataMultiProvider.java
public InstanceDataMultiProvider() { this.id = new String(); this.mapJobProfiles = new JobProfilesMap(); this.mapClassParameters = new ClassParametersMap(); this.mapPublicCloudParameters = new PublicCloudParametersMap(); this.mapJobMLProfiles = new JobMLProfilesMap(); this.validationError = new String(); this.scenario = Optional.of(Scenarios.PublicPeakWorkload); //this.privateCloudParameters = new PrivateCloudParameters(); this.mapVMConfigurations = new VMConfigurationsMap(); }
From source file:co.runrightfast.component.events.impl.ComponentEventFactoryImpl.java
@Override public <DATA> ComponentEvent<DATA> componentEvent(@NonNull final Event<DATA> event, @NonNull final Class<DATA> eventDataType, @NonNull final DATA data, @NonNull final Throwable exception, String... tags) {//from w ww. java2 s . com final ComponentEventImpl.ComponentEventImplBuilder<DATA> builder = ComponentEventImpl.<DATA>builder() .componentId(componentId).event(event).data(Optional.of(data)).exception(Optional.of(exception)); if (ArrayUtils.isNotEmpty(tags)) { return builder.tags(Optional.of(ImmutableSet.copyOf(tags))).build(); } return builder.build(); }
From source file:nu.yona.server.ThymeleafConfigurationTest.java
@Test public void smsTemplateEngine_processBuddyInvitationDutch_dutchTemplateFoundAndExpanded() { String requestingUserFirstName = "john"; String emailAddress = "a@b.c"; String result = buildSms(Optional.of(Locale.forLanguageTag("nl-NL")), requestingUserFirstName, emailAddress);//from ww w .j a v a 2 s .c o m assertThat(result, equalTo("john heeft je uitgenodigd voor Yona. Zie je mail op a@b.c!")); }
From source file:tds.assessment.services.impl.AssessmentWindowImplIntegrationTests.java
@Test public void shouldReturnCachedAssessmentWindow() { AssessmentWindow window = new AssessmentWindow.Builder().withWindowId("id") .withAssessmentKey("SBAC-Mathematics-8").build(); AssessmentWindow window2 = new AssessmentWindow.Builder().withWindowId("id") .withAssessmentKey("SBAC-Mathematics-8-2018").build(); AssessmentWindowParameters properties = new AssessmentWindowParameters.Builder(false, "SBAC_PT", "SBAC-Mathematics-8").build(); AssessmentFormWindowProperties assessmentFormWindowProperties = new AssessmentFormWindowProperties(true, true, "formField", true); when(mockAssessmentWindowQueryRepository.findCurrentAssessmentFormWindows("SBAC_PT", "SBAC-Mathematics-8", 0, 0, 0, 0)).thenReturn(Arrays.asList(window, window2)); when(mockAssessmentWindowQueryRepository.findAssessmentFormWindowProperties("SBAC_PT", "SBAC-Mathematics-8")).thenReturn(Optional.of(assessmentFormWindowProperties)); List<AssessmentWindow> windows1 = assessmentWindowService.findAssessmentWindows(properties); List<AssessmentWindow> windows2 = assessmentWindowService.findAssessmentWindows(properties); assertThat(windows1).containsExactly(window, window2); assertThat(windows2).containsExactly(window, window2); verify(mockAssessmentWindowQueryRepository, times(1)).findCurrentAssessmentFormWindows("SBAC_PT", "SBAC-Mathematics-8", 0, 0, 0, 0); verify(mockAssessmentWindowQueryRepository, times(1)).findAssessmentFormWindowProperties("SBAC_PT", "SBAC-Mathematics-8"); }
From source file:nl.knaw.huygens.alexandria.endpoint.annotation.AnnotationAnnotationsEndpointTest.java
@Test public void testAnnotationURIsAreCorrect() throws JsonProcessingException { AlexandriaAnnotationBody body0 = mock(AlexandriaAnnotationBody.class); when(body0.getType()).thenReturn(""); when(body0.getValue()).thenReturn("Bookmark"); UUID uuid0 = UUID.randomUUID(); AlexandriaAnnotation annotation0 = mock(AlexandriaAnnotation.class); when(annotation0.getId()).thenReturn(uuid0); when(annotation0.getBody()).thenReturn(body0); when(annotation0.isActive()).thenReturn(true); AlexandriaAnnotationBody body1 = mock(AlexandriaAnnotationBody.class); when(body1.getType()).thenReturn("Comment"); when(body1.getValue()).thenReturn("Improbable"); UUID uuid1 = UUID.randomUUID(); AlexandriaAnnotation annotation1 = mock(AlexandriaAnnotation.class); when(annotation1.getId()).thenReturn(uuid1); when(annotation1.getBody()).thenReturn(body1); when(annotation1.isActive()).thenReturn(true); // annotation1 is an annotation on annotation0 when(annotation0.getAnnotations()).thenReturn(ImmutableSet.of(annotation1)); AlexandriaService service = mock(AlexandriaService.class); Optional<AlexandriaAnnotation> optional0 = Optional.of(annotation0); Optional<AlexandriaAnnotation> optional1 = Optional.of(annotation1); when(service.readAnnotation(uuid0)).thenReturn(optional0); when(service.readAnnotation(uuid1)).thenReturn(optional1); AnnotationCreationRequestBuilder requestBuilder = mock(AnnotationCreationRequestBuilder.class); AlexandriaConfiguration configuration = new MockConfiguration(); LocationBuilder locationBuilder = new LocationBuilder(configuration, new EndpointPathResolver()); UUIDParam uuidParam = new UUIDParam(uuid0.toString()); AnnotationAnnotationsEndpoint aa = new AnnotationAnnotationsEndpoint(service, requestBuilder, locationBuilder, uuidParam); Response response = aa.get(); Log.info("response={}", response); @SuppressWarnings("unchecked") Map<String, Object> entity = (Map<String, Object>) response.getEntity(); Log.info("entity={}", entity); // ObjectMapper om = new ObjectMapper(); // Log.info("json={}", om.writeValueAsString(entity)); assertThat(entity).containsKeys("annotations"); @SuppressWarnings("unchecked") Set<AnnotationEntity> list = (Set<AnnotationEntity>) entity.get("annotations"); assertThat(list).hasSize(1);/* w ww . ja v a 2 s .c om*/ assertThat(list.iterator().next().getId()).isEqualTo(uuid1); }