void add(E element) { contents.add(EQUALITY_WITHOUT_USING_HASH_CODE.wrap(element)); }
boolean remove(E element) { return contents.remove(EQUALITY_WITHOUT_USING_HASH_CODE.wrap(element)); }
public void testWrap() { new EqualsTester() .addEqualityGroup( LENGTH_EQUIVALENCE.wrap("hello"), LENGTH_EQUIVALENCE.wrap("hello"), LENGTH_EQUIVALENCE.wrap("world")) .addEqualityGroup(LENGTH_EQUIVALENCE.wrap("hi"), LENGTH_EQUIVALENCE.wrap("yo")) .addEqualityGroup(LENGTH_EQUIVALENCE.wrap(null), LENGTH_EQUIVALENCE.wrap(null)) .addEqualityGroup(Equivalence.equals().wrap("hello")) .addEqualityGroup(Equivalence.equals().wrap(null)) .testEquals(); }
public void testWrap_get() { String test = "test"; Wrapper<String> wrapper = LENGTH_EQUIVALENCE.wrap(test); assertSame(test, wrapper.get()); }
@Override public void validate(final Processor<FullData, FullData> processor, final ProcessingReport report, final MessageBundle bundle, final FullData data) throws ProcessingException { if (!uniqueItems) return; final Set<Equivalence.Wrapper<JsonNode>> set = Sets.newHashSet(); final JsonNode node = data.getInstance().getNode(); for (final JsonNode element: node) if (!set.add(EQUIVALENCE.wrap(element))) { report.error(newMsg(data, bundle, "err.common.uniqueItems.duplicateElements")); return; } }
@GwtIncompatible // SerializableTester public void testSerialization() { SerializableTester.reserializeAndAssert(LENGTH_EQUIVALENCE.wrap("hello")); SerializableTester.reserializeAndAssert(Equivalence.equals()); SerializableTester.reserializeAndAssert(Equivalence.identity()); }
/** * Create a typed name object. * * @param name The name. * @param type The type. * @return An object encapsulating the specified name and type. */ @SuppressWarnings("unchecked") @Nonnull public static <T> TypedName<T> create(String name, Class<T> type) { Preconditions.checkNotNull(name, "name"); Preconditions.checkNotNull(type, "type"); if (type.isPrimitive()) { type = (Class<T>) ClassUtils.primitiveToWrapper(type); } TypedName<T> attribute = new TypedName<>(name.intern(), TypeToken.of(type)); return (TypedName<T>) FIELD_CACHE.intern(NAME_EQUIVALENCE.wrap(attribute)).get(); }
/** * Create a typed name object. * * @param name The name. * @param type The type. * @return An object encapsulating the specified name and type. */ @SuppressWarnings("unchecked") @Nonnull public static <T> TypedName<T> create(String name, TypeToken<T> type) { Preconditions.checkNotNull(name, "name"); Preconditions.checkNotNull(type, "type"); if (type.isPrimitive()) { type = TypeToken.of((Class<T>) ClassUtils.primitiveToWrapper(type.getRawType())); } TypedName<T> attribute = new TypedName<>(name.intern(), type); return (TypedName<T>) FIELD_CACHE.intern(NAME_EQUIVALENCE.wrap(attribute)).get(); }
assertThat(ratings, hasSize(4)); assertThat(Iterables.transform(ratings, eq::wrap), containsInAnyOrder(eq.wrap(entry(1, 7, 4)), eq.wrap(entry(1, 8, 5)), eq.wrap(entry(1, 9, 3)), eq.wrap(entry(1, 11, 5)))); assertEquals(4, ratings.size()); assertThat(Iterables.transform(ratings, eq::wrap), containsInAnyOrder(eq.wrap(entry(3, 7, 3)), eq.wrap(entry(3, 8, 3)), eq.wrap(entry(3, 9, 4)), eq.wrap(entry(3, 11, 5)))); containsInAnyOrder(eq.wrap(entry(4, 7, 4)), eq.wrap(entry(4, 8, 2)), eq.wrap(entry(4, 9, 5)), eq.wrap(entry(4, 10, 4)), eq.wrap(entry(4, 11, 5)))); containsInAnyOrder(eq.wrap(entry(5, 7, 3)), eq.wrap(entry(5, 8, 5)))); containsInAnyOrder(eq.wrap(entry(6, 7, 5)), eq.wrap(entry(6, 8, 5)))); containsInAnyOrder(eq.wrap(entry(7, 8, 2)), eq.wrap(entry(7, 9, 3)), eq.wrap(entry(7, 10, 4))));
/** * Is defined by Object or GroovyObject? */ public static boolean isObjectMethod(Method method) { return OBJECT_METHODS.contains(SIGNATURE_EQUIVALENCE.wrap(method)); } }
private static <B, S extends B> Map<Equivalence.Wrapper<B>, Integer> getCardinalityMap(Collection<S> coll, Equivalence<B> equiv) { Map<Equivalence.Wrapper<B>, Integer> count = new HashMap<>(); for (S obj : coll) { count.merge(equiv.wrap(obj), 1, (a, b) -> a + b); } return count; }
QueryList(Collection<ReasonerQueryImpl> queries){ this.collection = new ArrayList<>(queries); this.wrappedCollection = queries.stream().map(q -> equality().wrap(q)).collect(Collectors.toList()); } }
private static ImmutableSetMultimap<Equivalence.Wrapper<DeclaredType>, ContributionBinding> indexByMapKeyAnnotationType(ImmutableSet<ContributionBinding> contributions) { return ImmutableSetMultimap.copyOf( Multimaps.index( contributions, mapBinding -> MoreTypes.equivalence() .wrap(mapBinding.mapKeyAnnotation().get().getAnnotationType()))); }
private static ModifiableBindingMethod create( ModifiableBindingType type, BindingRequest request, TypeMirror returnType, MethodSpec methodSpec, boolean finalized) { return new AutoValue_ModifiableBindingMethods_ModifiableBindingMethod( type, request, MoreTypes.equivalence().wrap(returnType), methodSpec, finalized); }
static ComponentRequirement forModule(TypeMirror type) { return new AutoValue_ComponentRequirement( Kind.MODULE, MoreTypes.equivalence().wrap(checkNotNull(type)), Optional.empty(), Optional.empty(), simpleVariableName(MoreTypes.asTypeElement(type))); }
static ComponentRequirement forDependency(TypeMirror type) { return new AutoValue_ComponentRequirement( Kind.DEPENDENCY, MoreTypes.equivalence().wrap(checkNotNull(type)), Optional.empty(), Optional.empty(), simpleVariableName(MoreTypes.asTypeElement(type))); }
@Override protected Integer visitFunctionNode(FunctionNode node) { return Objects.hash(pairwise().wrap(node.getChildren()), node.getFunctionName()); }
/** * Returns a {@link OptionalType} for {@code type}. * * @throws IllegalArgumentException if {@code type} is not an {@code Optional} type */ static OptionalType from(TypeMirror type) { checkArgument(isOptional(type), "%s must be an Optional", type); return new AutoValue_OptionalType(MoreTypes.equivalence().wrap(MoreTypes.asDeclared(type))); }
/** * Returns a {@link MapType} for {@code type}. * * @throws IllegalArgumentException if {@code type} is not a {@link Map} type */ static MapType from(TypeMirror type) { checkArgument(isMap(type), "%s is not a Map", type); return new AutoValue_MapType(MoreTypes.equivalence().wrap(MoreTypes.asDeclared(type))); }
public void testWrap_get() { String test = "test"; Wrapper<String> wrapper = LENGTH_EQUIVALENCE.wrap(test); assertSame(test, wrapper.get()); }