List of usage examples for com.google.common.collect Sets filter
@GwtIncompatible("NavigableSet") @SuppressWarnings("unchecked") @CheckReturnValue public static <E> NavigableSet<E> filter(NavigableSet<E> unfiltered, Predicate<? super E> predicate)
From source file:gov.nih.nci.firebird.data.InvestigatorProfile.java
/** * Get all credentials of the specified type that are not expired. * * @param type type to match./*from ww w . j av a 2s . c o m*/ * @return credentials matching the specified type. */ public SortedSet<AbstractCredential<?>> getCurrentCredentials(final CredentialType type) { return getSortedSet(Sets.filter(getCredentials(type), new Predicate<AbstractCredential<?>>() { @Override public boolean apply(AbstractCredential<?> credential) { return !credential.isExpired(); } })); }
From source file:org.eclipse.sirius.diagram.sequence.business.internal.refresh.SequenceCanonicalSynchronizerAdapter.java
private Set<ISequenceEvent> getEventEndsOnUpperRange(SequenceDiagram sequenceDiagram, Lifeline lifeline, int upperRange, Set<ISequenceEvent> sequenceEventToIgnores) { Set<ISequenceEvent> eventEndsOnUpperRange = new TreeSet<ISequenceEvent>(new RangeComparator()); Set<ISequenceEvent> allSequenceEventsOnRange = new SequenceDiagramQuery(sequenceDiagram) .getAllSequenceEventsOn(upperRange); allSequenceEventsOnRange.removeAll(sequenceEventToIgnores); eventEndsOnUpperRange.addAll(// w w w. ja v a2s .c om Sets.filter(allSequenceEventsOnRange, Predicates.not(Predicates.instanceOf(Lifeline.class)))); return eventEndsOnUpperRange; }
From source file:gov.nih.nci.firebird.data.InvestigatorProfile.java
/** * get credentials of the specified type. * * @param <C> Credential//from www. ja va 2s . c o m * @param type type to match. * @return credentials matching the specified type. */ @SuppressWarnings("unchecked") // this is guaranteed to be a safe cast public <C extends AbstractCredential<?>> SortedSet<C> getCredentials(final Class<C> type) { return (SortedSet<C>) getSortedSet(Sets.filter(getCredentials(), new Predicate<AbstractCredential<?>>() { @Override public boolean apply(AbstractCredential<?> credential) { return type.isAssignableFrom(credential.getClass()); } })); }
From source file:org.eclipse.sw360.moderation.db.ModerationDatabaseHandler.java
private ModerationRequest createStubRequest(User user, boolean isDeleteRequest, String documentId, Set<String> moderators) { final ModerationRequest request; List<ModerationRequest> requestByDocumentId = getRequestByDocumentId(documentId); Optional<ModerationRequest> firstModerationRequestOfUser = CommonUtils .getFirstModerationRequestOfUser(requestByDocumentId, user.getEmail()); if (firstModerationRequestOfUser.isPresent() && CommonUtils.isStillRelevant(firstModerationRequestOfUser.get())) { request = firstModerationRequestOfUser.get(); } else {// w w w .j ava2 s . c o m request = new ModerationRequest(); request.setRequestingUser(user.getEmail()); request.setDocumentId(documentId); } request.setTimestamp(System.currentTimeMillis()); request.setModerationState(ModerationState.PENDING); request.setRequestDocumentDelete(isDeleteRequest); request.setModerators(Sets.filter(moderators, notEmptyOrNull())); request.setRequestingUserDepartment(user.getDepartment()); fillRequestWithCommentOfUser(request, user); ; return request; }
From source file:org.gradle.model.internal.manage.binding.DefaultStructBindingsStore.java
private static <T> Map<Wrapper<Method>, WeaklyTypeReferencingMethod<?, ?>> collectPublicViewImplMethods( StructSchema<T> publicSchema) { return indexBySignature( Sets.filter(publicSchema.getAllMethods(), new Predicate<WeaklyTypeReferencingMethod<?, ?>>() { @Override/*from www .j a va2 s.c o m*/ public boolean apply(WeaklyTypeReferencingMethod<?, ?> weakMethod) { return !Modifier.isAbstract(weakMethod.getModifiers()); } })); }
From source file:org.eclipse.sirius.diagram.ui.tools.internal.layout.PinnedElementsHandler.java
/** * Resolve all the overlaps concerning the given fixed edit part. This * method may also resolve overlaps concerning other fixed parts in the * process, but will at least resolve all the (solvable) ones concerning the * specified part. After successful execution of this method, the only parts * overlapping <code>fixedPart</code>, if any, are also fixed parts, and * thus are unsolvable overlaps./*from w ww .j a v a 2s .c om*/ * * @param fixedPart * the fixed edit part to consider. */ private void resolveOverlaps(final IGraphicalEditPart fixedPart) { final Set<IGraphicalEditPart> solvableOverlaps = Sets.filter(findOverlappingParts(fixedPart), Predicates.not(isPinned)); final Map<Direction, SortedSet<IGraphicalEditPart>> groupedOverlaps = groupByDirection(fixedPart, solvableOverlaps); for (Entry<Direction, SortedSet<IGraphicalEditPart>> group : groupedOverlaps.entrySet()) { // For a same group, we kept the movedPositions to allow a complete // rollback to move again several parts in same time Map<IGraphicalEditPart, Point> previousMovedPositionsBefore = Maps.newHashMap(); for (IGraphicalEditPart part : group.getValue()) { assert overlaps(fixedPart, part); previousMovedPositionsBefore = moveAside(Collections.singleton(part), Collections.singleton(fixedPart), group.getKey(), previousMovedPositionsBefore); assert !overlaps(fixedPart, part); } } assert Collections2.filter(findOverlappingParts(fixedPart), Predicates.not(isPinned)) .isEmpty() : Messages.PinnedElementsHandler_remainOverlapsMsg; }
From source file:org.eclipse.acceleo.engine.internal.environment.AcceleoEvaluationEnvironment.java
/** * Filters non-applicable templates out of the candidates list. * //www . ja va 2 s. c o m * @param candidates * List of templates that needs to be filtered out. * @param argumentTypes * Types of the arguments for the call. * @return The set of applicable templates. */ private Set<Template> applicableTemplates(Set<Template> candidates, final List<Object> argumentTypes) { Predicate<Template> argumentSizeMatch = new Predicate<Template>() { public boolean apply(Template input) { final List<Variable> parameters = input.getParameter(); return parameters.size() == argumentTypes.size() || parameters.isEmpty() && argumentTypes.size() == 1; } }; Predicate<Template> argumentsMatch = new Predicate<Template>() { public boolean apply(Template input) { final List<Variable> parameters = input.getParameter(); if (parameters.isEmpty() && argumentTypes.size() == 1) { return true; } boolean argumentMatch = true; for (int i = 0; i < argumentTypes.size() && argumentMatch; i++) { final Variable param = parameters.get(i); final Object parameterType = param.getType(); argumentMatch = isApplicableArgument(parameterType, argumentTypes.get(i)); } return argumentMatch; } }; return Sets.filter(candidates, Predicates.and(argumentSizeMatch, argumentsMatch)); }
From source file:org.apache.isis.runtimes.dflt.runtime.system.transaction.IsisTransaction.java
public Set<Entry<AdapterAndProperty, PreAndPostValues>> getAuditEntries() { updatePostValues(auditLog.entrySet()); return Collections.unmodifiableSet(Sets.filter(auditLog.entrySet(), PreAndPostValues.CHANGED)); }
From source file:dagger2.internal.codegen.BindingGraphValidator.java
private void validateBuilders(BindingGraph subject, Builder<BindingGraph> reportBuilder) { ComponentDescriptor componentDesc = subject.componentDescriptor(); if (!componentDesc.builderSpec().isPresent()) { // If no builder, nothing to validate. return;/*from w w w .j a v a 2 s . c o m*/ } Set<TypeElement> allDependents = Sets.union( Sets.union(subject.transitiveModules().keySet(), componentDesc.dependencies()), componentDesc.executorDependency().asSet()); Set<TypeElement> requiredDependents = Sets.filter(allDependents, new Predicate<TypeElement>() { @Override public boolean apply(TypeElement input) { return !Util.componentCanMakeNewInstances(input); } }); final BuilderSpec spec = componentDesc.builderSpec().get(); Map<TypeElement, ExecutableElement> allSetters = spec.methodMap(); ErrorMessages.ComponentBuilderMessages msgs = ErrorMessages .builderMsgsFor(subject.componentDescriptor().kind()); Set<TypeElement> extraSetters = Sets.difference(allSetters.keySet(), allDependents); if (!extraSetters.isEmpty()) { Collection<ExecutableElement> excessMethods = Maps.filterKeys(allSetters, Predicates.in(extraSetters)) .values(); Iterable<String> formatted = FluentIterable.from(excessMethods) .transform(new Function<ExecutableElement, String>() { @Override public String apply(ExecutableElement input) { return methodSignatureFormatter.format(input, Optional.of(MoreTypes.asDeclared(spec.builderDefinitionType().asType()))); } }); reportBuilder.addItem(String.format(msgs.extraSetters(), formatted), spec.builderDefinitionType()); } Set<TypeElement> missingSetters = Sets.difference(requiredDependents, allSetters.keySet()); if (!missingSetters.isEmpty()) { reportBuilder.addItem(String.format(msgs.missingSetters(), missingSetters), spec.builderDefinitionType()); } }
From source file:es.upm.dit.xsdinferencer.XSDInferenceConfiguration.java
/** * Loads a configuration from a properties file. Any value which was not present at the file would remain * at its previous value (which might be the default value) * @param file File object representing the properties file * @throws IOException If there is an I/O error related to the properties file. * @throws XSDConfigurationException if a value of a parameter is not valid or if a value of any parameter is inconsistent * with the value of another parameter *//*from w w w. j a va 2 s .c o m*/ protected void loadFromFile(File file) throws IOException, XSDConfigurationException { FileInputStream fis = new FileInputStream(file); Properties properties = new Properties(); properties.load(fis); String readMainNamespace = properties.getProperty(KEY_MAIN_NAMESPACE); if (readMainNamespace != null) { mainNamespace = readMainNamespace; } Set<String> foundSkipNamespacesKeys = Sets.filter(properties.stringPropertyNames(), Predicates.containsPattern("^\\Q" + KEY_MULTIPLE_SKIP_NAMESPACES + "\\E.*$")); if (!foundSkipNamespacesKeys.isEmpty()) { skipNamespaces.clear(); } for (String skipNamespace : foundSkipNamespacesKeys) { skipNamespaces.add(properties.getProperty(skipNamespace)); } String readTypeInferencer = properties.getProperty(KEY_TYPE_NAME_INFERENCER); String localityStr = properties.getProperty(KEY_TYPE_NAME_INFERENCER_LOCALITY); if (readTypeInferencer != null) { setTypeInferencer(readTypeInferencer, localityStr); } String readGenerateEnumerations = properties.getProperty(KEY_GENERATE_ENUMERATIONS); if (readGenerateEnumerations != null) { setGenerateEnumerations(readGenerateEnumerations); } String readWorkingFormat = properties.getProperty(KEY_WORKING_FORMAT); if (readWorkingFormat != null) { setWorkingFormat(readWorkingFormat); } String readMinNumberOfDistinctValuesToEnum = properties .getProperty(KEY_MIN_NUMBER_OF_DISTINCT_VALUES_TO_ENUM); if (readMinNumberOfDistinctValuesToEnum != null) { minNumberOfDistinctValuesToEnum = Integer.parseInt(readMinNumberOfDistinctValuesToEnum); } String readMaxNumberOfDistinctValuesToEnum = properties .getProperty(KEY_MAX_NUMBER_OF_DISTINCT_VALUES_TO_ENUM); if (readMaxNumberOfDistinctValuesToEnum != null) { maxNumberOfDistinctValuesToEnum = Integer.parseInt(readMaxNumberOfDistinctValuesToEnum); } String readSimpleTypeInferencer = properties.getProperty(KEY_SIMPLE_TYPE_INFERENCER); if (readSimpleTypeInferencer != null) { setSimpleTypeInferencer(readSimpleTypeInferencer); } String readAttributeListInferencer = properties.getProperty(KEY_ATTRIBUTE_LIST_INFERENCER); if (readAttributeListInferencer != null) { setAttributeListInferencer(readAttributeListInferencer); } String readChildrenPatternComparator = properties.getProperty(KEY_CHILDREN_PATTERN_COMPARATOR); String readAttributeListComparator = properties.getProperty(KEY_ATTRIBUTE_LIST_COMPARATOR); String readReduceThreshold = properties.getProperty(KEY_CHILDREN_PATTERN_COMPARATOR_REDUCE_THRESHOLD, DEFAULT_REDUCE_THRESHOLD); if ((readChildrenPatternComparator == null && readAttributeListComparator != null) || (readChildrenPatternComparator != null && readAttributeListComparator == null)) { throw new InconsistentXSDConfigurationParametersException( "If a 'childrenPatternComparator' is specified, an 'attributeListComparator' must be specified as well and vice versa"); } else if (readChildrenPatternComparator != null && readAttributeListComparator != null) { if ((readChildrenPatternComparator.equalsIgnoreCase(VALUE_CHILDREN_PATTERN_COMPARATOR_NO) && !readAttributeListComparator.equals(VALUE_ATTRIBUTE_LIST_COMPARATOR_NO)) || (!readChildrenPatternComparator.equalsIgnoreCase(VALUE_CHILDREN_PATTERN_COMPARATOR_NO) && readAttributeListComparator.equals(VALUE_ATTRIBUTE_LIST_COMPARATOR_NO))) { throw new InconsistentXSDConfigurationParametersException( "If a 'childrenPatternComparator' is specified to no, 'attributeListComparator' must be specified as well to no and vice versa"); } setChildrenPatternComparator(readChildrenPatternComparator, readReduceThreshold); setAttributeListComparator(readAttributeListComparator); } String snReadChildrenPatternComparator = properties.getProperty(KEY_SAME_NAME_CHILDREN_PATTERN_COMPARATOR); String snReadAttributeListComparator = properties.getProperty(KEY_SAME_NAME_ATTRIBUTE_LIST_COMPARATOR); String snReadReduceThreshold = properties .getProperty(KEY_SAME_NAME_CHILDREN_PATTERN_COMPARATOR_REDUCE_THRESHOLD, DEFAULT_REDUCE_THRESHOLD); if (snReadChildrenPatternComparator != null || snReadAttributeListComparator != null) { if ((readAttributeListComparator == null || attributeListComparator == null) && !(snReadChildrenPatternComparator != null && snReadAttributeListComparator != null)) { throw new InconsistentXSDConfigurationParametersException( "If same name comparators are defined when normal comparators are not defined, both same name comparators must be defined"); } setSnChildrenPatternComparator(snReadChildrenPatternComparator, snReadReduceThreshold); setSnAttributeListComparator(snReadAttributeListComparator); } String readEnumsComparator = properties.getProperty(KEY_ENUMS_COMPARATOR); String readEnumComparatorThreshold = properties.getProperty(KEY_ENUMS_COMPARATOR_THRESHOLD, DEFAULT_ENUM_COMPARATORS_THRESHOLD); if (readEnumsComparator != null) { setEnumsComparator(readEnumsComparator, readEnumComparatorThreshold); } String readSnEnumsComparator = properties.getProperty(KEY_SAME_NAME_ENUMS_COMPARATOR); String readSnEnumComparatorThreshold = properties.getProperty(KEY_SAME_NAME_ENUMS_COMPARATOR_THRESHOLD, DEFAULT_ENUM_COMPARATORS_THRESHOLD); if (readSnEnumsComparator != null) { setSnEnumsComparator(readSnEnumsComparator, readSnEnumComparatorThreshold); } String readAvoidSore = properties.getProperty(KEY_AVOID_SORE); if (readAvoidSore != null) { setAvoidSORE(readAvoidSore); } String readTryECHARE = properties.getProperty(KEY_TRY_ECHARE); if (readTryECHARE != null) { setTryECHARE(readTryECHARE); } Set<String> foundOptimizersKeys = Sets.filter(properties.stringPropertyNames(), Predicates.containsPattern("^\\Q" + KEY_MULTIPLE_OPTIMIZERS + "\\E.*$")); if (!foundOptimizersKeys.isEmpty()) { optimizers.clear(); Set<String> foundOptimizersValues = new HashSet<String>(foundOptimizersKeys.size()); for (String foundOptimizerKey : foundOptimizersKeys) { foundOptimizersValues.add(properties.getProperty(foundOptimizerKey)); } addOptimizersFromStringsSet(foundOptimizersValues); } String readStrictValidRootDefinitionWorkaround = properties .getProperty(KEY_STRICT_VALID_ROOT_DEFINITION_WORKAROUND); if (readStrictValidRootDefinitionWorkaround != null) { setStrictValidRootDefinitionWorkaround(readStrictValidRootDefinitionWorkaround); } String readElementsGlobal = properties.getProperty(KEY_ELEMENTS_GLOBAL); if (readElementsGlobal != null) { setElementsGlobal(readElementsGlobal); } String readComplexTypesGlobal = properties.getProperty(KEY_COMPLEX_TYPES_GLOBAL); if (readComplexTypesGlobal != null) { setComplexTypesGlobal(readComplexTypesGlobal); } String readSimpleTypesGlobal = properties.getProperty(KEY_SIMPLE_TYPES_GLOBAL); if (readSimpleTypesGlobal != null) { setSimpleTypesGlobal(readSimpleTypesGlobal); } String readTypeNamesAncestorSeparator = properties.getProperty(KEY_TYPE_NAMES_ANCESTORS_SEPARATOR); if (readTypeNamesAncestorSeparator != null) { setTypeNamesAncestorsSeparator(readTypeNamesAncestorSeparator); } String readMergedTypesSeparator = properties.getProperty(KEY_MERGED_TYPES_SEPARATOR); if (readMergedTypesSeparator != null) { setMergedTypesSeparator(readMergedTypesSeparator); } }