List of usage examples for java.util Optional of
public static <T> Optional<T> of(T value)
From source file:co.runrightfast.core.hazelcast.impl.TypesafeHazelcastConfig.java
/** * @param name Hazelcast instance name// ww w . jav a 2 s .c o m * @param config TypeSafe typeSafeConfig * @param serializerConfigs can be empty */ public TypesafeHazelcastConfig(@NonNull final String name, @NonNull final com.typesafe.config.Config config, @NonNull final Set<SerializerConfig> serializerConfigs) { this.hazelcastConfig = createHazelcastConfig(name, config, serializerConfigs.isEmpty() ? Optional.empty() : Optional.of(ImmutableSet.copyOf(serializerConfigs))); }
From source file:basedefense.client.version.ModificationVersionCheck.java
/** * Checks the modification version.//from w w w . j av a2 s . c o m * * @return The version. */ public Optional<String> check() { // We will only run this check once as this check may take a lot of time to process if (this.latestVersion != null) return this.latestVersion; InputStreamReader inputStreamReader = null; try { HttpGet getRequest = new HttpGet(API_URL + String.format(API_PATTERN, "LordAkkarin", "BaseDefense2")); HttpResponse response = this.httpClient.execute(getRequest); Preconditions.checkState(response.getStatusLine().getStatusCode() == 200, "Expected status code 200 but received %s", response.getStatusLine()); HttpEntity entity = response.getEntity(); inputStreamReader = new InputStreamReader(entity.getContent()); Gson gson = new Gson(); JsonObject object = gson.fromJson(inputStreamReader, JsonObject.class); Preconditions.checkState(object.has("tag_name"), "No valid version found."); this.latestVersion = Optional.of(object.get("tag_name").getAsString()); } catch (Exception ex) { BaseDefenseModification.getInstance().getLogger() .warn("Unable to retrieve version information: " + ex.getMessage(), ex); this.latestVersion = Optional.empty(); } finally { IOUtils.closeQuietly(inputStreamReader); } return this.latestVersion; }
From source file:com.ikanow.aleph2.examples.client.services.TestExampleClientService.java
@Before public void setup() throws Exception { final String temp_dir = System.getProperty("java.io.tmpdir") + File.separator; // OK we're going to use guice, it was too painful doing this by hand... final Config config = ConfigFactory .parseReader(new InputStreamReader(this.getClass().getResourceAsStream("/example_test.properties"))) .withValue("globals.local_root_dir", ConfigValueFactory.fromAnyRef(temp_dir)) .withValue("globals.local_cached_jar_dir", ConfigValueFactory.fromAnyRef(temp_dir)) .withValue("globals.distributed_root_dir", ConfigValueFactory.fromAnyRef(temp_dir)) .withValue("globals.local_yarn_config_dir", ConfigValueFactory.fromAnyRef(temp_dir)); final Injector app_injector = ModuleUtils.createTestInjector(Arrays.asList(), Optional.of(config)); app_injector.injectMembers(this); _core_mgmt_db = _context.getCoreManagementDbService(); }
From source file:org.ow2.proactive.workflow_catalog.rest.controller.WorkflowRevisionControllerIntegrationTest.java
@Before public void setup() throws IOException { bucket = bucketRepository.save(new Bucket("bucket")); firstWorkflowRevision = workflowRevisionService.createWorkflowRevision(bucket.getId(), Optional.empty(), IntegrationTestUtil.getWorkflowAsByteArray("workflow.xml")); secondWorkflowRevision = workflowRevisionService.createWorkflowRevision(bucket.getId(), Optional.of(firstWorkflowRevision.id), IntegrationTestUtil.getWorkflowAsByteArray("workflow-updated.xml")); }
From source file:com.ikanow.aleph2.security.service.IkanowV1DataGroupRoleProvider.java
@SuppressWarnings("unchecked") protected void initDb() { if (_core_management_db == null) { _core_management_db = _context.getCoreManagementDbService().readOnlyVersion(); }//from w ww .ja v a 2s. co m if (_underlying_management_db == null) { _underlying_management_db = _context.getService(IManagementDbService.class, Optional.empty()).get(); } if (personDb == null) { String personOptions = "social.person"; personDb = _underlying_management_db .getUnderlyingPlatformDriver(ICrudService.class, Optional.of(personOptions)).get(); } if (sourceDb == null) { String ingestOptions = "ingest.source"; sourceDb = _underlying_management_db .getUnderlyingPlatformDriver(ICrudService.class, Optional.of(ingestOptions)).get(); } if (bucketDb == null) { bucketDb = _core_management_db.getDataBucketStore(); } if (shareDb == null) { String shareOptions = "social.share"; shareDb = _underlying_management_db .getUnderlyingPlatformDriver(ICrudService.class, Optional.of(shareOptions)).get(); } if (communityDb == null) { String communityOptions = "social.community"; communityDb = _underlying_management_db .getUnderlyingPlatformDriver(ICrudService.class, Optional.of(communityOptions)).get(); } }
From source file:net.hamnaberg.json.generator.CollectionGeneratorTest.java
@Test public void templateCollection() throws Exception { JsonNode collection = new Collection.Builder(COLLECTION_URI) .withTemplate(Template/*from ww w .ja va2 s . c o m*/ .create(Arrays.asList(Property.value("one", Optional.of("One"), Optional.<Value>empty())))) .build().asJson(); assertNotNull(collection); assertEquals("1.0", collection.get("version").asText()); assertEquals(COLLECTION_URI.toString(), collection.get("href").asText()); assertEquals(createTemplate(), collection.get("template")); }
From source file:org.ulyssis.ipp.snapshot.Snapshot.java
public Optional<Long> getId() { if (id != -1) return Optional.of(id); else/*from www.jav a2 s .c om*/ return Optional.empty(); }
From source file:com.ejisto.core.classloading.javassist.ObjectEditor.java
private static Optional<String> getFieldMarker(String fieldName) { if (StringUtils.isBlank(fieldName)) { return Optional.empty(); }// w w w. j av a 2s. c o m return Optional.of(PREFIX + fieldName); }
From source file:com.spotify.apollo.http.server.ApolloRequestHandlerTest.java
@Test public void shouldReturnPayloadWhenPresent() throws Exception { httpServletRequest.setContent("hi there".getBytes(StandardCharsets.UTF_8)); assertThat(requestHandler.asApolloRequest(httpServletRequest).payload(), is(Optional.of(ByteString.encodeUtf8("hi there")))); }
From source file:com.devicehive.defects.Defect157NotificationTest.java
@Before public void prepareNotifications() { DeviceClassEquipmentVO equipment = DeviceFixture.createEquipmentVO(); DeviceClassUpdate deviceClass = DeviceFixture.createDeviceClass(); deviceClass.setEquipment(Optional.of(Collections.singleton(equipment))); NetworkVO network = DeviceFixture.createNetwork(); DeviceUpdate deviceUpdate = DeviceFixture.createDevice(guid); deviceUpdate.setDeviceClass(Optional.of(deviceClass)); deviceUpdate.setNetwork(Optional.of(network)); // register device Response response = performRequest("/device/" + guid, "PUT", emptyMap(), singletonMap(HttpHeaders.AUTHORIZATION, tokenAuthHeader(ACCESS_KEY)), deviceUpdate, NO_CONTENT, null);// w w w . java 2 s . c om assertNotNull(response); { DeviceNotification notification = createDeviceNotification("c1"); notification = performRequest("/device/" + guid + "/notification", "POST", emptyMap(), singletonMap(HttpHeaders.AUTHORIZATION, tokenAuthHeader(ACCESS_KEY)), notification, CREATED, DeviceNotification.class); assertNotNull(notification.getId()); } { DeviceNotification notification = createDeviceNotification("c2"); notification = performRequest("/device/" + guid + "/notification", "POST", emptyMap(), singletonMap(HttpHeaders.AUTHORIZATION, tokenAuthHeader(ACCESS_KEY)), notification, CREATED, DeviceNotification.class); assertNotNull(notification.getId()); } { DeviceNotification notification = createDeviceNotification("c3"); notification = performRequest("/device/" + guid + "/notification", "POST", emptyMap(), singletonMap(HttpHeaders.AUTHORIZATION, tokenAuthHeader(ACCESS_KEY)), notification, CREATED, DeviceNotification.class); assertNotNull(notification.getId()); } }