Refine search
/** * Determine a media type for the given resource, if possible. * @param resource the resource to introspect * @return the corresponding media type, or {@code null} if none found */ public static Optional<MediaType> getMediaType(@Nullable Resource resource) { return Optional.ofNullable(resource) .map(Resource::getFilename) .flatMap(MediaTypeFactory::getMediaType); }
/** * Determine a media type for the given resource, if possible. * @param resource the resource to introspect * @return the corresponding media type, or {@code null} if none found */ public static Optional<MediaType> getMediaType(@Nullable Resource resource) { return Optional.ofNullable(resource) .map(Resource::getFilename) .flatMap(MediaTypeFactory::getMediaType); }
/** * Restores properties contained in the file into the given object. * * @param root Root of the hierarchy * @param file Properties file */ public static void restoreProperties(SettingsOwner root, File file) { Optional<Document> odoc = getDocument(file); odoc.flatMap(XmlFormatRevision::getSuitableReader) .map(rev -> rev.xmlInterface) .flatMap(xmlInterface -> odoc.flatMap(xmlInterface::parseXml)) .ifPresent(n -> restoreSettings(root, n)); }
@Override public Optional<RowMapper<?>> build(Type mapType, ConfigRegistry config) { return Optional.of(mapType) .filter(ParameterizedType.class::isInstance) .map(ParameterizedType.class::cast) .filter(maybeMap -> Map.class.equals(maybeMap.getRawType())) .filter(map -> String.class.equals(GenericTypes.findGenericParameter(map, Map.class, 0).orElse(null))) .flatMap(map -> GenericTypes.findGenericParameter(map, Map.class, 1)) .filter(value -> !Object.class.equals(value)) .flatMap(config.get(ColumnMappers.class)::findFor) .map(GenericMapMapper::new); }
private boolean checkIfSupported(String app, String ip, int port) { try { return Optional.ofNullable(appManagement.getDetailApp(app)) .flatMap(e -> e.getMachine(ip, port)) .flatMap(m -> VersionUtils.parseVersion(m.getVersion()) .map(v -> v.greaterOrEqual(version020))) .orElse(true); // If error occurred or cannot retrieve machine info, return true. } catch (Exception ex) { return true; } }
private boolean checkIfSupported(String app, String ip, int port) { try { return Optional.ofNullable(appManagement.getDetailApp(app)) .flatMap(e -> e.getMachine(ip, port)) .flatMap(m -> VersionUtils.parseVersion(m.getVersion()) .map(v -> v.greaterOrEqual(version140))) .orElse(true); // If error occurred or cannot retrieve machine info, return true. } catch (Exception ex) { return true; } }
@Override public Result apply(WindowNode parent, Captures captures, Context context) { // Pulling the descendant WindowNode above projects is done as a part of this rule, as opposed in a // separate rule, because that pullup is not useful on its own, and could be undone by other rules. // For example, a rule could insert a project-off node between adjacent WindowNodes that use different // input symbols. List<ProjectNode> projects = projectCaptures.stream() .map(captures::get) .collect(toImmutableList()); return pullWindowNodeAboveProjects(captures.get(childCapture), projects) .flatMap(newChild -> manipulateAdjacentWindowNodes(parent, newChild, context)) .map(Result::ofPlanNode) .orElse(Result.empty()); }
@Override public boolean isOutboundSupported(ProviderRequest providerRequest, SecurityEnvironment outboundEnv, EndpointConfig outboundConfig) { return providerRequest.securityContext() .user() .flatMap(subject -> subject.publicCredential(TokenCredential.class)) .flatMap(token -> token.getIssuer() .map(issuer -> issuer.endsWith(".google.com"))) .orElse(false); }