下面列出了com.google.common.collect.Iterators#elementsEqual ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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());
}
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;
}
@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());
}
/**
* 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());
}
@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;
}
@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;
}
@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;
}
@Override
@SuppressWarnings("unchecked")
public boolean equals(Object genericRight) {
if (genericRight instanceof AbstractCounters<?, ?>) {
return Iterators.elementsEqual(iterator(),
((AbstractCounters<C, G>)genericRight).iterator());
}
return false;
}
@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;
}
@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;
}
@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;
}
@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;
}
@Override
@SuppressWarnings("unchecked")
public boolean equals(Object genericRight) {
if (genericRight instanceof AbstractCounters<?, ?>) {
return Iterators.elementsEqual(iterator(),
((AbstractCounters<C, G>)genericRight).iterator());
}
return false;
}
@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;
}
@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);
}
@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");
}
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;
}
@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());
}
@Override
protected boolean is(Iterator<Integer> input, Integer... elements) {
return Iterators.elementsEqual(input, Iterators.forArray(elements));
}
/**
* 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());
}