List of usage examples for com.google.common.base Predicates equalTo
public static <T> Predicate<T> equalTo(@Nullable T target)
From source file:org.apache.aurora.scheduler.updater.OneWayJobUpdater.java
private static <K, T> Set<K> filterByStatus(Map<K, InstanceUpdate<T>> instances, SideEffect.InstanceUpdateStatus status) { return ImmutableSet.copyOf( Maps.filterValues(instances, Predicates.compose(Predicates.equalTo(status), GET_STATE)).keySet()); }
From source file:org.apache.brooklyn.core.sensor.password.CreatePasswordSensor.java
@Override public void apply(EntityLocal entity) { super.apply(entity); boolean isCharacterGroupsPresent = characterGroups != null && characterGroups.size() > 0; boolean isCharacterGroupsValid = isCharacterGroupsPresent && !Iterables.contains(characterGroups, Predicates.isNull()) && !Iterables.contains(characterGroups, Predicates.equalTo("")); boolean isAcceptableCharsPresentAndValid = acceptableChars != null && !acceptableChars.isEmpty(); Preconditions.checkArgument(!isCharacterGroupsPresent || isCharacterGroupsValid, "password.character.groups config key was given but does not contain any valid groups"); Preconditions.checkArgument(!(isCharacterGroupsPresent && isAcceptableCharsPresentAndValid), "password.chars and password.character.groups both provided - please provide only ONE of them"); Preconditions.checkArgument(!isCharacterGroupsValid || characterGroups.size() <= passwordLength, "password.length must be longer than the number of entries in password.character.groups"); String password;/* w w w. j av a 2 s . c om*/ if (isCharacterGroupsValid) { password = Identifiers.makeRandomPassword(passwordLength, characterGroups.toArray(new String[0])); } else if (isAcceptableCharsPresentAndValid) { password = Identifiers.makeRandomPassword(passwordLength, acceptableChars); } else { password = Identifiers.makeRandomPassword(passwordLength); } entity.sensors().set(sensor, password); }
From source file:org.eclipse.sirius.common.tools.api.util.EclipseUtil.java
/** * Get the list of plug-ins which contribute to an extension ID, and with a * specific attribute value.// w w w . j a v a2s . com * * @param clazz * the class that plug-ins need to extend or implement * @param extensionId * the extension point id * @param executableAttribute * the executable attribute . Most often "class" is used * @param attributeName * a * @param exceptedAttributeValue * . * @param <T> * the class to implements for contributors * @return a List of clazz instance * @since 0.9.0 */ public static <T> List<T> getExtensionPlugins(final Class<T> clazz, final String extensionId, final String executableAttribute, final String attributeName, final String exceptedAttributeValue) { return EclipseUtil.getExtensionPlugins(clazz, extensionId, executableAttribute, attributeName, Predicates.equalTo(exceptedAttributeValue)); }
From source file:com.twitter.common.net.http.handlers.TimeSeriesDataSource.java
@VisibleForTesting String getResponse(@Nullable String metricsQuery, @Nullable String sinceQuery) throws MetricException { if (metricsQuery == null) { // Return metric listing. return gson.toJson(ImmutableList.copyOf(timeSeriesRepo.getAvailableSeries())); }// ww w . j av a 2 s.co m List<Iterable<Number>> tsData = Lists.newArrayList(); tsData.add(timeSeriesRepo.getTimestamps()); // Ignore requests for "time" since it is implicitly returned. Iterable<String> names = Iterables.filter(Splitter.on(",").split(metricsQuery), Predicates.not(Predicates.equalTo(TIME_METRIC))); for (String metric : names) { TimeSeries series = timeSeriesRepo.get(metric); if (series == null) { JsonObject response = new JsonObject(); response.addProperty("error", "Unknown metric " + metric); throw new MetricException(gson.toJson(response)); } tsData.add(series.getSamples()); } final long since = Long.parseLong(Optional.fromNullable(sinceQuery).or("0")); Predicate<List<Number>> sinceFilter = new Predicate<List<Number>>() { @Override public boolean apply(List<Number> next) { return next.get(0).longValue() > since; } }; ResponseStruct response = new ResponseStruct( ImmutableList.<String>builder().add(TIME_METRIC).addAll(names).build(), FluentIterable.from(Iterables2.zip(tsData, 0)).filter(sinceFilter).toList()); return gson.toJson(response); }
From source file:com.wavemaker.tools.apidocs.tools.parser.scanner.FilterableScanner.java
private Predicate<String> getEqualClassPredicate(final String type) { return Predicates.equalTo(type + CLASS_EXT); }
From source file:com.eucalyptus.component.ComponentMessages.java
public static Collection<Class<? extends BaseMessage>> forComponent(ComponentId compId) { Class<? extends ComponentId> compIdClass = compId.getClass(); if (!compIdMap.containsValue(compIdClass)) { return Collections.emptyList(); } else {//from www . ja v a 2s.c o m return Maps.filterValues((Map) compIdMap, Predicates.equalTo(compIdClass)).keySet(); } }
From source file:org.xpect.util.IssueVisualizer.java
public String visualize(String documentString, Collection<Issue> issues) { Text document = new Text(documentString); @SuppressWarnings("unchecked") List<Issue>[] mapped = new List[document.length()]; List<Issue> unmapped = Lists.newArrayList(); for (Issue issue : issues) { if (issue.getOffset() != null && issue.getLength() != null && issue.getOffset() >= 0 && issue.getOffset() < document.length() && issue.getLength() > 0) { int max = Math.min(issue.getOffset() + issue.getLength(), document.length()); for (int i = issue.getOffset(); i < max; i++) { if (mapped[i] == null) mapped[i] = Lists.newArrayList(issue); else mapped[i].add(issue); }// w w w . jav a 2s. c om } else unmapped.add(issue); } StringBuffer result = new StringBuffer(); for (Issue issue : unmapped) { if (result.length() > 0) result.append(document.getNL()); result.append(issueToString(issue)); } boolean first = true; int offset = 0; for (String line : document.splitIntoLines()) { if (first) first = false; else result.append(document.getNL()); result.append(line); boolean lineHasIssue = false; for (int i = offset; i < offset + line.length(); i++) if (mapped[i] != null) lineHasIssue = true; if (lineHasIssue) { result.append(document.getNL()); Set<Issue> lineIssues = Sets.newLinkedHashSet(); for (int i = offset; i < offset + line.length(); i++) if (mapped[i] != null) { int mark = 0; lineIssues.addAll(mapped[i]); for (Issue issue : mapped[i]) mark += 1 << Iterables.indexOf(lineIssues, Predicates.equalTo(issue)); result.append(Integer.toHexString(mark)); } else result.append(document.charAt(i) == '\t' ? "\t" : " "); for (Issue issue : lineIssues) { int id = 1 << Iterables.indexOf(lineIssues, Predicates.equalTo(issue)); result.append(document.getNL()); result.append(id); result.append(": "); result.append(issueToString(issue)); } } offset += line.length() + document.currentLineEndLenght(offset); } return result.toString(); }
From source file:org.apache.abdera2.common.misc.MorePredicates.java
public static <T> Selector<T> equalTo(Class<T> _class, String method, Object obj) { return PropertySelector.<T>create(_class, method, Predicates.equalTo(obj)); }
From source file:brooklyn.entity.nosql.couchbase.CouchbaseSyncGatewaySshDriver.java
@Override public void launch() { Entity cbNode = entity.getConfig(CouchbaseSyncGateway.COUCHBASE_SERVER); Entities.waitForServiceUp(cbNode, Duration.ONE_HOUR); DependentConfiguration.waitInTaskForAttributeReady(cbNode, CouchbaseCluster.IS_CLUSTER_INITIALIZED, Predicates.equalTo(true)); // Even once the bucket has published its API URL, it can still take a couple of seconds for it to become available Time.sleep(10 * 1000);/*from w w w .j ava2 s. c o m*/ if (cbNode instanceof CouchbaseCluster) { Optional<Entity> cbClusterNode = Iterables.tryFind(cbNode.getAttribute(CouchbaseCluster.GROUP_MEMBERS), new Predicate<Entity>() { @Override public boolean apply(@Nullable Entity entity) { // Must either be recognised by a cluster as added, or be the primary node in a cluster of ONE. return entity instanceof CouchbaseNode && (Boolean.TRUE .equals(entity.getAttribute(CouchbaseNode.IS_IN_CLUSTER)) || Boolean.TRUE.equals(entity.getAttribute(CouchbaseNode.IS_PRIMARY_NODE))); } }); if (cbClusterNode.isPresent()) { cbNode = cbClusterNode.get(); } else { throw new IllegalArgumentException( format("The cluster %s does not contain any suitable Couchbase nodes to connect to..", cbNode.getId())); } } String hostname = cbNode.getAttribute(CouchbaseNode.HOSTNAME); String webPort = cbNode.getAttribute(CouchbaseNode.COUCHBASE_WEB_ADMIN_PORT).toString(); String username = cbNode.getConfig(CouchbaseNode.COUCHBASE_ADMIN_USERNAME); String password = cbNode.getConfig(CouchbaseNode.COUCHBASE_ADMIN_PASSWORD); String bucketName = entity.getConfig(CouchbaseSyncGateway.COUCHBASE_SERVER_BUCKET); String pool = entity.getConfig(CouchbaseSyncGateway.COUCHBASE_SERVER_POOL); String pretty = entity.getConfig(CouchbaseSyncGateway.PRETTY) ? "-pretty" : ""; String verbose = entity.getConfig(CouchbaseSyncGateway.VERBOSE) ? "-verbose" : ""; String adminRestApiPort = entity.getConfig(CouchbaseSyncGateway.ADMIN_REST_API_PORT).iterator().next() .toString(); String syncRestApiPort = entity.getConfig(CouchbaseSyncGateway.SYNC_REST_API_PORT).iterator().next() .toString(); String serverWebAdminUrl = format("http://%s:%s@%s:%s", username, password, hostname, webPort); String options = format( "-url %s -bucket %s -adminInterface 0.0.0.0:%s -interface 0.0.0.0:%s -pool %s %s %s", serverWebAdminUrl, bucketName, adminRestApiPort, syncRestApiPort, pool, pretty, verbose); newScript(ImmutableMap.of("usePidFile", true), LAUNCHING).body .append(format("/opt/couchbase-sync-gateway/bin/sync_gateway %s ", options) + "> out.log 2> err.log < /dev/null &") .failOnNonZeroResultCode().execute(); }
From source file:net.automatalib.util.graphs.ShortestPaths.java
public static <N, E> Path<N, E> shortestPath(IndefiniteGraph<N, E> graph, N start, int limit, N target) { return shortestPath(graph, start, limit, Predicates.equalTo(target)); }