List of usage examples for com.google.common.base Predicates equalTo
public static <T> Predicate<T> equalTo(@Nullable T target)
From source file:org.sosy_lab.cpachecker.core.algorithm.pdr.transition.Blocks.java
/** * Combine the reached sets of the given blocks and insert their states into * the given target reached set./*from ww w. ja v a 2 s. c om*/ * * @param pBlocks the blocks. The order of the blocks is expected to be * 'forward', e.g. from the program entry to a target state. * * @param pTargetReachedSet the target reached set. */ public static void combineReachedSets(Iterable<Block> pBlocks, ReachedSet pTargetReachedSet) { if (Iterables.isEmpty(pBlocks)) { return; } AbstractState previousState = null; ARGState argPreviousState = null; List<Iterable<StateWithPrecision>> blockStates = new ArrayList<>(); for (Block block : pBlocks) { ReachedSet reachedSet = block.getReachedSet(); AbstractState firstState = block.getPredecessor(); final AbstractState removed; if (argPreviousState == null) { removed = null; } else { ARGState argFirstState = AbstractStates.extractStateByType(firstState, ARGState.class); Preconditions .checkArgument(!Sets .intersection( FluentIterable.from(AbstractStates.extractLocations(argPreviousState)) .toSet(), FluentIterable.from(AbstractStates.extractLocations(argFirstState)).toSet()) .isEmpty(), "Blocks must connect."); if (block.getDirection() == AnalysisDirection.FORWARD) { for (ARGState childOfFirstState : argFirstState.getChildren()) { childOfFirstState.addParent(argPreviousState); } argFirstState.removeFromARG(); removed = firstState; } else { for (ARGState childOfPreviousState : argPreviousState.getChildren()) { childOfPreviousState.addParent(argFirstState); } argPreviousState.removeFromARG(); removed = argPreviousState; } } Iterable<StateWithPrecision> remainingStates = FluentIterable.from(reachedSet) .filter(Predicates.not(Predicates.equalTo(removed))) .filter(as -> !AbstractStates.extractStateByType(as, ARGState.class).isDestroyed()) .transform(as -> new StateWithPrecision(as, reachedSet.getPrecision(as))); blockStates.add(remainingStates); previousState = block.getSuccessor(); argPreviousState = AbstractStates.extractStateByType(previousState, ARGState.class); } ListIterator<Iterable<StateWithPrecision>> blockStatesIterator = blockStates .listIterator(blockStates.size()); while (blockStatesIterator.hasPrevious()) { for (StateWithPrecision stateWithPrecision : blockStatesIterator.previous()) { pTargetReachedSet.add(stateWithPrecision.state, stateWithPrecision.precision); pTargetReachedSet.removeOnlyFromWaitlist(stateWithPrecision.state); } } }
From source file:org.jclouds.googlecomputeengine.compute.extensions.GoogleComputeEngineSecurityGroupExtension.java
private SecurityGroup groupForTagsInNetwork(Network nw, final Set<String> tags) { ListOptions opts = new Builder().filter("network eq .*/" + nw.getName()); Set<Firewall> fws = api.getFirewallApiForProject(userProject.get()).list(opts).concat() .filter(new Predicate<Firewall>() { @Override// w w w . jav a 2s . c om public boolean apply(final Firewall input) { // If any of the targetTags on the firewall apply or the firewall has no target tags... return Iterables.any(input.getTargetTags(), Predicates.in(tags)) || Predicates.equalTo(0).apply(input.getTargetTags().size()); } }).toSet(); if (fws.isEmpty()) { return null; } return groupConverter.apply(nw); }
From source file:io.selendroid.standalone.server.model.DeviceStore.java
private Predicate<AndroidDevice> deviceSatisfiesCapabilities(final SelendroidCapabilities capabilities) { return new Predicate<AndroidDevice>() { @Override// w w w. j a v a2 s .c o m public boolean apply(AndroidDevice candidate) { ArrayList<Boolean> booleanExpressions = Lists.newArrayList( candidate.screenSizeMatches(capabilities.getScreenSize()), capabilities.getEmulator() == null ? true : capabilities.getEmulator() ? candidate instanceof DefaultAndroidEmulator : candidate instanceof DefaultHardwareDevice, StringUtils.isNotBlank(capabilities.getSerial()) ? capabilities.getSerial().equals(candidate.getSerial()) : true, StringUtils.isNotBlank(capabilities.getModel()) ? candidate.getModel().contains(capabilities.getModel()) : true, StringUtils.isNotBlank(capabilities.getAPITargetType()) ? candidate.getAPITargetType() != null && candidate.getAPITargetType().contains(capabilities.getAPITargetType()) : true); return Iterables.all(booleanExpressions, Predicates.equalTo(true)); } }; }
From source file:ec.nbdemetra.ui.DemetraUI.java
private static <X, Y> X find(Class<X> clazz, Function<? super X, Y> toName, Y... names) { Collection<? extends X> items = Lookup.getDefault().lookupAll(clazz); for (Y o : names) { Optional<? extends X> result = Iterables.tryFind(items, Predicates.compose(Predicates.equalTo(o), toName)); if (result.isPresent()) { return result.get(); }/* w w w .j a va 2 s . com*/ } return null; }
From source file:com.google.devtools.build.lib.rules.cpp.LinkBuildVariables.java
private static Iterable<String> removePieIfCreatingSharedLibrary(boolean isCreatingSharedLibrary, List<String> flags) { if (isCreatingSharedLibrary) { return Iterables.filter(flags, Predicates.not(Predicates.equalTo("-pie"))); } else {/*from w w w . j a va 2s. c o m*/ return flags; } }
From source file:com.google.javascript.jscomp.AggressiveInlineAliases.java
/** * Attempts to inline a non-global alias of a global name. * * <p>It is assumed that the name for which it is an alias meets conditions (a) and (b). * * <p>The non-global alias is only inlinable if it is well-defined and assigned once, according to * the definitions in {@link ReferenceCollection} * * <p>If the aliasing name is completely removed, also deletes the aliasing Ref. * * @param name The global name being aliased * @param alias The aliasing reference to the name to remove */// w w w.ja v a 2 s .com private void inlineAliasIfPossible(Name name, Ref alias, GlobalNamespace namespace) { // Ensure that the alias is assigned to a local variable at that // variable's declaration. If the alias's parent is a NAME, // then the NAME must be the child of a VAR, LET, or CONST node, and we must // be in a VAR, LET, or CONST assignment. // Otherwise if the parent is an assign, we are in a "a = alias" case. Node aliasParent = alias.node.getParent(); if (aliasParent.isName() || aliasParent.isAssign()) { Node aliasLhsNode = aliasParent.isName() ? aliasParent : aliasParent.getFirstChild(); String aliasVarName = aliasLhsNode.getString(); Var aliasVar = alias.scope.getVar(aliasVarName); checkState(aliasVar != null, "Expected variable to be defined in scope", aliasVarName); ReferenceCollectingCallback collector = new ReferenceCollectingCallback(compiler, ReferenceCollectingCallback.DO_NOTHING_BEHAVIOR, new Es6SyntacticScopeCreator(compiler), Predicates.equalTo(aliasVar)); Scope aliasScope = aliasVar.getScope(); collector.processScope(aliasScope); ReferenceCollection aliasRefs = collector.getReferences(aliasVar); Set<AstChange> newNodes = new LinkedHashSet<>(); if (aliasRefs.isWellDefined() && aliasRefs.isAssignedOnceInLifetime()) { // The alias is well-formed, so do the inlining now. int size = aliasRefs.references.size(); // It's initialized on either the first or second reference. int firstRead = aliasRefs.references.get(0).isInitializingDeclaration() ? 1 : 2; for (int i = firstRead; i < size; i++) { Reference aliasRef = aliasRefs.references.get(i); newNodes.add(replaceAliasReference(alias, aliasRef)); } // just set the original alias to null. if (tryReplacingAliasingAssignment(alias, aliasLhsNode)) { name.removeRef(alias); } // Inlining the variable may have introduced new references // to descendants of {@code name}. So those need to be collected now. namespace.scanNewNodes(newNodes); return; } if (name.isConstructor()) { // TODO(lharker): the main reason this was added is because method decomposition inside // generators introduces some constructor aliases that weren't getting inlined. // If we find another (safer) way to avoid aliasing in method decomposition, consider // removing this. if (!partiallyInlineAlias(alias, namespace, aliasRefs, aliasLhsNode)) { // If we can't inline all alias references, make sure there are no unsafe property // accesses. if (referencesCollapsibleProperty(aliasRefs, name, namespace)) { compiler.report(JSError.make(aliasParent, UNSAFE_CTOR_ALIASING, aliasVarName)); } } } } }
From source file:com.google.javascript.jscomp.CollapseProperties.java
private boolean inlineAliasIfPossible(Name name, Ref alias, GlobalNamespace namespace) { // Ensure that the alias is assigned to a local variable at that // variable's declaration. If the alias's parent is a NAME, // then the NAME must be the child of a VAR node, and we must // be in a VAR assignment. Node aliasParent = alias.node.getParent(); if (aliasParent.isName()) { // Ensure that the local variable is well defined and never reassigned. Scope scope = alias.scope;/*w ww . j av a 2 s .co m*/ String aliasVarName = aliasParent.getString(); Var aliasVar = scope.getVar(aliasVarName); ReferenceCollectingCallback collector = new ReferenceCollectingCallback(compiler, ReferenceCollectingCallback.DO_NOTHING_BEHAVIOR, Predicates.equalTo(aliasVar)); collector.processScope(scope); ReferenceCollection aliasRefs = collector.getReferences(aliasVar); Set<AstChange> newNodes = new LinkedHashSet<>(); if (aliasRefs.isWellDefined() && aliasRefs.firstReferenceIsAssigningDeclaration()) { if (!aliasRefs.isAssignedOnceInLifetime()) { // Static properties of constructors are always collapsed. // So, if a constructor is aliased and its properties are accessed from // the alias, we would like to inline the alias here to access the // properties correctly. // But if the aliased variable is assigned more than once, we can't // inline, so we warn. if (name.isConstructor()) { boolean accessPropsAfterAliasing = false; for (Reference ref : aliasRefs.references) { if (ref.getNode().getParent().isGetProp()) { accessPropsAfterAliasing = true; break; } } if (accessPropsAfterAliasing) { compiler.report(JSError.make(aliasParent, UNSAFE_CTOR_ALIASING, aliasVarName)); } } return false; } // The alias is well-formed, so do the inlining now. int size = aliasRefs.references.size(); for (int i = 1; i < size; i++) { ReferenceCollectingCallback.Reference aliasRef = aliasRefs.references.get(i); Node newNode = alias.node.cloneTree(); aliasRef.getParent().replaceChild(aliasRef.getNode(), newNode); newNodes.add(new AstChange(getRefModule(aliasRef), aliasRef.getScope(), newNode)); } // just set the original alias to null. aliasParent.replaceChild(alias.node, IR.nullNode()); compiler.reportCodeChange(); // Inlining the variable may have introduced new references // to descendants of {@code name}. So those need to be collected now. namespace.scanNewNodes(newNodes); return true; } } return false; }
From source file:com.google.devtools.build.lib.rules.cpp.LinkCommandLine.java
private ImmutableList<String> getToolchainFlags() { boolean fullyStatic = (linkStaticness == LinkStaticness.FULLY_STATIC); boolean mostlyStatic = (linkStaticness == LinkStaticness.MOSTLY_STATIC); boolean sharedLinkopts = linkTargetType == LinkTargetType.DYNAMIC_LIBRARY || linkopts.contains("-shared") || cppConfiguration.getLinkOptions().contains("-shared"); List<String> toolchainFlags = new ArrayList<>(); /*/*from w ww . ja v a2s .co m*/ * For backwards compatibility, linkopts come _after_ inputFiles. * This is needed to allow linkopts to contain libraries and * positional library-related options such as * -Wl,--begin-group -lfoo -lbar -Wl,--end-group * or * -Wl,--as-needed -lfoo -Wl,--no-as-needed * * As for the relative order of the three different flavours of linkopts * (global defaults, per-target linkopts, and command-line linkopts), * we have no idea what the right order should be, or if anyone cares. */ toolchainFlags.addAll(linkopts); // Extra toolchain link options based on the output's link staticness. if (fullyStatic) { toolchainFlags.addAll(cppConfiguration.getFullyStaticLinkOptions(features, sharedLinkopts)); } else if (mostlyStatic) { toolchainFlags.addAll(cppConfiguration.getMostlyStaticLinkOptions(features, sharedLinkopts)); } else { toolchainFlags.addAll(cppConfiguration.getDynamicLinkOptions(features, sharedLinkopts)); } // Extra test-specific link options. if (useTestOnlyFlags) { toolchainFlags.addAll(cppConfiguration.getTestOnlyLinkOptions()); } toolchainFlags.addAll(cppConfiguration.getLinkOptions()); // -pie is not compatible with shared and should be // removed when the latter is part of the link command. Should we need to further // distinguish between shared libraries and executables, we could add additional // command line / CROSSTOOL flags that distinguish them. But as long as this is // the only relevant use case we're just special-casing it here. if (linkTargetType == LinkTargetType.DYNAMIC_LIBRARY) { Iterables.removeIf(toolchainFlags, Predicates.equalTo("-pie")); } // Fission mode: debug info is in .dwo files instead of .o files. Inform the linker of this. if (linkTargetType.staticness() == Staticness.DYNAMIC && cppConfiguration.useFission()) { toolchainFlags.add("-Wl,--gdb-index"); } return ImmutableList.copyOf(toolchainFlags); }
From source file:com.eucalyptus.network.NetworkGroupManager.java
public AuthorizeSecurityGroupIngressResponseType authorize(final AuthorizeSecurityGroupIngressType request) throws Exception { final Context ctx = Contexts.lookup(); final AuthorizeSecurityGroupIngressResponseType reply = request.getReply(); final EntityTransaction db = Entities.get(NetworkGroup.class); try {//from w w w .j a v a 2 s . c om final NetworkGroup ruleGroup = lookupGroup(request.getGroupId(), request.getGroupName()); if (!RestrictedTypes.filterPrivileged().apply(ruleGroup)) { throw new EucalyptusCloudException("Not authorized to authorize network group " + ruleGroup.getDisplayName() + " for " + ctx.getUser()); } final List<NetworkRule> ruleList = Lists.newArrayList(); List<IpPermissionType> ipPermissions = handleOldAndNewIpPermissions(request.getCidrIp(), request.getIpProtocol(), request.getFromPort(), request.getToPort(), request.getSourceSecurityGroupName(), request.getSourceSecurityGroupOwnerId(), request.getIpPermissions()); NetworkGroups.resolvePermissions(ipPermissions, ctx.getUser().getAccountNumber(), false); for (final IpPermissionType ipPerm : ipPermissions) { if (ipPerm.getCidrIpRanges().isEmpty() && ipPerm.getGroups().isEmpty()) { continue; // see EUCA-5934 } try { final List<NetworkRule> rules = NetworkGroups.IpPermissionTypeAsNetworkRule.INSTANCE .apply(ipPerm); ruleList.addAll(rules); } catch (final IllegalArgumentException ex) { throw new ClientComputeException("InvalidPermission.Malformed", ex.getMessage()); } } if (Iterables.any(ruleGroup.getNetworkRules(), new Predicate<NetworkRule>() { @Override public boolean apply(final NetworkRule rule) { return Iterables.any(ruleList, Predicates.equalTo(rule)); } })) { reply.set_return(false); return reply; } else { ruleGroup.getNetworkRules().addAll(ruleList); reply.set_return(true); } db.commit(); NetworkGroups.flushRules(); return reply; } catch (Exception ex) { Logs.exhaust().error(ex, ex); throw ex; } finally { if (db.isActive()) db.rollback(); } }
From source file:org.renjin.primitives.Attributes.java
@Internal public static SEXP inherits(SEXP exp, StringVector what, boolean which) { if (!which) { return new LogicalArrayVector(inherits(exp, what)); }//from ww w .ja v a 2s .co m StringVector classes = getClass(exp); int result[] = new int[what.length()]; for (int i = 0; i != what.length(); ++i) { result[i] = Iterables.indexOf(classes, Predicates.equalTo(what.getElementAsString(i))) + 1; } return new IntArrayVector(result); }