List of usage examples for com.google.common.base Predicates equalTo
public static <T> Predicate<T> equalTo(@Nullable T target)
From source file:com.facebook.litho.testing.viewtree.ViewPredicates.java
/** * Returns a predicate that returns true if the applied on view's text is equal to the given * text./*from w w w. j a v a2s . com*/ * substring. * @param text the text to check * @return the predicate */ public static Predicate<View> hasText(final String text) { return hasTextMatchingPredicate(Predicates.equalTo(text)); }
From source file:org.jetbrains.kotlin.types.expressions.LocalClassifierAnalyzer.java
public static void processClassOrObject(@NotNull GlobalContext globalContext, @Nullable final WritableScope scope, @NotNull ExpressionTypingContext context, @NotNull final DeclarationDescriptor containingDeclaration, @NotNull JetClassOrObject object, @NotNull AdditionalCheckerProvider additionalCheckerProvider, @NotNull DynamicTypesSettings dynamicTypesSettings) { TopDownAnalysisParameters topDownAnalysisParameters = TopDownAnalysisParameters.createForLocalDeclarations( globalContext.getStorageManager(), globalContext.getExceptionTracker(), Predicates.equalTo(object.getContainingFile())); InjectorForTopDownAnalyzerBasic injector = new InjectorForTopDownAnalyzerBasic(object.getProject(), topDownAnalysisParameters, context.trace, DescriptorUtils.getContainingModule(containingDeclaration), additionalCheckerProvider, dynamicTypesSettings);/*ww w.j a v a 2 s. c o m*/ TopDownAnalysisContext c = new TopDownAnalysisContext(topDownAnalysisParameters); c.setOuterDataFlowInfo(context.dataFlowInfo); injector.getTopDownAnalyzer().doProcess(c, context.scope, new PackageLikeBuilder() { @NotNull @Override public DeclarationDescriptor getOwnerForChildren() { return containingDeclaration; } @Override public void addClassifierDescriptor(@NotNull MutableClassDescriptor classDescriptor) { if (scope != null) { scope.addClassifierDescriptor(classDescriptor); } } @Override public void addFunctionDescriptor(@NotNull SimpleFunctionDescriptor functionDescriptor) { throw new UnsupportedOperationException(); } @Override public void addPropertyDescriptor(@NotNull PropertyDescriptor propertyDescriptor) { } @Override public ClassObjectStatus setClassObjectDescriptor( @NotNull MutableClassDescriptor classObjectDescriptor) { return null; } }, Collections.<PsiElement>singletonList(object)); }
From source file:com.cinchapi.common.base.CaseFormats.java
/** * Generates all possible case formats for a given set of strings. * /* w ww .ja v a2 s. c o m*/ * @param strings * @return a {@link Set} that contains all possible {@link CaseFormat case * formats} for each of the {@code strings} */ public static Map<String, CaseFormat> allVariationsOf(String... strings) { Map<String, CaseFormat> formatted = Maps.newLinkedHashMap(); CaseFormat[] formats = CaseFormat.values(); for (String string : strings) { CaseFormat original = detect(string); formatted.put(string, original); for (CaseFormat target : Arrays.stream(formats).filter(Predicates.equalTo(original).negate()) .collect(Collectors.toList())) { formatted.put(original.to(target, string), target); } } return formatted; }
From source file:org.trancecode.collection.TcMaps.java
public static <K, V> Map<K, V> copyAndPut(final Map<K, V> map, final K key, final V value) { Preconditions.checkNotNull(map);//from w w w.jav a 2 s . c om Preconditions.checkNotNull(key); if (map instanceof ImmutableMap && TcObjects.equals(map.get(key), value)) { return map; } final Builder<K, V> builder = ImmutableMap.builder(); final Map<K, V> mapWithoutKey = Maps.filterKeys(map, Predicates.not(Predicates.equalTo(key))); return builder.putAll(mapWithoutKey).put(key, value).build(); }
From source file:edu.buaa.satla.analysis.util.GraphUtils.java
/** * Project a graph to a subset of "relevant" nodes. * The result is a SetMultimap containing the successor relationships between all relevant nodes. * A pair of nodes (a, b) is in the SetMultimap, * if there is a path through the graph from a to b which does not pass through * any other relevant node.// w ww . j a v a2s . co m * * To get the predecessor relationship, you can use {@link Multimaps#invertFrom(com.google.common.collect.Multimap, com.google.common.collect.Multimap)}. * * @param root The start of the graph to project (always considered relevant). * @param isRelevant The predicate determining which nodes are in the resulting relationship. * @param successorFunction A function giving the direct successors of any node. * @param <N> The node type of the graph. */ public static <N> SetMultimap<N, N> projectARG(final N root, final Function<? super N, ? extends Iterable<N>> successorFunction, Predicate<? super N> isRelevant) { isRelevant = Predicates.or(Predicates.equalTo(root), isRelevant); SetMultimap<N, N> successors = HashMultimap.create(); // Our state is a stack of pairs of todo items. // The first item of each pair is a relevant state, // for which we are looking for relevant successor states. // The second item is a state, // whose children should be handled next. Deque<Pair<N, N>> todo = new ArrayDeque<>(); Set<N> visited = new HashSet<>(); todo.push(Pair.of(root, root)); while (!todo.isEmpty()) { final Pair<N, N> currentPair = todo.pop(); final N currentPredecessor = currentPair.getFirst(); final N currentState = currentPair.getSecond(); if (!visited.add(currentState)) { continue; } for (N child : successorFunction.apply(currentState)) { if (isRelevant.apply(child)) { successors.put(currentPredecessor, child); todo.push(Pair.of(child, child)); } else { todo.push(Pair.of(currentPredecessor, child)); } } } return successors; }
From source file:org.trancecode.collection.TcSets.java
public static <T> ImmutableSet<T> immutableSetWithout(final Iterable<T> elements, final T element) { Preconditions.checkNotNull(elements); Preconditions.checkNotNull(element); if (elements instanceof Set && !((Set<?>) elements).contains(element)) { return ImmutableSet.copyOf(elements); }/* ww w . jav a 2 s . co m*/ return ImmutableSet.copyOf(Iterables.filter(elements, Predicates.not(Predicates.equalTo(element)))); }
From source file:io.druid.segment.DimensionSelectorUtils.java
/** * Generic implementation of {@link DimensionSelector#makeValueMatcher(String)}, uses {@link * DimensionSelector#getRow()} of the given {@link DimensionSelector}. "Lazy" DimensionSelectors could delegate * {@code makeValueMatcher()} to this method, but encouraged to implement {@code makeValueMatcher()} themselves, * bypassing the {@link IndexedInts} abstraction. */// w ww.j a va 2s . c o m public static ValueMatcher makeValueMatcherGeneric(DimensionSelector selector, String value) { IdLookup idLookup = selector.idLookup(); if (idLookup != null) { return makeDictionaryEncodedValueMatcherGeneric(selector, idLookup.lookupId(value), value == null); } else if (selector.getValueCardinality() >= 0 && selector.nameLookupPossibleInAdvance()) { // Employ precomputed BitSet optimization return makeDictionaryEncodedValueMatcherGeneric(selector, Predicates.equalTo(value)); } else { return makeNonDictionaryEncodedValueMatcherGeneric(selector, value); } }
From source file:suneido.database.immudb.ForeignKeyTargets.java
ForeignKeyTargets without(ForeignKey source, ForeignKeyTarget target) { Set<ForeignKeyTarget> cur = targets.get(source); ImmutableSet<ForeignKeyTarget> wo = ImmutableSet .copyOf(Iterables.filter(cur, Predicates.not(Predicates.equalTo(target)))); return new ForeignKeyTargets(targets.with(source, wo)); }
From source file:org.polarsys.reqcycle.traceability.cache.emfbased.predicates.TraceabilityLinkPredicate.java
@Override public boolean apply(TraceabilityLink arg0) { try {/* w ww.java 2 s . c o m*/ if (Objects.equal(arg0.getLabel(), label)) { if (Iterables.find(arg0.getSources(), Predicates.equalTo(source)) != null) { if (Iterables.elementsEqual(arg0.getTargets(), targets)) { return true; } } } } catch (NoSuchElementException e) { } return false; }
From source file:org.apache.druid.segment.DimensionSelectorUtils.java
/** * Generic implementation of {@link DimensionSelector#makeValueMatcher(String)}, uses {@link * DimensionSelector#getRow()} of the given {@link DimensionSelector}. "Lazy" DimensionSelectors could delegate * {@code makeValueMatcher()} to this method, but encouraged to implement {@code makeValueMatcher()} themselves, * bypassing the {@link IndexedInts} abstraction. *///ww w .j a v a2 s . c om public static ValueMatcher makeValueMatcherGeneric(DimensionSelector selector, @Nullable String value) { IdLookup idLookup = selector.idLookup(); if (idLookup != null) { return makeDictionaryEncodedValueMatcherGeneric(selector, idLookup.lookupId(value), value == null); } else if (selector.getValueCardinality() >= 0 && selector.nameLookupPossibleInAdvance()) { // Employ caching BitSet optimization return makeDictionaryEncodedValueMatcherGeneric(selector, Predicates.equalTo(value)); } else { return makeNonDictionaryEncodedValueMatcherGeneric(selector, value); } }