Skip to content

Commit

Permalink
Fix the iteration order of BiMap.each() and BiMap.forEachValue().
Browse files Browse the repository at this point in the history
  • Loading branch information
motlin committed May 19, 2016
1 parent 73bd4ca commit 51787c5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ public void appendString(Appendable appendable, String start, String separator,
@Override
public void forEachValue(Procedure<? super V> procedure)
{
this.getInverse().forEachKey(procedure);
this.getDelegate().forEachValue(procedure);
}

@Override
Expand All @@ -371,7 +371,7 @@ public void forEachKeyValue(Procedure2<? super K, ? super V> procedure)
@Override
public void each(Procedure<? super V> procedure)
{
this.getInverse().forEachKey(procedure);
this.getDelegate().forEachValue(procedure);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 Goldman Sachs.
* Copyright (c) 2016 Goldman Sachs.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
Expand All @@ -11,10 +11,33 @@
package org.eclipse.collections.test.bimap;

import org.eclipse.collections.api.bimap.BiMap;
import org.eclipse.collections.api.list.MutableList;
import org.eclipse.collections.impl.factory.Lists;
import org.eclipse.collections.test.RichIterableUniqueTestCase;

import static org.eclipse.collections.test.IterableTestCase.assertEquals;

public interface BiMapTestCase extends RichIterableUniqueTestCase
{
@Override
<T> BiMap<Object, T> newWith(T... elements);

default void BiMap_toList()
{
BiMap<Object, Integer> iterable = this.newWith(4, 3, 2, 1);

{
MutableList<Integer> target = Lists.mutable.empty();
iterable.forEachValue(target::add);
assertEquals(
target,
iterable.toList());
}

MutableList<Integer> target = Lists.mutable.empty();
iterable.forEachKeyValue((key, value) -> target.add(value));
assertEquals(
target,
iterable.toList());
}
}

0 comments on commit 51787c5

Please sign in to comment.