Java Code Examples for com.google.common.collect.Iterators#elementsEqual()

The following examples show how to use com.google.common.collect.Iterators#elementsEqual() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CheckpointCloseableIterableImpl.java    From connector-sdk with Apache License 2.0 6 votes vote down vote up
/**
 * Compares instances of {@link CheckpointCloseableIterable}. The comparison exhausts the
 * supplied iterable before comparing checkpoint and hasMore flag.
 *
 * @param items1 to compare
 * @param items2 to compare
 * @return true if supplied CheckpointCloseableIterable match, false otherwise.
 */
public boolean compare(
    CheckpointCloseableIterable<T> items1, CheckpointCloseableIterable<T> items2) {
  if (items1 == items2) {
    return true;
  }
  if ((items1 == null) || (items2 == null)) {
    return false;
  }
  // The iterators must be compared first to cause iteration through the items. This allows
  // the repository to process each item and optionally update the checkpoint with data from
  // the item (e.g. database connector might compare a last modified field to get the latest).
  // Only after the changes are processed can the correct checkpoint and pagination be compared.
  return Iterators.elementsEqual(items1.iterator(), items2.iterator())
      && Arrays.equals(items1.getCheckpoint(), items2.getCheckpoint())
      && (items1.hasMore() == items2.hasMore());
}
 
Example 2
Source File: AbstractBsonArray.java    From mongowp with Apache License 2.0 6 votes vote down vote up
@Override
public boolean equals(Object obj) {
  if (this == obj) {
    return true;
  }
  if (obj == null) {
    return false;
  }
  if (!(obj instanceof BsonArray)) {
    return false;
  }
  BsonArray other = (BsonArray) obj;
  if (this.size() != other.size()) {
    return false;
  }
  return Iterators.elementsEqual(this.iterator(), other.iterator());
}
 
Example 3
Source File: StorageService.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
private boolean hasSameReplication(List<String> list)
{
    if (list.isEmpty())
        return false;

    for (int i = 0; i < list.size() -1; i++)
    {
        KSMetaData ksm1 = Schema.instance.getKSMetaData(list.get(i));
        KSMetaData ksm2 = Schema.instance.getKSMetaData(list.get(i + 1));
        if (!ksm1.strategyClass.equals(ksm2.strategyClass) ||
                !Iterators.elementsEqual(ksm1.strategyOptions.entrySet().iterator(),
                                         ksm2.strategyOptions.entrySet().iterator()))
            return false;
    }
    return true;
}
 
Example 4
Source File: AbstractBsonDocument.java    From mongowp with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(Object obj) {
  if (this == obj) {
    return true;
  }
  if (obj == null) {
    return false;
  }
  if (!(obj instanceof BsonDocument)) {
    return false;
  }
  return Iterators.elementsEqual(this.iterator(), ((BsonDocument) obj)
      .iterator());
}
 
Example 5
Source File: BatchApiOperation.java    From connector-sdk with Apache License 2.0 5 votes vote down vote up
/**
 * Indicates whether another object is also a {@code BatchApiOperation} and iterates
 * over the same objects. This implementation exhausts the iterators of both objects,
 * and should only be used by tests.
 */
@Override
public boolean equals(Object o) {
  if (this == o) {
    return true;
  }
  if (!(o instanceof BatchApiOperation)) {
    return false;
  }
  BatchApiOperation other = (BatchApiOperation) o;
  return Iterators.elementsEqual(this.iterator(), other.iterator());
}
 
Example 6
Source File: StringMultimap.java    From armeria with Apache License 2.0 5 votes vote down vote up
private boolean equalsSlow(StringMultimapGetters<IN_NAME, NAME> that) {
    Entry e = firstGroupHead.after;
    while (e != firstGroupHead) {
        final NAME name = e.getKey();
        if (!Iterators.elementsEqual(valueIterator(name), that.valueIterator(name))) {
            return false;
        }
        e = e.after;
    }
    return true;
}
 
Example 7
Source File: Guava.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@NoWarning("GC")
public static void testIteratorsOK(Iterator<String> i, Collection<String> c) {
    Iterators.contains(i, "x");
    Iterators.removeAll(i,c);
    Iterators.retainAll(i, c);
    Iterators.elementsEqual(i, c.iterator());
    Iterators.frequency(i, "x");
}
 
Example 8
Source File: Guava.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@ExpectWarning(value="GC", num=5)
public static void testIterators(Iterator<String> i, Collection<Integer> c) {
    Iterators.contains(i, 1);
    Iterators.removeAll(i,c);
    Iterators.retainAll(i, c);
    Iterators.elementsEqual(i, c.iterator());
    Iterators.frequency(i, 1);
}
 
Example 9
Source File: FileSystemCounterGroup.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized boolean equals(Object genericRight) {
  if (genericRight instanceof CounterGroupBase<?>) {
    @SuppressWarnings("unchecked")
    CounterGroupBase<C> right = (CounterGroupBase<C>) genericRight;
    return Iterators.elementsEqual(iterator(), right.iterator());
  }
  return false;
}
 
Example 10
Source File: AbstractCounters.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public boolean equals(Object genericRight) {
  if (genericRight instanceof AbstractCounters<?, ?>) {
    return Iterators.elementsEqual(iterator(),
        ((AbstractCounters<C, G>)genericRight).iterator());
  }
  return false;
}
 
Example 11
Source File: FrameworkCounterGroup.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(Object genericRight) {
  if (genericRight instanceof CounterGroupBase<?>) {
    @SuppressWarnings("unchecked")
    CounterGroupBase<C> right = (CounterGroupBase<C>) genericRight;
    return Iterators.elementsEqual(iterator(), right.iterator());
  }
  return false;
}
 
Example 12
Source File: Counters.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized boolean equals(Object genericRight) {
  if (genericRight instanceof CounterGroupBase<?>) {
    @SuppressWarnings("unchecked")
    CounterGroupBase<Counter> right = ((CounterGroupBase<Counter>) 
    genericRight).getUnderlyingGroup();
    return Iterators.elementsEqual(iterator(), right.iterator());
  }
  return false;
}
 
Example 13
Source File: AbstractCounterGroup.java    From incubator-tez with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized boolean equals(Object genericRight) {
  if (genericRight instanceof CounterGroupBase<?>) {
    @SuppressWarnings("unchecked")
    CounterGroupBase<T> right = (CounterGroupBase<T>) genericRight;
    return Iterators.elementsEqual(iterator(), right.iterator());
  }
  return false;
}
 
Example 14
Source File: FileSystemCounterGroup.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized boolean equals(Object genericRight) {
  if (genericRight instanceof CounterGroupBase<?>) {
    @SuppressWarnings("unchecked")
    CounterGroupBase<C> right = (CounterGroupBase<C>) genericRight;
    return Iterators.elementsEqual(iterator(), right.iterator());
  }
  return false;
}
 
Example 15
Source File: AbstractCounters.java    From tez with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public boolean equals(Object genericRight) {
  if (genericRight instanceof AbstractCounters<?, ?>) {
    return Iterators.elementsEqual(iterator(),
        ((AbstractCounters<C, G>)genericRight).iterator());
  }
  return false;
}
 
Example 16
Source File: FrameworkCounterGroup.java    From incubator-tez with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(Object genericRight) {
  if (genericRight instanceof CounterGroupBase<?>) {
    @SuppressWarnings("unchecked")
    CounterGroupBase<C> right = (CounterGroupBase<C>) genericRight;
    return Iterators.elementsEqual(iterator(), right.iterator());
  }
  return false;
}
 
Example 17
Source File: AbstractCounterGroup.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized boolean equals(Object genericRight) {
  if (genericRight instanceof CounterGroupBase<?>) {
    @SuppressWarnings("unchecked")
    CounterGroupBase<T> right = (CounterGroupBase<T>) genericRight;
    return Iterators.elementsEqual(iterator(), right.iterator());
  }
  return false;
}
 
Example 18
Source File: Counters.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized boolean equals(Object genericRight) {
  if (genericRight instanceof CounterGroupBase<?>) {
    @SuppressWarnings("unchecked")
    CounterGroupBase<Counter> right = ((CounterGroupBase<Counter>) 
    genericRight).getUnderlyingGroup();
    return Iterators.elementsEqual(iterator(), right.iterator());
  }
  return false;
}
 
Example 19
Source File: IteratorExtensionsTest.java    From xtext-lib with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected boolean is(Iterator<Integer> input, Integer... elements) {
	return Iterators.elementsEqual(input, Iterators.forArray(elements));
}
 
Example 20
Source File: IteratorExtensions.java    From xtext-lib with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Determines whether two iterators contain equal elements in the same order. More specifically, this method returns
 * {@code true} if {@code iterator} and {@code iterable} contain the same number of elements and every element of
 * {@code iterator} is equal to the corresponding element of {@code iterable}.
 * 
 * <p>Note that this will advance or even exhaust the given iterators.</p>
 * 
 * @param iterator
 *            an iterator. May not be <code>null</code>.
 * @param iterable
 *            an iterable. May not be <code>null</code>.
 * @return <code>true</code> if the two iterators contain equal elements in the same order.
 */
public static boolean elementsEqual(Iterator<?> iterator, Iterable<?> iterable) {
	return Iterators.elementsEqual(iterator, iterable.iterator());
}