List of usage examples for java.util.function Supplier get
T get();
From source file:org.briljantframework.array.AbstractDoubleArray.java
@Override public <T> T collect(Supplier<T> supplier, ObjDoubleConsumer<T> consumer) { T accumulator = supplier.get(); for (int i = 0; i < size(); i++) { consumer.accept(accumulator, get(i)); }//from w ww. j av a 2s . co m return accumulator; }
From source file:org.briljantframework.data.vector.Vector.java
/** * Creates a vector with the specified size consisting of the values given by the supplier * * <pre>/*from w w w. j a v a 2s . c om*/ * { * @code * Vector.Builder b; * for (int i = 0; i < size; i++) { * b.plus(supplier.get()); * } * } * </pre> */ static Vector fromSupplier(Supplier<Object> supplier, int size) { if (size < 1) { throw new UnsupportedOperationException(); } Object value = supplier.get(); Vector.Builder builder = VectorType.of(value).newBuilder().add(value); for (int i = 1; i < size; i++) { builder.add(supplier.get()); } return builder.build(); }
From source file:org.codelibs.fess.timer.SystemMonitorTarget.java
protected StringBuilder append(final StringBuilder buf, final String key, final Supplier<Object> supplier) { buf.append('"').append(key).append("\":"); try {/*from ww w .ja v a 2 s . c o m*/ final Object value = supplier.get(); if (value == null) { buf.append("null"); } else if (value instanceof Integer) { buf.append(((Integer) value).intValue()); } else if (value instanceof Long) { buf.append(((Long) value).longValue()); } else if (value instanceof Short) { buf.append(((Short) value).shortValue()); } else if (value instanceof double[]) { buf.append(Arrays.toString((double[]) value)); } else { buf.append('"').append(StringEscapeUtils.escapeJson(value.toString())).append('"'); } } catch (final Exception e) { buf.append("null"); } return buf; }
From source file:org.codice.ddf.admin.application.service.migratable.TaskList.java
/** * Adds a new or retrieves an already registered compound task to be executed for a specific * operation. This method expects to be called consistently for each subtasks of a given operation * as the container and the compound task will only be created and registered the first time this * method is called. The returned {@link CompoundTask} object provides a way for the client to add * subtask information to the container that will later be provided to the registered compound * task when it is executed.// w ww . java 2s . com * * <p><i>Note:</i> It is recommended to call this method for a given operation in one single place * in your code to ensure consistency of the container type and the compound task for each * subtasks being added. * * <p> * * <pre><code> * private final TaskList tasks = new TaskList(); * ... * tasks.addIfAbsent( * Operation.INSTALL, * HashSet<MyObjectClass>::new, * (objects, r) -> [do something with the accumulated objects] * ).add(name, objects -> objects.add(obj)); * </code></pre> * * @param <T> the type of the container used to accumulate recorded subtasks * @param op the operation for which to record the subtask * @param containerFactory a supplier which returns a new, empty container object (only called the * first time this method is called) * @param task the compound task to add for later execution (the task will only be registered the * first time this method is called for a given operation) * @throws IllegalArgumentException if <code>op</code>, <code>containerFactory</code>, or <code> * task</code>, is <code>null</code> */ public <T> CompoundTask<T> addIfAbsent(Operation op, Supplier<T> containerFactory, BiPredicate<T, ProfileMigrationReport> task) { Validate.notNull(op, "invalid null operation"); Validate.notNull(containerFactory, "invalid null container factory"); Validate.notNull(task, "invalid null task"); return (CompoundTask<T>) compoundGroups.computeIfAbsent(op, o -> new CompoundTask<>(op, task, containerFactory.get())); }
From source file:org.codice.ddf.catalog.ui.query.monitor.impl.WorkspaceQueryService.java
/** * @param queryUpdateSubscriber must be non-null * @param workspaceService must be non-null * @param catalogFramework must be non-null * @param filterBuilder must be non-null * @param schedulerSupplier must be non-null * @param securityService must be non-null * @param filterService must be non-null */// w w w.j a v a 2 s . c o m public WorkspaceQueryService(QueryUpdateSubscriber queryUpdateSubscriber, WorkspaceService workspaceService, CatalogFramework catalogFramework, FilterBuilder filterBuilder, Supplier<Optional<Scheduler>> schedulerSupplier, SecurityService securityService, FilterService filterService) throws SchedulerException { notNull(queryUpdateSubscriber, "queryUpdateSubscriber must be non-null"); notNull(workspaceService, "workspaceService must be non-null"); notNull(catalogFramework, "catalogFramework must be non-null"); notNull(filterBuilder, "filterBuilder must be non-null"); notNull(schedulerSupplier, "scheduleSupplier must be non-null"); notNull(securityService, "securityService must be non-null"); notNull(filterService, "filterService must be non-null"); this.queryUpdateSubscriber = queryUpdateSubscriber; this.workspaceService = workspaceService; this.catalogFramework = catalogFramework; this.filterBuilder = filterBuilder; this.securityService = securityService; this.filterService = filterService; Optional<Scheduler> schedulerOptional = schedulerSupplier.get(); if (schedulerOptional.isPresent()) { scheduler = schedulerOptional.get(); jobDetail = newJob(QueryJob.class).withIdentity(JOB_IDENTITY).build(); scheduler.scheduleJob(jobDetail, new CronString(DEFAULT_CRON_STRING, TRIGGER_NAME).get()); scheduler.start(); } else { LOGGER.warn("unable to get a quartz scheduler object, email notifications will not run"); } }
From source file:org.codice.ddf.catalog.ui.query.monitor.impl.WorkspaceQueryServiceImpl.java
/** * @param queryUpdateSubscriber must be non-null * @param workspaceService must be non-null * @param catalogFramework must be non-null * @param filterBuilder must be non-null * @param schedulerSupplier must be non-null * @param securityService must be non-null * @param filterService must be non-null *//*from ww w . j a v a 2 s . c om*/ public WorkspaceQueryServiceImpl(QueryUpdateSubscriber queryUpdateSubscriber, WorkspaceService workspaceService, CatalogFramework catalogFramework, FilterBuilder filterBuilder, Supplier<Optional<Scheduler>> schedulerSupplier, SecurityService securityService, FilterService filterService) throws SchedulerException { notNull(queryUpdateSubscriber, "queryUpdateSubscriber must be non-null"); notNull(workspaceService, "workspaceService must be non-null"); notNull(catalogFramework, "catalogFramework must be non-null"); notNull(filterBuilder, "filterBuilder must be non-null"); notNull(schedulerSupplier, "scheduleSupplier must be non-null"); notNull(securityService, "securityService must be non-null"); notNull(filterService, "filterService must be non-null"); this.queryUpdateSubscriber = queryUpdateSubscriber; this.workspaceService = workspaceService; this.catalogFramework = catalogFramework; this.filterBuilder = filterBuilder; this.securityService = securityService; this.filterService = filterService; Optional<Scheduler> schedulerOptional = schedulerSupplier.get(); if (schedulerOptional.isPresent()) { scheduler = schedulerOptional.get(); scheduler.getContext().put(JOB_IDENTITY, this); jobDetail = newJob(QueryJob.class).withIdentity(JOB_IDENTITY).build(); scheduler.start(); } else { LOGGER.warn("unable to get a quartz scheduler object, email notifications will not run"); } }
From source file:org.codice.ddf.catalog.ui.security.accesscontrol.AccessControlPolicyExtension.java
private KeyValueCollectionPermission isPermitted(CollectionPermission s, KeyValueCollectionPermission match, KeyValueCollectionPermission allPerms) { Map<String, Set<String>> subject = getPermissions(s.getPermissionList()); Map<String, Set<String>> metacard = getPermissions(allPerms.getPermissionList()); // There is nothing to imply if the incoming permission set doesn't contain _ALL_ ACL attributes if (Collections.disjoint(metacard.keySet(), ACCESS_CONTROL_IMPLIED)) { return match; // Simply imply nothing early on (essentially a no-op in this extension) }/*from w w w. ja v a 2 s. c om*/ // To be able to have viewing access to the metacard, you must satisfy the following criteria SecurityPredicate subjectImpliesACL = (sub, mc) -> hasAccessAdministrators.apply(sub, mc) || hasAccessIndividuals.apply(sub, mc) || hasAccessGroups.apply(sub, mc) || (READ_ACTION.equals(allPerms.getAction()) && (hasAccessGroupsReadOnly.apply(sub, mc) || hasAccessIndividualsReadOnly.apply(sub, mc))); // get all permissions implied by the subject, this function returns what permissions // to filter from the key-value permission collection Supplier<Set<String>> impliedPermissions = () -> { if (isSystem.test(subject) || isOwner.apply(subject, metacard)) { return metacard.keySet(); // all permissions are implied } else if (subjectImpliesACL.apply(subject, metacard)) { return ACCESS_CONTROL_IMPLIED; // access control perms implied } else { return Collections.emptySet(); // nothing is implied } }; // filter out all implied permissions Function<Set<String>, KeyValueCollectionPermission> filterPermissions = (implied) -> { List<KeyValuePermission> values = match.getPermissionList().stream().map(p -> (KeyValuePermission) p) .filter((permission) -> !implied.contains((permission).getKey())).collect(Collectors.toList()); return new KeyValueCollectionPermission(match.getAction(), values); }; return filterPermissions.apply(impliedPermissions.get()); }
From source file:org.codice.ddf.catalog.ui.security.AccessControlPolicyExtension.java
private KeyValueCollectionPermission isPermitted(CollectionPermission s, KeyValueCollectionPermission match, KeyValueCollectionPermission allPerms) { Map<String, Set<String>> subject = getPermissions(s.getPermissionList()); Map<String, Set<String>> metacard = getPermissions(allPerms.getPermissionList()); // There is nothing to imply if the incoming permission set doesn't contain _ALL_ ACL attributes if (Collections.disjoint(metacard.keySet(), ACCESS_CONTROL_IMPLIED)) { return match; // Simply imply nothing early on (essentially a no-op in this extension) }//from w w w . j a va 2 s . c o m // get all permissions implied by the subject, this function returns what permissions // to filter from the key-value permission collection Supplier<Set<String>> impliedPermissions = () -> { if (isSystem.test(subject) || isOwner.apply(subject, metacard)) { return metacard.keySet(); // all permissions are implied } else if (hasAccessAdministrators.apply(subject, metacard) || hasAccessIndividuals.apply(subject, metacard) || hasAccessGroups.apply(subject, metacard)) { return ACCESS_CONTROL_IMPLIED; // access control perms implied } else { return Collections.emptySet(); // nothing is implied } }; // filter out all implied permissions Function<Set<String>, KeyValueCollectionPermission> filterPermissions = (implied) -> { List<KeyValuePermission> values = match.getPermissionList().stream().map(p -> (KeyValuePermission) p) .filter((permission) -> !implied.contains((permission).getKey())).collect(Collectors.toList()); return new KeyValueCollectionPermission(match.getAction(), values); }; return filterPermissions.apply(impliedPermissions.get()); }
From source file:org.codice.ddf.configuration.admin.ImportMigrationConfigurationAdminContext.java
@Nullable private Path getPathFromConfiguration(@Nullable Dictionary<String, Object> properties, Supplier<String> from) { if (properties == null) { return null; }// w w w .jav a 2 s .c o m final Object o = properties.get(DirectoryWatcher.FILENAME); final Path path; if (o != null) { try { if (o instanceof URL) { path = new File(((URL) o).toURI()).toPath(); } else if (o instanceof URI) { path = new File((URI) o).toPath(); } else if (o instanceof String) { path = new File(new URL((String) o).toURI()).toPath(); } else if (o instanceof File) { path = ((File) o).toPath(); } else if (o instanceof Path) { path = (Path) o; } else { LOGGER.debug("unsupported {} property '{}' from {}", DirectoryWatcher.FILENAME, o, from.get()); return null; } } catch (MalformedURLException | URISyntaxException e) { LOGGER.debug(String.format("failed to parse %s property '%s' from %s; ", DirectoryWatcher.FILENAME, o, from.get()), e); return null; } } else { return null; } // ignore the whole path if any (there shouldn't be any other than etc) and force it to be under // etc return ImportMigrationConfigurationAdminContext.ETC_PATH.resolve(path.getFileName()); }
From source file:org.commonjava.indy.client.core.util.UrlUtils.java
public static String buildUrl(final String baseUrl, final Supplier<Map<String, String>> paramSupplier, final String... parts) { Logger logger = LoggerFactory.getLogger(UrlUtils.class); if (logger.isDebugEnabled()) { logger.debug("Creating url from base: '{}' and parts: {}", baseUrl, join(parts, ", ")); }//from www .j av a 2 s . co m if (parts == null || parts.length < 1) { return baseUrl; } final StringBuilder urlBuilder = new StringBuilder(); final List<String> list = new ArrayList<>(); if (baseUrl != null && !"null".equals(baseUrl)) { list.add(baseUrl); } else { list.add("/"); } for (final String part : parts) { if (part == null || "null".equals(part)) { continue; } list.add(part); } urlBuilder.append(normalizePath(list.toArray(new String[list.size()]))); // // if ( parts[0] == null || !parts[0].startsWith( baseUrl ) ) // { // urlBuilder.append( baseUrl ); // } // // for ( String part : parts ) // { // if ( part == null || part.trim() // .length() < 1 ) // { // continue; // } // // if ( part.startsWith( "/" ) ) // { // part = part.substring( 1 ); // } // // if ( urlBuilder.length() > 0 && urlBuilder.charAt( urlBuilder.length() - 1 ) != '/' ) // { // urlBuilder.append( "/" ); // } // // urlBuilder.append( part ); // } if (paramSupplier != null) { Map<String, String> params = paramSupplier.get(); urlBuilder.append("?"); boolean first = true; for (final Map.Entry<String, String> param : params.entrySet()) { if (first) { first = false; } else { urlBuilder.append("&"); } urlBuilder.append(param.getKey()).append("=").append(param.getValue()); } } return urlBuilder.toString(); }