Search in sources :

Example 51 with Predicate

use of java.util.function.Predicate in project kie-wb-common by kiegroup.

the class AbstractProcessFilteredNodeProvider method findElements.

protected Collection<Pair<Object, String>> findElements(final Predicate<Node> filter, final Function<Node, Pair<Object, String>> mapper) {
    final Diagram diagram = sessionManager.getCurrentSession().getCanvasHandler().getDiagram();
    @SuppressWarnings("unchecked") Iterable<Node> it = diagram.getGraph().nodes();
    return StreamSupport.stream(it.spliterator(), false).filter(filter).map(mapper).filter(pair -> pair != null).collect(Collectors.toSet());
}
Also used : SelectorData(org.kie.workbench.common.forms.dynamic.model.config.SelectorData) FormRenderingContext(org.kie.workbench.common.forms.dynamic.service.shared.FormRenderingContext) Predicate(java.util.function.Predicate) Collection(java.util.Collection) SelectorDataProvider(org.kie.workbench.common.forms.dynamic.model.config.SelectorDataProvider) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) TreeMap(java.util.TreeMap) Map(java.util.Map) StreamSupport(java.util.stream.StreamSupport) Comparator(java.util.Comparator) SessionManager(org.kie.workbench.common.stunner.core.client.api.SessionManager) Pair(org.uberfire.commons.data.Pair) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Node(org.kie.workbench.common.stunner.core.graph.Node) Node(org.kie.workbench.common.stunner.core.graph.Node) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram)

Example 52 with Predicate

use of java.util.function.Predicate in project ArachneCentralAPI by OHDSI.

the class WebSecurityConfig method urlToHostUrlMapConverter.

public static LinkedHashMap<String, URI> urlToHostUrlMapConverter(List<String> portalUrlWhiteList) {
    final Pattern urlPattern = Pattern.compile("(https?://)([^:^/]*)(:\\\\d*)?(.*)?");
    final Predicate<String> urlFilterPredicate = s -> {
        final Matcher matcher = urlPattern.matcher(s);
        return matcher.matches();
    };
    return portalUrlWhiteList.stream().filter(urlFilterPredicate).map(URI::create).collect(Collectors.toMap(URI::getHost, s -> s, (host1, host2) -> host1, LinkedHashMap::new));
}
Also used : FilterChain(javax.servlet.FilterChain) BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder) ServletException(javax.servlet.ServletException) HostNameIsNotInServiceException(com.odysseusinc.arachne.portal.security.HostNameIsNotInServiceException) LoggerFactory(org.slf4j.LoggerFactory) ClassPathResource(org.springframework.core.io.ClassPathResource) UserDetailsService(org.springframework.security.core.userdetails.UserDetailsService) Autowired(org.springframework.beans.factory.annotation.Autowired) OncePerRequestFilter(org.springframework.web.filter.OncePerRequestFilter) HttpSecurity(org.springframework.security.config.annotation.web.builders.HttpSecurity) StringUtils(org.apache.commons.lang3.StringUtils) BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) LinkedHashMap(java.util.LinkedHashMap) Value(org.springframework.beans.factory.annotation.Value) WebSecurityConfigurerAdapter(org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter) HttpServletRequest(javax.servlet.http.HttpServletRequest) AuthenticationManagerBuilder(org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder) ArachnePasswordValidator(com.odysseusinc.arachne.portal.security.passwordvalidator.ArachnePasswordValidator) Matcher(java.util.regex.Matcher) Roles(com.odysseusinc.arachne.portal.security.Roles) Map(java.util.Map) AuthenticationSystemTokenFilter(com.odysseusinc.arachne.portal.security.AuthenticationSystemTokenFilter) URI(java.net.URI) Logger(org.slf4j.Logger) AuthenticationManager(org.springframework.security.authentication.AuthenticationManager) ExpressionUrlAuthorizationConfigurer(org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer) DataNodeAuthenticationProvider(com.odysseusinc.arachne.portal.security.DataNodeAuthenticationProvider) Predicate(java.util.function.Predicate) HttpServletResponse(javax.servlet.http.HttpServletResponse) HttpMethod(org.springframework.http.HttpMethod) IOException(java.io.IOException) SecurityConfigException(com.odysseusinc.arachne.portal.exception.SecurityConfigException) BaseDataNodeService(com.odysseusinc.arachne.portal.service.BaseDataNodeService) Collectors(java.util.stream.Collectors) Configuration(org.springframework.context.annotation.Configuration) List(java.util.List) PasswordEncoder(org.springframework.security.crypto.password.PasswordEncoder) UsernamePasswordAuthenticationFilter(org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter) PasswordValidatorBuilder(com.odysseusinc.arachne.portal.security.passwordvalidator.PasswordValidatorBuilder) EnableWebSecurity(org.springframework.security.config.annotation.web.configuration.EnableWebSecurity) PostConstruct(javax.annotation.PostConstruct) SessionCreationPolicy(org.springframework.security.config.http.SessionCreationPolicy) EntryPointUnauthorizedHandler(com.odysseusinc.arachne.portal.security.EntryPointUnauthorizedHandler) Pattern(java.util.regex.Pattern) Bean(org.springframework.context.annotation.Bean) AuthenticationTokenFilter(com.odysseusinc.arachne.portal.security.AuthenticationTokenFilter) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher)

Example 53 with Predicate

use of java.util.function.Predicate in project engineblock by engineblock.

the class CoreServices method getInputDispenser.

// public static <A extends Activity> Optional<IntPredicateDispenser> getResultFilterDispenser(A activity) {
// Optional<IntPredicateDispenser> intPredicateDispenser = new SimpleConfig(activity, "resultfilter")
// .getString("type")
// .flatMap(ExperimentalResultFilterType.FINDER::get)
// .map(rft -> rft.getFilterDispenser(activity));
// return intPredicateDispenser;
// }
// 
public static <A extends Activity> InputDispenser getInputDispenser(A activity) {
    String inputTypeName = new SimpleConfig(activity, "input").getString("type").orElse("targetrate");
    InputType inputType = InputType.FINDER.getOrThrow(inputTypeName);
    InputDispenser dispenser = inputType.getInputDispenser(activity);
    Optional<Predicate<ResultReadable>> inputFilterDispenser = getInputFilter(activity);
    if (inputFilterDispenser.isPresent()) {
        dispenser = new FilteringInputDispenser(dispenser, inputFilterDispenser.get());
    }
    return dispenser;
}
Also used : SimpleConfig(io.engineblock.util.SimpleConfig) InputType(io.engineblock.activityapi.input.InputType) InputDispenser(io.engineblock.activityapi.input.InputDispenser) Predicate(java.util.function.Predicate)

Example 54 with Predicate

use of java.util.function.Predicate in project oap by oaplatform.

the class MemoryStorage method updateObject.

protected Optional<? extends Metadata<T>> updateObject(String id, Predicate<T> predicate, Function<T, T> update, Supplier<T> init) {
    return lockStrategy.synchronizedOn(id, () -> {
        Metadata<T> metadata = data.get(id);
        if (metadata == null) {
            if (init == null)
                return Optional.empty();
            metadata = data.computeIfAbsent(id, (id1) -> {
                val object = init.get();
                identifier.set(object, id);
                checkConstraints(object);
                return new Metadata<>(object);
            });
            data.put(id, metadata);
            metadata.setUpdated();
        } else {
            if (predicate.test(metadata.object)) {
                val newObject = update.apply(Binder.json.clone(metadata.object));
                checkConstraints(newObject);
                identifier.set(newObject, id);
                metadata.update(newObject);
            } else {
                return Optional.empty();
            }
        }
        return Optional.of(metadata);
    });
}
Also used : Binder(oap.json.Binder) Optionals(oap.util.Optionals) Iterator(java.util.Iterator) Maps(oap.util.Maps) Predicate(java.util.function.Predicate) Collection(java.util.Collection) lombok.val(lombok.val) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Function(java.util.function.Function) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) Consumer(java.util.function.Consumer) List(java.util.List) Map(java.util.Map) Optional(java.util.Optional) Stream(oap.util.Stream) lombok.val(lombok.val)

Example 55 with Predicate

use of java.util.function.Predicate in project vorto by eclipse.

the class GeneratorMojo method loadInformationModels.

private byte[] loadInformationModels() throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final ZipOutputStream zaos = new ZipOutputStream(baos);
    Files.walk(Paths.get((project.getBasedir().toURI()))).filter(new Predicate<Path>() {

        public boolean test(Path path) {
            return !path.toFile().isDirectory() && (path.getFileName().toString().endsWith(ModelType.InformationModel.getExtension()) || path.getFileName().toString().endsWith(ModelType.Functionblock.getExtension()) || path.getFileName().toString().endsWith(ModelType.Datatype.getExtension()) || path.getFileName().toString().endsWith(ModelType.Mapping.getExtension()));
        }
    }).forEach(new Consumer<Path>() {

        public void accept(Path t) {
            addToZip(zaos, t);
        }
    });
    return baos.toByteArray();
}
Also used : Path(java.nio.file.Path) ZipOutputStream(java.util.zip.ZipOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Predicate(java.util.function.Predicate)

Aggregations

Predicate (java.util.function.Predicate)589 List (java.util.List)266 ArrayList (java.util.ArrayList)170 Collectors (java.util.stream.Collectors)167 Map (java.util.Map)164 Set (java.util.Set)137 Test (org.junit.Test)133 IOException (java.io.IOException)122 Collections (java.util.Collections)118 Arrays (java.util.Arrays)110 HashMap (java.util.HashMap)105 Collection (java.util.Collection)93 Optional (java.util.Optional)87 HashSet (java.util.HashSet)85 Stream (java.util.stream.Stream)69 Function (java.util.function.Function)61 File (java.io.File)60 Iterator (java.util.Iterator)55 Logger (org.slf4j.Logger)53 LoggerFactory (org.slf4j.LoggerFactory)52