use of java.util.function.Function in project neo4j by neo4j.
the class Settings method advertisedAddress.
public static BaseSetting<AdvertisedSocketAddress> advertisedAddress(String name, Setting<ListenSocketAddress> listenAddressSetting) {
return new ScopeAwareSetting<AdvertisedSocketAddress>() {
@Override
protected String provideName() {
return name;
}
@Override
public String getDefaultValue() {
return default_advertised_address.getDefaultValue() + ":" + LISTEN_SOCKET_ADDRESS.apply(listenAddressSetting.getDefaultValue()).socketAddress().getPort();
}
@Override
public AdvertisedSocketAddress from(Configuration config) {
return config.get(this);
}
@Override
public AdvertisedSocketAddress apply(Function<String, String> config) {
ListenSocketAddress listenSocketAddress = listenAddressSetting.apply(config);
String hostname = default_advertised_address.apply(config);
int port = listenSocketAddress.socketAddress().getPort();
String name = name();
String value = config.apply(name);
return SocketAddressFormat.socketAddress(name, value, hostname, port, AdvertisedSocketAddress::new);
}
@Override
public void withScope(Function<String, String> scopingRule) {
super.withScope(scopingRule);
listenAddressSetting.withScope(scopingRule);
}
@Override
public String valueDescription() {
return ADVERTISED_SOCKET_ADDRESS.toString();
}
};
}
use of java.util.function.Function in project jersey by jersey.
the class OutboundMessageContext method getAcceptableMediaTypes.
/**
* Get a list of media types that are acceptable for the message.
*
* @return a read-only list of requested message media types sorted according
* to their q-value, with highest preference first.
*/
@SuppressWarnings("unchecked")
public List<MediaType> getAcceptableMediaTypes() {
final List<Object> values = headers.get(HttpHeaders.ACCEPT);
if (values == null || values.isEmpty()) {
return WILDCARD_ACCEPTABLE_TYPE_SINGLETON_LIST;
}
final List<MediaType> result = new ArrayList<>(values.size());
final RuntimeDelegate rd = RuntimeDelegate.getInstance();
boolean conversionApplied = false;
for (final Object value : values) {
try {
if (value instanceof MediaType) {
final AcceptableMediaType _value = AcceptableMediaType.valueOf((MediaType) value);
// true if value was not an instance of AcceptableMediaType already
conversionApplied = _value != value;
result.add(_value);
} else {
conversionApplied = true;
result.addAll(HttpHeaderReader.readAcceptMediaType(HeaderUtils.asString(value, rd)));
}
} catch (java.text.ParseException e) {
throw exception(HttpHeaders.ACCEPT, value, e);
}
}
if (conversionApplied) {
// cache converted
headers.put(HttpHeaders.ACCEPT, result.stream().map((Function<MediaType, Object>) mediaType -> mediaType).collect(Collectors.toList()));
}
return Collections.unmodifiableList(result);
}
use of java.util.function.Function in project jersey by jersey.
the class OutboundMessageContext method getAcceptableLanguages.
/**
* Get a list of languages that are acceptable for the message.
*
* @return a read-only list of acceptable languages sorted according
* to their q-value, with highest preference first.
*/
public List<Locale> getAcceptableLanguages() {
final List<Object> values = headers.get(HttpHeaders.ACCEPT_LANGUAGE);
if (values == null || values.isEmpty()) {
return Collections.singletonList(new AcceptableLanguageTag("*", null).getAsLocale());
}
final List<Locale> result = new ArrayList<Locale>(values.size());
final RuntimeDelegate rd = RuntimeDelegate.getInstance();
boolean conversionApplied = false;
for (final Object value : values) {
if (value instanceof Locale) {
result.add((Locale) value);
} else {
conversionApplied = true;
try {
result.addAll(HttpHeaderReader.readAcceptLanguage(HeaderUtils.asString(value, rd)).stream().map(LanguageTag::getAsLocale).collect(Collectors.toList()));
} catch (java.text.ParseException e) {
throw exception(HttpHeaders.ACCEPT_LANGUAGE, value, e);
}
}
}
if (conversionApplied) {
// cache converted
headers.put(HttpHeaders.ACCEPT_LANGUAGE, result.stream().map((Function<Locale, Object>) locale -> locale).collect(Collectors.toList()));
}
return Collections.unmodifiableList(result);
}
use of java.util.function.Function in project jersey by jersey.
the class ParameterInjectionBinder method configure.
@Override
public void configure() {
// Param converter providers
// TODO: Replace by non-di version
bind(new ParamConverters.AggregatedProvider()).to(ParamConverterProvider.class);
Provider<ContainerRequest> requestProvider = Injections.getProvider(injectionManager, ContainerRequest.class);
Provider<AsyncContext> asyncContextProvider = Injections.getProvider(injectionManager, AsyncContext.class);
Function<Class<? extends Configuration>, Configuration> clientConfigProvider = clientConfigClass -> Injections.getOrCreate(injectionManager, clientConfigClass);
// Param Converters must be initialized Lazy and created at the time of the call on extractor
LazyValue<ParamConverterFactory> lazyParamConverterFactory = Values.lazy((Value<ParamConverterFactory>) () -> new ParamConverterFactory(Providers.getProviders(injectionManager, ParamConverterProvider.class), Providers.getCustomProviders(injectionManager, ParamConverterProvider.class)));
LazyValue<Configuration> lazyConfiguration = Values.lazy((Value<Configuration>) () -> injectionManager.getInstance(Configuration.class));
MultivaluedParameterExtractorFactory paramExtractor = new MultivaluedParameterExtractorFactory(lazyParamConverterFactory);
bind(paramExtractor).to(MultivaluedParameterExtractorProvider.class);
// Parameter injection value providers
AsyncResponseValueSupplierProvider asyncSupplier = new AsyncResponseValueSupplierProvider(asyncContextProvider);
bindValueSupplier(asyncSupplier);
CookieParamValueSupplierProvider cookieSupplier = new CookieParamValueSupplierProvider(paramExtractor, requestProvider);
bindValueSupplier(cookieSupplier);
EntityParamValueSupplierProvider entitySupplier = new EntityParamValueSupplierProvider(paramExtractor, requestProvider);
bindValueSupplier(entitySupplier);
FormParamValueSupplierProvider formSupplier = new FormParamValueSupplierProvider(paramExtractor, requestProvider);
bindValueSupplier(formSupplier);
HeaderParamValueSupplierProvider headerSupplier = new HeaderParamValueSupplierProvider(paramExtractor, requestProvider);
bindValueSupplier(headerSupplier);
MatrixParamValueSupplierProvider matrixSupplier = new MatrixParamValueSupplierProvider(paramExtractor, requestProvider);
bindValueSupplier(matrixSupplier);
PathParamValueSupplierProvider pathSupplier = new PathParamValueSupplierProvider(paramExtractor, requestProvider);
bindValueSupplier(pathSupplier);
QueryParamValueSupplierProvider querySupplier = new QueryParamValueSupplierProvider(paramExtractor, requestProvider);
bindValueSupplier(querySupplier);
WebTargetValueSupplierProvider webTargetSupplier = new WebTargetValueSupplierProvider(requestProvider, lazyConfiguration, clientConfigProvider);
bindValueSupplier(webTargetSupplier);
BeanParamValueSupplierProvider beanSupplier = new BeanParamValueSupplierProvider(paramExtractor, requestProvider, injectionManager);
bindValueSupplier(beanSupplier);
// Register InjectionResolvers with param providers
// TODO: RENAME INJECTION RESOLVER
bind(new ParamInjectionResolver<>(cookieSupplier, CookieParam.class));
bind(new ParamInjectionResolver<>(formSupplier, FormParam.class));
bind(new ParamInjectionResolver<>(headerSupplier, HeaderParam.class));
bind(new ParamInjectionResolver<>(matrixSupplier, MatrixParam.class));
bind(new ParamInjectionResolver<>(querySupplier, QueryParam.class));
bind(new ParamInjectionResolver<>(pathSupplier, PathParam.class));
bind(new ParamInjectionResolver<>(asyncSupplier, Suspended.class));
bind(new ParamInjectionResolver<>(webTargetSupplier, Uri.class));
bind(new ParamInjectionResolver<>(beanSupplier, BeanParam.class));
// Delegated value supplier for Context InjectionResolver which is implemented directly in DI provider
ContextInjectionResolver contextInjectionResolver = injectionManager.getInstance(ContextInjectionResolver.class);
bind(new DelegatedInjectionValueSupplierProvider(contextInjectionResolver, injectionManager::createForeignDescriptor)).to(ValueSupplierProvider.class);
}
use of java.util.function.Function in project POL-POM-5 by PlayOnLinux.
the class NashornEngineFactory method createEngine.
NashornEngine createEngine() {
final Set<List<String>> includedScripts = new HashSet<>();
final NashornEngine nashornEngine = new NashornEngine(new ScriptEngineManager().getEngineByName("nashorn"));
nashornEngine.eval(new InputStreamReader(getClass().getResourceAsStream("utils.js")), this::throwException);
nashornEngine.put("Bean", (Function<String, Object>) title -> applicationContext.getBean(title), this::throwException);
nashornEngine.put("SetupWizard", (Function<String, UiSetupWizardImplementation>) (name) -> {
final UiSetupWizardImplementation uiSetupWizardImplementation = uiSetupWizardFactory.create(name);
nashornEngine.addErrorHandler(e -> uiSetupWizardImplementation.close());
return uiSetupWizardImplementation;
}, this::throwException);
nashornEngine.put("EngineProgressUi", (Function<String, UiProgressWizardImplementation>) (name) -> {
final UiProgressWizardImplementation uiProgressWizardImplementation = uiProgressWizardFactory.create(name);
nashornEngine.addErrorHandler(e -> uiProgressWizardImplementation.close());
return uiProgressWizardImplementation;
}, this::throwException);
nashornEngine.put("include", (Consumer<ScriptObjectMirror>) args -> {
final String[] arguments = args.to(String[].class);
final String script = scriptFetcher.getScript(arguments);
if (script == null) {
throwException(new ScriptException(Arrays.asList(arguments).toString() + " is not found"));
}
if (includedScripts.add(Arrays.asList(arguments))) {
nashornEngine.eval("//# sourceURL=" + Arrays.asList(arguments).toString() + "\n" + script, this::throwException);
}
}, this::throwException);
return nashornEngine;
}
Aggregations