List of usage examples for com.google.common.collect FluentIterable anyMatch
@CheckReturnValue public final boolean anyMatch(Predicate<? super E> predicate)
From source file:com.google.api.tools.framework.importers.swagger.MethodBuilder.java
/** * Returns all parameters for the operation. Note: According to the spec, parameters defined * inside the operations overrides the parameters defined in the path scope which has the same * name and location values (example name : 'shelveId' and location : 'query'). *///ww w . j a v a 2s .c o m public static ImmutableList<Parameter> getAllResolvedParameters(Operation operation, Path parentPath, final DiagCollector diagCollector, Location location) { List<Parameter> allResolvedParameters = new ArrayList<>(); // First populate all the parameters defined in the operation. if (operation.getParameters() != null) { ImmutableList<Parameter> resolvedParameters = getResolvedParameters(diagCollector, ImmutableList.copyOf(operation.getParameters()), location); allResolvedParameters.addAll(resolvedParameters); } FluentIterable<Parameter> fluentAllParameters = FluentIterable.from(allResolvedParameters); // Now populate shared parameters that were not overridden inside the operation. if (parentPath.getParameters() != null) { ImmutableList<Parameter> resolvedSharedParameters = getResolvedParameters(diagCollector, ImmutableList.copyOf(parentPath.getParameters()), location); for (final Parameter sharedParam : resolvedSharedParameters) { boolean overriddenInOperation = fluentAllParameters.anyMatch(new Predicate<Parameter>() { @Override public boolean apply(Parameter parameter) { return parameter.getName().equals(sharedParam.getName()) && parameter.getIn().equals(sharedParam.getIn()); } }); if (!overriddenInOperation) { allResolvedParameters.add(sharedParam); } } } return ImmutableList.copyOf(allResolvedParameters); }
From source file:com.google.errorprone.bugpatterns.inject.dagger.PrivateConstructorForNoninstantiableModule.java
@Override public Description matchClass(ClassTree classTree, VisitorState state) { if (!DaggerAnnotations.isAnyModule().matches(classTree, state)) { return NO_MATCH; }/*from w w w .ja va 2 s. c o m*/ // if a module is declared as an interface, skip it if (!classTree.getKind().equals(CLASS)) { return NO_MATCH; } FluentIterable<? extends Tree> nonSyntheticMembers = FluentIterable.from(classTree.getMembers()) .filter(Predicates.not(new Predicate<Tree>() { @Override public boolean apply(Tree tree) { return tree.getKind().equals(METHOD) && isGeneratedConstructor((MethodTree) tree); } })); // ignore empty modules if (nonSyntheticMembers.isEmpty()) { return NO_MATCH; } if (nonSyntheticMembers.anyMatch(IS_CONSTRUCTOR)) { return NO_MATCH; } boolean hasBindingDeclarationMethods = nonSyntheticMembers .anyMatch(matcherAsPredicate(isBindingDeclarationMethod(), state)); if (hasBindingDeclarationMethods) { return describeMatch(classTree, addPrivateConstructor(classTree, state)); } boolean allStaticMembers = nonSyntheticMembers.allMatch(matcherAsPredicate(isStatic(), state)); if (allStaticMembers) { return describeMatch(classTree, addPrivateConstructor(classTree, state)); } return NO_MATCH; }
From source file:com.google.api.codegen.csharp.CSharpDiscoveryContext.java
public Iterable<String> sortUsings(Iterable<String> usings) { Predicate<String> isAlias = new Predicate<String>() { @Override//from w w w. jav a 2s . c om public boolean apply(String using) { return using.contains("="); } }; FluentIterable<String> fluentUsings = FluentIterable.from(usings).transform(new Function<String, String>() { @Override public String apply(String using) { return "using " + using + ";"; } }); Iterable<String> aliases = fluentUsings.anyMatch(isAlias) ? FluentIterable.of(new String[] { "" }).append(fluentUsings.filter(isAlias)) : Collections.<String>emptyList(); return fluentUsings.filter(Predicates.<String>not(isAlias)).append(aliases); }
From source file:org.opendaylight.controller.md.compatibility.topologymanager.CompatibleTopologyManager.java
/** * Returns true if point is connected to link *///www . j a v a2 s . c om public boolean isInternal(final TerminationPoint point) { TypeSafeDataReader _dataReader = this.getDataReader(); InstanceIdentifier<Topology> _topologyPath = this._topologyMapping.getTopologyPath(); final Topology topology = _dataReader.<Topology>readConfigurationData(_topologyPath); TerminationPointKey _key = point.getKey(); final TpId tpId = _key.getTpId(); List<Link> _link = topology.getLink(); FluentIterable<Link> _from = FluentIterable.<Link>from(_link); final Predicate<Link> _function = new Predicate<Link>() { public boolean apply(final Link it) { boolean _or = false; Source _source = it.getSource(); TpId _sourceTp = _source.getSourceTp(); boolean _equals = Objects.equal(_sourceTp, tpId); if (_equals) { _or = true; } else { Destination _destination = it.getDestination(); TpId _destTp = _destination.getDestTp(); boolean _equals_1 = Objects.equal(_destTp, tpId); _or = (_equals || _equals_1); } return _or; } }; return _from.anyMatch(_function); }
From source file:org.sosy_lab.cpachecker.core.counterexample.AssumptionToEdgeAllocator.java
private @Nullable AExpressionStatement buildEquationExpressionStatement(CBinaryExpressionBuilder pBuilder, CExpression pLeftSide, CExpression pRightSide) { CExpression leftSide = pLeftSide;//from www . j a va 2 s . c om CExpression rightSide = pRightSide; final CType leftType = leftSide.getExpressionType().getCanonicalType(); final CType rightType = rightSide.getExpressionType().getCanonicalType(); if (leftType instanceof CVoidType && rightType instanceof CVoidType) { return null; } boolean equalTypes = leftType.equals(rightType); FluentIterable<Class<? extends CType>> acceptedTypes = FluentIterable .from(Collections.<Class<? extends CType>>singleton(CSimpleType.class)); if (includeConstantsForPointers) { acceptedTypes = acceptedTypes.append(Arrays.asList(CArrayType.class, CPointerType.class)); } boolean leftIsAccepted = equalTypes || acceptedTypes.anyMatch(new Predicate<Class<? extends CType>>() { @Override public boolean apply(Class<? extends CType> pArg0) { return pArg0.isAssignableFrom(leftType.getClass()); } }); boolean rightIsAccepted = equalTypes || acceptedTypes.anyMatch(new Predicate<Class<? extends CType>>() { @Override public boolean apply(Class<? extends CType> pArg0) { return pArg0.isAssignableFrom(rightType.getClass()); } }); if (!includeConstantsForPointers && (!leftIsAccepted || !rightIsAccepted)) { return null; } if (leftType instanceof CSimpleType && !rightIsAccepted) { rightSide = new CCastExpression(rightSide.getFileLocation(), leftType, rightSide); } else if (!leftIsAccepted && rightType instanceof CSimpleType) { leftSide = new CCastExpression(leftSide.getFileLocation(), rightType, leftSide); } CBinaryExpression assumption = pBuilder.buildBinaryExpressionUnchecked(leftSide, rightSide, CBinaryExpression.BinaryOperator.EQUALS); return new CExpressionStatement(assumption.getFileLocation(), assumption); }