List of usage examples for com.google.common.base Predicates equalTo
public static <T> Predicate<T> equalTo(@Nullable T target)
From source file:brooklyn.entity.basic.EntityPredicates.java
public static <T> Predicate<Entity> attributeNotEqualTo(final AttributeSensor<T> attribute, final T val) { return attributeSatisfies(attribute, Predicates.not(Predicates.equalTo(val))); }
From source file:org.grouplens.grapht.graph.DAGNode.java
/** * Get an outgoing edge from this node with the specified label, if it exists. * * @param label The label./*w w w. j a v a 2 s. c om*/ * @return An outgoing edge with the specified label, or {@code null} if no such edge exists. * If multiple edges have this label, an arbitrary one is returned. */ public DAGEdge<V, E> getOutgoingEdgeWithLabel(E label) { return getOutgoingEdgeWithLabel(Predicates.equalTo(label)); }
From source file:brooklyn.entity.basic.EntityPredicates.java
public static <T> Predicate<Entity> configEqualTo(final ConfigKey<T> configKey, final T val) { return configSatisfies(configKey, Predicates.equalTo(val)); }
From source file:brooklyn.location.docker.DockerContainerLocation.java
private void parseDockerCallback(String commandString) { List<String> tokens = DockerCallbacks.PARSER.splitToList(commandString); int callback = Iterables.indexOf(tokens, Predicates.equalTo(DockerCallbacks.DOCKER_HOST_CALLBACK)); if (callback == -1) { LOG.warn("Could not find callback token: {}", commandString); throw new IllegalStateException("Cannot find callback token in command line"); }//from w w w .j a v a 2 s. c o m String command = tokens.get(callback + 1); LOG.info("Executing callback for {}: {}", getOwner(), command); if (DockerCallbacks.COMMIT.equalsIgnoreCase(command)) { String containerId = getOwner().getContainerId(); String imageName = getOwner().getAttribute(DockerContainer.IMAGE_NAME); String output = getOwner().getDockerHost() .runDockerCommandTimeout(format("commit %s %s", containerId, imageName), Duration.minutes(20)); String imageId = DockerUtils.checkId(output); ((EntityLocal) getOwner().getRunningEntity()).setAttribute(DockerContainer.IMAGE_ID, imageId); ((EntityLocal) getOwner()).setAttribute(DockerContainer.IMAGE_ID, imageId); getOwner().getDockerHost().getDynamicLocation().markImage(imageName); } else if (DockerCallbacks.PUSH.equalsIgnoreCase(command)) { String imageName = getOwner().getAttribute(DockerContainer.IMAGE_NAME); getOwner().getDockerHost().runDockerCommand(format("push %s", imageName)); } else if (DockerCallbacks.SUBNET_ADDRESS.equalsIgnoreCase(command)) { String address = getOwner().getAttribute(Attributes.SUBNET_ADDRESS); ((EntityLocal) getOwner().getRunningEntity()).setAttribute(Attributes.SUBNET_ADDRESS, address); ((EntityLocal) getOwner().getRunningEntity()).setAttribute(Attributes.SUBNET_HOSTNAME, address); } else { LOG.warn("Unknown Docker host command: {}", command); } }
From source file:sai.graph.jgrapht.Graph.java
/** associate feature t with this graph. t must not conflict with existing * features. If t, or an equivalent feature, is already associated, no action is taken. * Otherwise, the feature is added and the ID associating this object with * a stored graph is cleared./*from w ww.j ava2 s. c o m*/ * @param t */ public void addFeature(Feature t) { int size = features.size(); features.add(t); for (Feature f : features) { if (!f.canAccompany(Collections2.filter(features, Predicates.equalTo(f)))) { features.remove(t); throw new IllegalArgumentException("Added feature cannot accompany existing features"); } } }
From source file:clocker.mesos.entity.MesosClusterImpl.java
@Override public void init() { LOG.info("Starting Mesos cluster id {}", getId()); registerLocationResolver();/* ww w. j a va2 s. c om*/ super.init(); Group slaves = addChild(EntitySpec.create(BasicGroup.class).displayName("Mesos Slaves")); Group frameworks = addChild(EntitySpec.create(BasicGroup.class).displayName("Mesos Frameworks")); DynamicGroup tasks = addChild(EntitySpec.create(DynamicGroup.class) .configure(DynamicGroup.ENTITY_FILTER, Predicates.and(Predicates.instanceOf(MesosTask.class), EntityPredicates.attributeEqualTo(MesosAttributes.MESOS_CLUSTER, this))) .displayName("Mesos Tasks")); DynamicMultiGroup applications = addChild(EntitySpec.create(DynamicMultiGroup.class) .configure(DynamicMultiGroup.ENTITY_FILTER, Predicates.and(MesosUtils.sameCluster(this), Predicates.not(EntityPredicates.applicationIdEqualTo(getApplicationId())))) .configure(DynamicMultiGroup.RESCAN_INTERVAL, 15L) .configure(DynamicMultiGroup.BUCKET_FUNCTION, new Function<Entity, String>() { @Override public String apply(@Nullable Entity input) { return input.getApplication().getDisplayName() + ":" + input.getApplicationId(); } }).configure(DynamicMultiGroup.BUCKET_SPEC, EntitySpec.create(BasicGroup.class)) .displayName("Mesos Applications")); if (config().get(SDN_ENABLE) && config().get(SDN_PROVIDER_SPEC) != null) { EntitySpec entitySpec = EntitySpec.create(config().get(SDN_PROVIDER_SPEC)); entitySpec.configure(MesosAttributes.MESOS_CLUSTER, this); Entity sdn = addChild(entitySpec); sensors().set(SDN_PROVIDER, sdn); } sensors().set(MESOS_SLAVES, slaves); sensors().set(MESOS_FRAMEWORKS, frameworks); sensors().set(MESOS_TASKS, tasks); sensors().set(MESOS_APPLICATIONS, applications); // Override the health-check: just interested in the slaves, frameworks and sdn (rather than // the groups that show the tasks or apps). Entity sdn = sensors().get(SDN_PROVIDER); enrichers().add(EnricherSpec.create(ComputeServiceIndicatorsFromChildrenAndMembers.class) .uniqueTag(ComputeServiceIndicatorsFromChildrenAndMembers.DEFAULT_UNIQUE_TAG) .configure(ComputeServiceIndicatorsFromChildrenAndMembers.FROM_CHILDREN, true) .configure(ComputeServiceIndicatorsFromChildrenAndMembers.ENTITY_FILTER, Predicates.or(ImmutableList.of(Predicates.<Entity>equalTo(slaves), Predicates.<Entity>equalTo(frameworks), (sdn == null ? Predicates.<Entity>alwaysFalse() : Predicates.equalTo(sdn)))))); }
From source file:com.facebook.watchman.WatchmanClientImpl.java
/** * unsubscribes from all the subscriptions; convenience method *//*from w ww. j a va 2 s. co m*/ @Override public ListenableFuture<Boolean> unsubscribeAll() { Collection<ListenableFuture<Boolean>> unsubscribeAll = Collections2.transform(subscriptions.keySet(), new Function<SubscriptionDescriptor, ListenableFuture<Boolean>>() { @Nullable @Override public ListenableFuture<Boolean> apply(@Nullable SubscriptionDescriptor input) { return unsubscribe(input); } }); return Futures.transform(Futures.allAsList(unsubscribeAll), new Function<List<Boolean>, Boolean>() { @Nullable @Override public Boolean apply(@Nullable List<Boolean> input) { return !Collections2.filter(input, Predicates.equalTo(false)).isEmpty(); } }); }
From source file:eu.stratosphere.sopremo.expressions.EvaluationExpression.java
/** * Replaces all expressions that are equal to <code>toReplace</code> with the given <code>replaceFragment</code> . * /*from w w w .ja va2s .co m*/ * @param toReplace * the expressions that should be replaced * @param replaceFragment * the expression which should replace another one * @return the expression with the replaces */ public EvaluationExpression replace(final EvaluationExpression toReplace, final EvaluationExpression replaceFragment) { return this.replace(Predicates.equalTo(toReplace), replaceFragment); }
From source file:org.xwiki.scripting.documentation.internal.ExtensionBindingResource.java
private Set<String> getPomPropertyFiles() { ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.setScanners(new ResourcesScanner()); configurationBuilder.setUrls(url);// w w w.j av a 2 s .c om configurationBuilder.filterInputsBy(new FilterBuilder.Include(FilterBuilder.prefix("META-INF.maven"))); Reflections reflections = new Reflections(configurationBuilder); return reflections.getResources(Predicates.equalTo("pom.properties")); }
From source file:com.google.devtools.build.lib.skyframe.SkylarkImportLookupFunction.java
private SkyValue computeInternal(Label fileLabel, boolean inWorkspace, Environment env, @Nullable LinkedHashMap<Label, SkylarkImportLookupValue> alreadyVisited) throws InconsistentFilesystemException, SkylarkImportFailedException, InterruptedException { PathFragment filePath = fileLabel.toPathFragment(); // Load the AST corresponding to this file. ASTFileLookupValue astLookupValue;/*from ww w. j a v a 2 s .c o m*/ try { SkyKey astLookupKey = ASTFileLookupValue.key(fileLabel); astLookupValue = (ASTFileLookupValue) env.getValueOrThrow(astLookupKey, ErrorReadingSkylarkExtensionException.class, InconsistentFilesystemException.class); } catch (ErrorReadingSkylarkExtensionException e) { throw SkylarkImportFailedException.errorReadingFile(filePath, e.getMessage()); } if (astLookupValue == null) { return null; } if (!astLookupValue.lookupSuccessful()) { // Skylark import files have to exist. throw SkylarkImportFailedException.noFile(astLookupValue.getErrorMsg()); } BuildFileAST ast = astLookupValue.getAST(); if (ast.containsErrors()) { throw SkylarkImportFailedException.skylarkErrors(filePath); } // Process the load statements in the file. ImmutableList<SkylarkImport> imports = ast.getImports(); Map<String, Extension> extensionsForImports = Maps.newHashMapWithExpectedSize(imports.size()); ImmutableList.Builder<SkylarkFileDependency> fileDependencies = ImmutableList.builder(); ImmutableMap<String, Label> labelsForImports; // Find the labels corresponding to the load statements. labelsForImports = findLabelsForLoadStatements(imports, fileLabel, env); if (labelsForImports == null) { return null; } // Look up and load the imports. ImmutableCollection<Label> importLabels = labelsForImports.values(); List<SkyKey> importLookupKeys = Lists.newArrayListWithExpectedSize(importLabels.size()); for (Label importLabel : importLabels) { importLookupKeys.add(SkylarkImportLookupValue.key(importLabel, inWorkspace)); } Map<SkyKey, SkyValue> skylarkImportMap; boolean valuesMissing = false; if (alreadyVisited == null) { // Not inlining. skylarkImportMap = env.getValues(importLookupKeys); valuesMissing = env.valuesMissing(); } else { // Inlining calls to SkylarkImportLookupFunction. if (alreadyVisited.containsKey(fileLabel)) { ImmutableList<Label> cycle = CycleUtils.splitIntoPathAndChain(Predicates.equalTo(fileLabel), alreadyVisited.keySet()).second; throw new SkylarkImportFailedException("Skylark import cycle: " + cycle); } alreadyVisited.put(fileLabel, null); skylarkImportMap = Maps.newHashMapWithExpectedSize(imports.size()); for (SkyKey importLookupKey : importLookupKeys) { SkyValue skyValue = this.computeWithInlineCallsInternal(importLookupKey, env, alreadyVisited); if (skyValue == null) { Preconditions.checkState(env.valuesMissing(), "no skylark import value for %s", importLookupKey); // We continue making inline calls even if some requested values are missing, to maximize // the number of dependent (non-inlined) SkyFunctions that are requested, thus avoiding a // quadratic number of restarts. valuesMissing = true; } else { skylarkImportMap.put(importLookupKey, skyValue); } } // All imports traversed, this key can no longer be part of a cycle. Preconditions.checkState(alreadyVisited.remove(fileLabel) == null, fileLabel); } if (valuesMissing) { // This means some imports are unavailable. return null; } // Process the loaded imports. for (Entry<String, Label> importEntry : labelsForImports.entrySet()) { String importString = importEntry.getKey(); Label importLabel = importEntry.getValue(); SkyKey keyForLabel = SkylarkImportLookupValue.key(importLabel, inWorkspace); SkylarkImportLookupValue importLookupValue = (SkylarkImportLookupValue) skylarkImportMap .get(keyForLabel); extensionsForImports.put(importString, importLookupValue.getEnvironmentExtension()); fileDependencies.add(importLookupValue.getDependency()); } // Skylark UserDefinedFunction-s in that file will share this function definition Environment, // which will be frozen by the time it is returned by createExtension. Extension extension = createExtension(ast, fileLabel, extensionsForImports, env, inWorkspace); SkylarkImportLookupValue result = new SkylarkImportLookupValue(extension, new SkylarkFileDependency(fileLabel, fileDependencies.build())); if (alreadyVisited != null) { alreadyVisited.put(fileLabel, result); } return result; }