List of usage examples for java.util Optional of
public static <T> Optional<T> of(T value)
From source file:org.jhk.pulsing.web.dao.prod.db.sql.MySqlUserDao.java
public Optional<User> getUser(UserId userId) { _LOGGER.debug("MySqlUserDao.getUser" + userId); MUser mUser = getSession().find(MUser.class, userId.getId()); if (mUser != null) { _LOGGER.debug("User is " + mUser); return Optional.of(AvroMySqlMappers.mySqlToAvro(mUser)); } else {/*from www . java2 s. c o m*/ return Optional.empty(); } }
From source file:org.trustedanalytics.cloud.cc.api.CcOrg.java
@JsonIgnore public String getStatus() { Optional<CcOrg> org = Optional.of(this); return org.map(CcOrg::getEntity).map(CcOrgEntity::getStatus).orElse(null); }
From source file:com.qpark.eip.core.sftp.SftpDownload.java
/** * Get the {@link Optional} of the file content. This could be empty, * because possibly another thread already read the content of the file path * and removed it.//w ww. jav a2 s.c o m * * @param filePath * the file path. * @return the {@link Optional} of the file content. */ private Optional<byte[]> getFilePathContent(final String filePath) { Optional<byte[]> value = Optional.empty(); try { final byte[] fileContent = this.sftpGateway.retrieveAndRead(filePath); value = Optional.of(fileContent); } catch (final Exception e) { // The file was eventually read by another thread. } return value; }
From source file:org.openwms.tms.RedirectTODocumentation.java
public @Test void testRedirectToUnknownLocationGroupButLoc() throws Exception { // setup ...//from w w w. j a v a 2 s . co m CreateTransportOrderVO vo = createTO(); postTOAndValidate(vo, NOTLOGGED); vo.setTarget(UNKNOWN); given(commonGateway.getLocationGroup(UNKNOWN)).willReturn(Optional.empty()); given(commonGateway.getLocation(UNKNOWN)).willReturn(Optional.of(INIT_LOC)); // test ... sendPatch(vo, status().isNoContent(), "to-patch-target-unknown-loc"); }
From source file:jp.toastkid.script.runner.JavaScriptRunner.java
@Override public Optional<String> run(final String script) { if (StringUtils.isEmpty(script)) { return Optional.empty(); }//from w w w .j a v a 2 s . c o m final StringBuilder result = new StringBuilder(); try (final StringWriter writer = new StringWriter();) { final ScriptContext context = engine.getContext(); context.setWriter(writer); context.setErrorWriter(writer); final java.lang.Object run = engine.eval(script); result.append(writer.toString()).append(LINE_SEPARATOR); if (run != null) { result.append("return = ").append(run.toString()); } writer.close(); } catch (final CompilationFailedException | IOException | ScriptException e) { e.printStackTrace(); result.append("Occurred Exception.").append(LINE_SEPARATOR).append(e.getMessage()); } return Optional.of(result.toString()); }
From source file:ch.zweivelo.renderer.simple.shapes.ShapeTest.java
@Test public void testIntersect() throws Exception { Shape testShape;//www .j a v a2 s. com Optional<CollisionInformation> collisionInformationOptional; testShape = ray1 -> Optional.empty(); collisionInformationOptional = testShape.intersect(ray); assertNotNull(collisionInformationOptional); assertFalse(collisionInformationOptional.isPresent()); testShape = ray1 -> Optional.of(1d); collisionInformationOptional = testShape.intersect(ray); assertNotNull(collisionInformationOptional); CollisionInformation collisionInformation = collisionInformationOptional.get(); assertNotNull(collisionInformation.getShape()); assertEquals(Vector3D.PLUS_I, collisionInformation.getPoint()); }
From source file:org.leandreck.endpoints.examples.abstractbase.BaseEndpoint.java
@RequestMapping(value = "/{id}", method = GET, produces = APPLICATION_JSON_VALUE) public Optional<T> read(@PathVariable String id) { // do something return Optional.of(useLessField); }
From source file:fi.luontola.cqrshotel.ApiControllerTest.java
@Before public void initMocks() { stub(pricingEngine.getAccommodationPrice(any(LocalDate.class))).toReturn(Optional.of(pricePerDay)); }
From source file:com.ikanow.aleph2.data_model.utils.TestCrudServiceUtils.java
@Test public void test_readOnlyCrudService() { final MockManagementCrudService<String> mock_crud = new MockManagementCrudService<String>(); final ReadOnlyCrudService<String> ro_crud = new ReadOnlyCrudService<>(mock_crud); // Add a few dummy entries mock_crud.setMockValues(Arrays.asList("test1", "test2")); test_readOnly(ro_crud, mock_crud);/*from ww w . j ava 2s . c o m*/ assertEquals(Optional.of(ro_crud), ro_crud.getCrudService()); }
From source file:org.trustedanalytics.cloud.cc.api.CcSpace.java
@JsonIgnore public UUID getOrgGuid() { Optional<CcSpace> space = Optional.of(this); return space.map(CcSpace::getEntity).map(CcSpaceEntity::getOrgGuid).orElse(null); }