Java Code Examples for java.util.Set#removeIf()

The following examples show how to use java.util.Set#removeIf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MockProviderDataAccessor.java    From blackduck-alert with Apache License 2.0 6 votes vote down vote up
private List<ProviderProject> updateProjectDB(Long providerConfigId, Set<ProviderProject> currentProjects) {
    Set<ProviderProject> storedProjectsSet = providerProjects.get(providerConfigId);
    if (null == storedProjectsSet) {
        storedProjectsSet = new HashSet<>();
    }

    Set<ProviderProject> projectsToRemove = new HashSet<>(storedProjectsSet);
    projectsToRemove.removeIf(currentProjects::contains);

    Set<ProviderProject> projectsToAdd = new HashSet<>(currentProjects);
    projectsToAdd.removeIf(storedProjectsSet::contains);

    deleteProjects(projectsToRemove);

    this.providerProjects.addAll(providerConfigId, projectsToAdd);
    return new ArrayList<>(this.providerProjects.get(providerConfigId));
}
 
Example 2
Source File: ComWorkflowServiceImpl.java    From openemm with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Generate and store workflow dependencies list — must be easily available to other EMM components without parsing
 * workflow schema. Managed and referenced mailings, archives, user forms, target groups, etc.
 *
 * @param companyId an admin who saves a workflow.
 * @param workflowId an identifier of a workflow to collect dependencies list for.
 * @param icons icons of a workflow to collect dependencies from.
 */
private void saveDependencies(@VelocityCheck int companyId, int workflowId, List<WorkflowIcon> icons) {
    Set<WorkflowDependency> dependencies = new HashSet<>();

    for (WorkflowIcon icon : icons) {
        dependencies.addAll(icon.getDependencies());
    }

    Set<Integer> mailingIds = new HashSet<>();

    for (WorkflowDependency dependency : dependencies) {
        if (MAILING_DELIVERY == dependency.getType()) {
            mailingIds.add(dependency.getEntityId());
        }
    }

    // Remove redundant dependencies -> mailing delivery overlaps mailing reference.
    dependencies.removeIf(dependency -> {
        // Referenced mailing may or may not be used in a mailing icon (to be delivered).
        return WorkflowDependencyType.MAILING_REFERENCE == dependency.getType() && mailingIds.contains(dependency.getEntityId());
    });

    workflowDao.setDependencies(companyId, workflowId, dependencies, false);
}
 
Example 3
Source File: AbstractUpdateImports.java    From flow with Apache License 2.0 6 votes vote down vote up
private void collectModules(List<String> lines) {
    Set<String> modules = new LinkedHashSet<>();
    modules.addAll(resolveModules(getModules()));
    modules.addAll(resolveModules(getScripts()));

    modules.addAll(getGeneratedModules());

    modules.removeIf(UrlUtil::isExternal);

    ArrayList<String> externals = new ArrayList<>();
    ArrayList<String> internals = new ArrayList<>();

    for (String module : getModuleLines(modules)) {
        if (FRONTEND_IMPORT_LINE.matcher(module).matches()) {
            internals.add(module);
        } else {
            externals.add(module);
        }
    }

    lines.addAll(externals);
    lines.addAll(internals);
}
 
Example 4
Source File: HasHeader.java    From james-project with Apache License 2.0 6 votes vote down vote up
@Override
public Collection<MailAddress> match(Mail mail) throws javax.mail.MessagingException {
    Set<MailAddress> matchingRecipients = new HashSet<>();
    boolean first = true;
    for (HeaderCondition headerCondition : headerConditions) {
        if (first) {
            first = false;
            // Keep the first list
            matchingRecipients.addAll(headerCondition.isMatching(mail));
        } else {
            // Ensure intersection (all must be true)
            Collection<MailAddress> currentMatching = headerCondition.isMatching(mail);
            matchingRecipients.removeIf(it -> !currentMatching.contains(it));
        }
    }
    return matchingRecipients.isEmpty() ? null : matchingRecipients;
}
 
Example 5
Source File: MatchingDataAttestationGroup.java    From teku with Apache License 2.0 6 votes vote down vote up
/**
 * Removes any attestation from this group whose validators are all included in the specified
 * attestation. Attestations that include some but not all validators in the specified attestation
 * are not removed.
 *
 * <p>This is well suited for removing attestations that have been included in a block.
 *
 * @param attestation the attestation to logically remove from the pool.
 */
public void remove(final Attestation attestation) {
  final Collection<Set<ValidateableAttestation>> attestationSets =
      attestationsByValidatorCount.values();
  for (Iterator<Set<ValidateableAttestation>> i = attestationSets.iterator(); i.hasNext(); ) {
    final Set<ValidateableAttestation> candidates = i.next();
    candidates.removeIf(
        candidate ->
            attestation
                .getAggregation_bits()
                .isSuperSetOf(candidate.getAttestation().getAggregation_bits()));
    if (candidates.isEmpty()) {
      i.remove();
    }
  }
}
 
Example 6
Source File: ConsumesRequestCondition.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Checks if any of the contained media type expressions match the given
 * request 'Content-Type' header and returns an instance that is guaranteed
 * to contain matching expressions only. The match is performed via
 * {@link MediaType#includes(MediaType)}.
 * @param request the current request
 * @return the same instance if the condition contains no expressions;
 * or a new condition with matching expressions only;
 * or {@code null} if no expressions match
 */
@Override
@Nullable
public ConsumesRequestCondition getMatchingCondition(HttpServletRequest request) {
	if (CorsUtils.isPreFlightRequest(request)) {
		return PRE_FLIGHT_MATCH;
	}
	if (isEmpty()) {
		return this;
	}

	MediaType contentType;
	try {
		contentType = (StringUtils.hasLength(request.getContentType()) ?
				MediaType.parseMediaType(request.getContentType()) :
				MediaType.APPLICATION_OCTET_STREAM);
	}
	catch (InvalidMediaTypeException ex) {
		return null;
	}

	Set<ConsumeMediaTypeExpression> result = new LinkedHashSet<>(this.expressions);
	result.removeIf(expression -> !expression.match(contentType));
	return (!result.isEmpty() ? new ConsumesRequestCondition(result) : null);
}
 
Example 7
Source File: AddVotingConfigExclusionsRequest.java    From crate with Apache License 2.0 5 votes vote down vote up
Set<VotingConfigExclusion> resolveVotingConfigExclusions(ClusterState currentState) {
    final DiscoveryNodes allNodes = currentState.nodes();
    final Set<VotingConfigExclusion> resolvedNodes = Arrays.stream(allNodes.resolveNodes(nodeDescriptions))
            .map(allNodes::get).filter(DiscoveryNode::isMasterNode).map(VotingConfigExclusion::new).collect(Collectors.toSet());

    if (resolvedNodes.isEmpty()) {
        throw new IllegalArgumentException("add voting config exclusions request for " + Arrays.asList(nodeDescriptions)
            + " matched no master-eligible nodes");
    }

    resolvedNodes.removeIf(n -> currentState.getVotingConfigExclusions().contains(n));
    return resolvedNodes;
}
 
Example 8
Source File: TestTargetUtils.java    From bazel with Apache License 2.0 5 votes vote down vote up
/**
 * Filters 'tests' (by mutation) according to the 'tags' attribute, specifically those that
 * match ALL of the tags in tagsAttribute.
 *
 * @precondition {@code env.getAccessor().isTestSuite(testSuite)}
 * @precondition {@code env.getAccessor().isTestRule(test)} for all test in tests
 */
public static void filterTests(Rule testSuite, Set<Target> tests) {
  List<String> tagsAttribute =
      NonconfigurableAttributeMapper.of(testSuite).get("tags", Type.STRING_LIST);
  // Split the tags list into positive and negative tags
  Pair<Collection<String>, Collection<String>> tagLists = sortTagsBySense(tagsAttribute);
  Collection<String> positiveTags = tagLists.first;
  Collection<String> negativeTags = tagLists.second;
  tests.removeIf((Target t) -> !testMatchesFilters((Rule) t, positiveTags, negativeTags));
}
 
Example 9
Source File: LoadBalancerProvisioner.java    From vespa with Apache License 2.0 5 votes vote down vote up
/** Find IP addresses reachable by the load balancer service */
private Set<String> reachableIpAddresses(Node node) {
    Set<String> reachable = new LinkedHashSet<>(node.ipAddresses());
    // Remove addresses unreachable by the load balancer service
    switch (service.protocol()) {
        case ipv4:
            reachable.removeIf(IP::isV6);
            break;
        case ipv6:
            reachable.removeIf(IP::isV4);
            break;
    }
    return reachable;
}
 
Example 10
Source File: TemplateMultiAgg.java    From systemds with Apache License 2.0 5 votes vote down vote up
private Hop getSparseSafeSharedInput(ArrayList<Hop> roots, HashSet<Hop> inHops) {
	Set<Hop> tmp = inHops.stream()
		.filter(h -> h.getDataType().isMatrix())
		.collect(Collectors.toSet());
	for( Hop root : roots ) {
		root.resetVisitStatus();
		HashSet<Hop> inputs = new HashSet<>();
		rCollectSparseSafeInputs(root, inHops, inputs);
		tmp.removeIf(h -> !inputs.contains(h));
	}
	Hop.resetVisitStatus(roots);
	return tmp.isEmpty() ? null : 
		tmp.toArray(new Hop[0])[0];
}
 
Example 11
Source File: SeedNodeAddresses.java    From bisq-core with GNU Affero General Public License v3.0 5 votes vote down vote up
public SeedNodeAddresses excludeByHost(Set<String> hosts) {
    Set<NodeAddress> copy = new HashSet<>(this);
    copy.removeIf(address -> {
        String hostName = address.getHostName();
        return hosts.contains(hostName);
    });
    return new SeedNodeAddresses(copy);
}
 
Example 12
Source File: ProducesRequestCondition.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Checks if any of the contained media type expressions match the given
 * request 'Content-Type' header and returns an instance that is guaranteed
 * to contain matching expressions only. The match is performed via
 * {@link MediaType#isCompatibleWith(MediaType)}.
 * @param request the current request
 * @return the same instance if there are no expressions;
 * or a new condition with matching expressions;
 * or {@code null} if no expressions match.
 */
@Override
@Nullable
public ProducesRequestCondition getMatchingCondition(HttpServletRequest request) {
	if (CorsUtils.isPreFlightRequest(request)) {
		return PRE_FLIGHT_MATCH;
	}
	if (isEmpty()) {
		return this;
	}

	List<MediaType> acceptedMediaTypes;
	try {
		acceptedMediaTypes = getAcceptedMediaTypes(request);
	}
	catch (HttpMediaTypeException ex) {
		return null;
	}

	Set<ProduceMediaTypeExpression> result = new LinkedHashSet<>(this.expressions);
	result.removeIf(expression -> !expression.match(acceptedMediaTypes));
	if (!result.isEmpty()) {
		return new ProducesRequestCondition(result, this.contentNegotiationManager);
	}
	else if (MediaType.ALL.isPresentIn(acceptedMediaTypes)) {
		return EMPTY_CONDITION;
	}
	else {
		return null;
	}
}
 
Example 13
Source File: ArrangeAssociations.java    From txtUML with Eclipse Public License 1.0 5 votes vote down vote up
private Set<Pair<Point, Double>> setReflexiveSet(Set<Pair<Point, Double>> fromSet, RectangleObject obj,
		Boolean isStart) {
	Set<Pair<Point, Double>> result = new HashSet<Pair<Point, Double>>(fromSet);

	Integer halfwayH = ((obj.getWidth() % 2) == 0) ? ((obj.getWidth() / 2) - 1) : ((obj.getWidth() - 1) / 2);
	Integer halfwayV = ((obj.getHeight() % 2) == 0) ? ((obj.getHeight() / 2) - 1) : ((obj.getHeight() - 1) / 2);

	Point northern = Point.Add(obj.getPosition(), new Point(halfwayH, 0));
	if (isStart)
		result.removeIf(p -> p.getFirst().getY().equals(northern.getY()) && p.getFirst().getX() >= northern.getX());
	else
		result.removeIf(p -> p.getFirst().getY().equals(northern.getY()) && p.getFirst().getX() <= northern.getX());

	Point eastern = Point.Add(obj.getBottomRight(), new Point(0, halfwayV));
	if (isStart)
		result.removeIf(p -> p.getFirst().getX().equals(eastern.getX()) && p.getFirst().getY() <= eastern.getY());
	else
		result.removeIf(p -> p.getFirst().getX().equals(eastern.getX()) && p.getFirst().getY() >= eastern.getY());

	Point southern = Point.Add(obj.getBottomRight(), new Point(-1 * halfwayH, 0));
	if (isStart)
		result.removeIf(p -> p.getFirst().getY().equals(southern.getY()) && p.getFirst().getX() <= southern.getX());
	else
		result.removeIf(p -> p.getFirst().getY().equals(southern.getY()) && p.getFirst().getX() >= southern.getX());

	Point western = Point.Add(obj.getPosition(), new Point(0, -1 * halfwayV));
	if (isStart)
		result.removeIf(p -> p.getFirst().getX().equals(western.getX()) && p.getFirst().getY() >= western.getY());
	else
		result.removeIf(p -> p.getFirst().getX().equals(western.getX()) && p.getFirst().getY() <= western.getY());

	// Set the weights of points
	for (Pair<Point, Double> pair : result) {
		pair = new Pair<Point, Double>(pair.getFirst(), 0.0);
	}

	return result;
}
 
Example 14
Source File: ProtectedNiFiProperties.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves all known property keys.
 *
 * @return all known property keys
 */
@Override
public Set<String> getPropertyKeys() {
    Set<String> filteredKeys = getPropertyKeysIncludingProtectionSchemes();
    filteredKeys.removeIf(p -> p.endsWith(".protected"));
    return filteredKeys;
}
 
Example 15
Source File: PathMapper.java    From AsciidocFX with Apache License 2.0 5 votes vote down vote up
public Optional<Path> lookUpFile(Path file) {
    if (Objects.isNull(file)) {
        return Optional.empty();
    }
    Path fileName = file.getFileName();

    if (Objects.isNull(fileName)) {
        return Optional.empty();
    }

    Set<Path> pathList = pathMap.get(fileName);

    if (Objects.isNull(pathList)) {
        return Optional.empty();
    }

    pathList.removeIf(Files::notExists);

    if (pathList.size() > 1) {
        return Optional.empty();
    }

    for (Path path : pathList) {
        if (Files.exists(path)) {
            return Optional.ofNullable(path);
        }
    }

    return Optional.empty();
}
 
Example 16
Source File: ItemFacade.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public void removeItemTagByTagId(String tagId) {
  final Set itemTagSet = getItemTagSet();
  if ( itemTagSet == null || itemTagSet.isEmpty() ) {
    return;
  }
  itemTagSet.removeIf(itemTag -> tagId.equals(((ItemTagIfc)itemTag).getTagId()));
  this.itemTagSet = getItemTagSet();
}
 
Example 17
Source File: JournalStoreState.java    From journalkeeper with Apache License 2.0 5 votes vote down vote up
private JournalStoreQueryResult queryPartitions(RaftJournal journal) {
    Set<Integer> partitions = journal.getPartitions();
    partitions.removeIf(partition -> partition >= RESERVED_PARTITIONS_START);
    return
            new JournalStoreQueryResult(
                    partitions.stream()
                            .collect(Collectors.toMap(
                                    Integer::intValue,
                                    partition -> new JournalStoreQueryResult.Boundary(journal.minIndex(partition), appliedIndices.getOrDefault(partition, 0L))
                            )));
}
 
Example 18
Source File: QuerydslPredicateOperationCustomizer.java    From springdoc-openapi with Apache License 2.0 4 votes vote down vote up
@Override
public Operation customize(Operation operation, HandlerMethod handlerMethod) {
	if (operation.getParameters() == null) {
		return operation;
	}

	MethodParameter[] methodParameters = handlerMethod.getMethodParameters();

	int parametersLength = methodParameters.length;
	List<Parameter> parametersToAddToOperation = new ArrayList<>();
	for (int i = 0; i < parametersLength; i++) {
		MethodParameter parameter = methodParameters[i];
		QuerydslPredicate predicate = parameter.getParameterAnnotation(QuerydslPredicate.class);

		if (predicate == null) {
			continue;
		}

		QuerydslBindings bindings = extractQdslBindings(predicate);

		Set<String> fieldsToAdd = Arrays.stream(predicate.root().getDeclaredFields()).map(Field::getName).collect(Collectors.toSet());

		Map<String, Object> pathSpecMap = getPathSpec(bindings, "pathSpecs");
		//remove blacklisted fields
		Set<String> blacklist = getFieldValues(bindings, "blackList");
		fieldsToAdd.removeIf(blacklist::contains);

		Set<String> whiteList = getFieldValues(bindings, "whiteList");
		Set<String> aliases = getFieldValues(bindings, "aliases");

		fieldsToAdd.addAll(aliases);
		fieldsToAdd.addAll(whiteList);
		for (String fieldName : fieldsToAdd) {
			Type type = getFieldType(fieldName, pathSpecMap, predicate.root());
			io.swagger.v3.oas.models.parameters.Parameter newParameter = buildParam(type, fieldName);

			parametersToAddToOperation.add(newParameter);
		}
	}
	operation.getParameters().addAll(parametersToAddToOperation);
	return operation;
}
 
Example 19
Source File: EventConverter.java    From logging-log4j-audit with Apache License 2.0 4 votes vote down vote up
public  EventModel convert(Event event) {
    LOGGER.traceEntry(event.getName());
    EventModel model;
    if (event.getId() != null) {
        model = eventService.getEvent(event.getId()).orElseGet(EventModel::new);
    } else {
        model = new EventModel();
    }
    model.setCatalogId(event.getCatalogId());
    model.setName(event.getName());
    model.setAliases(event.getAliases());
    model.setDescription(event.getDescription());
    model.setDisplayName(event.getDisplayName());
    if (model.getAttributes() == null) {
        model.setAttributes(new HashSet<>());
    }
    Set<EventAttributeModel> eventAttributeModels = model.getAttributes() != null ? model.getAttributes() :
            new HashSet<>();
    List<EventAttribute> eventAttributes = event.getAttributes() != null ? event.getAttributes() : new ArrayList<>();
    if (!eventAttributes.isEmpty()) {
        for (EventAttribute eventAttribute : eventAttributes) {
            EventAttributeModel eventAttributeModel = model.getAttribute(eventAttribute.getName());
            if (eventAttributeModel != null) {
                eventAttributeModel.setRequired(eventAttribute.isRequired());
            } else {
                Optional<AttributeModel> optional = getAttribute(event.getCatalogId(), eventAttribute.getName());
                if (optional.isPresent()) {
                    eventAttributeModel = new EventAttributeModel();
                    eventAttributeModel.setRequired(eventAttribute.isRequired());
                    eventAttributeModel.setEvent(model);
                    eventAttributeModel.setAttribute(optional.get());
                    eventAttributeModels.add(eventAttributeModel);
                } else {
                    throw new CatalogModificationException("No catalog entry for " + eventAttribute.getName());
                }
            }
        }
    }
    eventAttributeModels.removeIf(a -> eventAttributes.stream().noneMatch(b -> b.getName().equals(a.getAttribute().getName())));
    model.setAttributes(eventAttributeModels);
    return LOGGER.traceExit(model);
}
 
Example 20
Source File: VerifyBackupPartitionsTaskV2.java    From ignite with Apache License 2.0 2 votes vote down vote up
/**
 * Filters cache groups by cache filter, also removes system (if not specified in filter option) and local
 * caches.
 *
 * @param cachesToFilter cache groups to filter
 */
private void filterByCacheFilter(Set<CacheGroupContext> cachesToFilter) {
    cachesToFilter.removeIf(grp -> !doesGrpMatchFilter(grp));
}