List of usage examples for java.util Optional ofNullable
@SuppressWarnings("unchecked") public static <T> Optional<T> ofNullable(T value)
From source file:io.syndesis.model.connection.Action.java
@JsonProperty(access = JsonProperty.Access.READ_ONLY) default Optional<DataShape> getOutputDataShape() { return Optional.ofNullable(getDefinition()).flatMap(ActionDefinition::getOutputDataShape); }
From source file:io.gravitee.repository.jdbc.JdbcUserRepository.java
public Optional<User> findByUsername(String username) throws TechnicalException { return Optional.ofNullable(userJpaConverter.convertTo(internalJpaUserRepository.findOne(username))); }
From source file:io.gravitee.repository.mongodb.management.MongoApiRepository.java
@Override public Optional<Api> findById(String apiId) throws TechnicalException { ApiMongo apiMongo = internalApiRepo.findOne(apiId); return Optional.ofNullable(mapApi(apiMongo)); }
From source file:com.github.ljtfreitas.restify.http.spring.contract.metadata.reflection.SpringWebJavaMethodMetadata.java
public SpringWebJavaMethodMetadata(Method javaMethod) { this.javaMethod = javaMethod; RequestMapping mapping = Optional .ofNullable(AnnotatedElementUtils.findMergedAnnotation(javaMethod, RequestMapping.class)) .orElseThrow(() -> new IllegalArgumentException( "Method [" + javaMethod + "] does not have a @RequestMapping annotation.")); isTrue(mapping.value().length <= 1, "Only single path is allowed."); isTrue(mapping.method().length == 1, "You must set the HTTP method (only one!) of your Java method [" + javaMethod + "]."); this.mapping = new SpringWebRequestMappingMetadata(mapping); }
From source file:com.github.ljtfreitas.restify.spring.configure.RestifyableType.java
private String doName() { return Optional.ofNullable(restifyable.name()).filter(n -> !n.isEmpty()) .orElseGet(() -> objectType.getSimpleName()); }
From source file:com.todo.backend.web.rest.UserApi.java
@RequestMapping(value = "/user/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @Timed// www .j a va 2 s . c o m @Transactional(readOnly = true) @PreAuthorize("hasAuthority('ADMIN')") public ResponseEntity<ReadUserResponse> readUser(@PathVariable Long id) { log.debug("GET /user/{}", id); final Optional<User> result = Optional.ofNullable(userRepository.findOne(id)); if (result.isPresent()) { return ResponseEntity.ok().body(convertToReadUserResponse(result.get())); } return new ResponseEntity<>(HttpStatus.NOT_FOUND); }
From source file:io.gravitee.repository.mongodb.management.MongoEventRepository.java
@Override public Optional<Event> findById(String id) throws TechnicalException { logger.debug("Find event by ID [{}]", id); EventMongo event = internalEventRepo.findOne(id); Event res = mapEvent(event);//from w w w .java 2 s.co m logger.debug("Find event by ID [{}] - Done", id); return Optional.ofNullable(res); }
From source file:io.knotx.knot.action.domain.FormEntity.java
private static Optional<String> getFormIdentifierFromRequest(KnotContext knotContext, String formIdAttrName) { return Optional.ofNullable(knotContext.getClientRequest().getFormAttributes().get(formIdAttrName)); }
From source file:spring.travel.site.model.user.User.java
@JsonIgnore public Optional<Address> getAddress() { return Optional.ofNullable(a); }
From source file:com.culturedear.counterpoint.XmlRestController.java
@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_XML_VALUE) public ResponseEntity<Object> write(@RequestBody CounterpointModel counterpointModel) { // prepare response XML out CounterpointGenerator cg = new CounterpointGenerator(); cg.fillRhyPat();//from w w w .j a va 2 s. c om int[] cf = counterpointModel.getMainMelody(); cg.setCantusFirmus(cf); int[] vbs = counterpointModel.getPartsInitialNotes(); CounterpointSolution counterpointSolution = cg.anySpecies(counterpointModel.getScaleMode(), vbs, cf.length, counterpointModel.getCounterpointSpecies(), counterpointModel.getRulePenalties()); ScorePartwise scorePartwise = null; try { scorePartwise = counterpointSolution.toScorePartwise(); } catch (NullPointerException ex) { scorePartwise = null; } return Optional.ofNullable(scorePartwise).map(cm -> new ResponseEntity<>((Object) cm, HttpStatus.OK)) .orElse(new ResponseEntity<>("Could not compute the counterpoint.", HttpStatus.INTERNAL_SERVER_ERROR)); }