Skip to content

Commit

Permalink
Merge branch 'eclipse:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
youssef-abdallah authored May 28, 2022
2 parents 038aa4b + fc7b8b2 commit 22748ac
Show file tree
Hide file tree
Showing 9 changed files with 186 additions and 100 deletions.
4 changes: 1 addition & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ If this is your first time contributing to an Eclipse Foundation project, you'll
- [Create an account](https://dev.eclipse.org/site_login/createaccount.php) on dev.eclipse.org
- Open your [Account Settings tab](https://dev.eclipse.org/site_login/myaccount.php#open_tab_accountsettings), enter your GitHub ID and click Update Account
- Read and [sign the ECA](https://dev.eclipse.org/site_login/myaccount.php#open_tab_cla)
- Your git commits must be [signed off](https://wiki.eclipse.org/Development_Resources/Contributing_via_Git#Signing_off_on_a_commit)
- Use the exact same email address for your Eclipse account, your commit author, and your commit sign-off.
- Use the exact same email address for your Eclipse account and your commit author.

Issues
------
Expand Down Expand Up @@ -80,7 +79,6 @@ Commit messages
- [Use the imperative mood][imperative-mood] as in "Fix bug" or "Add feature" rather than "Fixed bug" or "Added feature"
- [Mention the GitHub issue][github-issue] when relevant
- It's a good idea to follow the [advice in Pro Git](https://git-scm.com/book/ch5-2.html)
- Sign-off your commits using `git commit --signoff` or `git commit -s` for short

Pull requests
-------------
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Eclipse Collections is compatible with Java 8+. Eclipse Collections is a part of
* [Eclipse Collections Katas](https://github.com/eclipse/eclipse-collections-kata), a fun way to help you learn idiomatic Eclipse Collections usage.
* Start Here - [Pet Kata](http://eclipse.github.io/eclipse-collections-kata/pet-kata/#/)
* Continue Here - [Company Kata](http://eclipse.github.io/eclipse-collections-kata/company-kata/#/)
* [Eclipse Collections Reference Guide](https://github.com/eclipse/eclipse-collections/blob/master/docs/guide.md) and [Javadoc](https://www.eclipse.org/collections/javadoc/11.0.0/overview-summary.html)
* [Eclipse Collections Reference Guide](https://github.com/eclipse/eclipse-collections/blob/master/docs/0-RefGuide.adoc) and [Javadoc](https://www.eclipse.org/collections/javadoc/11.0.0/overview-summary.html)
* [Serializing Eclipse Collections with Jackson](./docs/jackson.md)
* [Articles](https://github.com/eclipse/eclipse-collections/wiki/Articles) and [Blogs](https://medium.com/tag/eclipse-collections/latest)
* Some OSS projects that use Eclipse Collections
Expand Down
2 changes: 1 addition & 1 deletion docs/1-Iteration_Patterns.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ ____
The _GroupBy_ pattern gathers the elements on the collection into a map-like container called a *{Multimap}*, which associates multiple values for each key.
The *{Function}* is applied to each element and the result is used as the key into the *Multimap* where the element should appear as the value.
See xref:2-Collection_Containers.adoc#multimap-container[the discussion of Multimap] for examples of **groupby**.
See xref:2-Collection_Containers.adoc#multimap-container[the discussion of Multimap] for examples of *groupby*.
****
##`*groupBy(Function): Multimap*`##
Expand Down
173 changes: 92 additions & 81 deletions docs/3-Code_Blocks.adoc

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions docs/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
~ http://www.eclipse.org/org/documents/edl-v10.php.
-->
# Reference Guide <a href="https://www.eclipse.org/collections/"><img align="right" src="https://github.com/eclipse/eclipse-collections/blob/master/artwork/eclipse-collections-logo.png" height="25%" width="25%"></a>

<div dir="auto"><a href="https://github.com/eclipse/eclipse-collections/blob/master/docs/0-RefGuide.adoc">A newer version of this guide is available.</a></div><br/>

- [About Eclipse Collections](#-about-eclipse-collections)
- [About this guide](#-about-this-guide)
- [Getting Started With Eclipse Collections](#-getting-started-with-eclipse-collections)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import org.eclipse.collections.api.block.function.primitive.<name>IntToObjectFun
import org.eclipse.collections.api.block.function.primitive.<name>ToObjectFunction;
import org.eclipse.collections.api.block.predicate.primitive.<name>IntPredicate;
import org.eclipse.collections.api.block.predicate.primitive.<name>Predicate;
import org.eclipse.collections.api.block.procedure.primitive.<name><name>Procedure;
import org.eclipse.collections.api.block.procedure.primitive.<name>Procedure;
import org.eclipse.collections.api.list.ListIterable;
import org.eclipse.collections.api.ordered.primitive.Reversible<name>Iterable;
Expand All @@ -33,6 +34,7 @@ import java.util.Spliterator;
import java.util.stream.StreamSupport;
import java.util.stream.<name>Stream;
<endif>
import java.util.Objects;

/**
* This file was automatically generated from template file primitiveList.stg.
Expand All @@ -58,6 +60,27 @@ public interface <name>List extends Reversible<name>Iterable
return this;
}

/**
* This method iterates over two CharList instances of the same size together using the specified CharCharProcedure.
*
* @since 11.1
*/
default void forEachInBoth(<name>List other, <name><name>Procedure procedure)
{
Objects.requireNonNull(other);
if (this.size() == other.size())
{
this.forEachWithIndex((each, index) -> procedure.value(each, other.get(index)));
}
else
{
throw new IllegalArgumentException("Attempt to call forEachInBoth with two <name>List instances of different sizes :"
+ this.size()
+ ':'
+ other.size());
}
}

/**
* Returns a new <name>List including all elements with corresponding indexes matching the specified predicate.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ import org.eclipse.collections.api.block.function.primitive.<name>ToObjectFuncti
import org.eclipse.collections.api.block.function.primitive.Object<name>IntToObjectFunction;
import org.eclipse.collections.api.block.predicate.primitive.<name>IntPredicate;
import org.eclipse.collections.api.block.predicate.primitive.<name>Predicate;
import org.eclipse.collections.api.block.procedure.primitive.<name>IntProcedure;
import org.eclipse.collections.api.block.procedure.primitive.<name><name>Procedure;
<if(!primitive.intPrimitive)>import org.eclipse.collections.api.block.procedure.primitive.<name>IntProcedure;<endif>
import org.eclipse.collections.api.collection.primitive.Mutable<name>Collection;
import org.eclipse.collections.api.list.MutableList;
<if(!primitive.booleanPrimitive)>import org.eclipse.collections.api.list.primitive.<name>List;<endif>
import org.eclipse.collections.api.list.primitive.<name>List;
import org.eclipse.collections.api.list.primitive.Immutable<name>List;
import org.eclipse.collections.api.list.primitive.Mutable<name>List;
import org.eclipse.collections.api.tuple.primitive.<name><name>Pair;
Expand Down Expand Up @@ -331,6 +332,15 @@ public class Synchronized<name>List
return Reverse<name>Iterable.adapt(this);
}

@Override
public void forEachInBoth(<name>List other, <name><name>Procedure procedure)
{
synchronized (this.getLock())
{
this.getMutable<name>List().forEachInBoth(other, procedure);
}
}

@Override
public void forEachWithIndex(<name>IntProcedure procedure)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,29 @@ public abstract class Abstract<name>ListTestCase extends AbstractMutable<name>Co
Assert.assertEquals(<(wideLiteral.(type))("9")>, sum[0]<wideDelta.(type)>);
}

/**
* @since 11.1.
*/
@Test
public void forEachInBoth()
{
Mutable<name>List list1 = this.newWith(<["3", "1"]:(literal.(type))(); separator=", ">);
Mutable<name>List list2 = this.newWith(<["7", "9"]:(literal.(type))(); separator=", ">);
MutableList\<<name><name>Pair> result = Lists.mutable.empty();
list1.forEachInBoth(list2, (one, two) -> result.add(PrimitiveTuples.pair(one, two)));

MutableList\<<name><name>Pair> expected = Lists.mutable.with(
PrimitiveTuples.pair(<["3", "7"]:(literal.(type))(); separator=", ">),
PrimitiveTuples.pair(<["1", "9"]:(literal.(type))(); separator=", ">));
Assert.assertEquals(expected, result);

Mutable<name>List list3 = this.newWith(<["7", "9", "1"]:(literal.(type))(); separator=", ">);
Assert.assertThrows(
IllegalArgumentException.class,
() -> list1.forEachInBoth(list3,
(one, three) -> result.add(PrimitiveTuples.pair(one, three))));
}

/**
* @since 11.1.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

import org.eclipse.collections.api.bag.primitive.MutableCharBag;
import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.factory.primitive.CharLists;
import org.eclipse.collections.api.list.ImmutableList;
import org.eclipse.collections.api.list.primitive.MutableCharList;
import org.eclipse.collections.api.tuple.Triplet;
import org.eclipse.collections.api.tuple.primitive.CharCharPair;
import org.eclipse.collections.impl.factory.Strings;
Expand Down Expand Up @@ -47,6 +49,9 @@ public class WordleTest
@Test
public void wordleTest()
{
Verify.assertAllSatisfy(
TRIPLES,
triple -> triple.getOne().equals(new Wordle(triple.getTwo()).guessForEachInBoth(triple.getThree())));
Verify.assertAllSatisfy(
TRIPLES,
triple -> triple.getOne().equals(new Wordle(triple.getTwo()).guessInjectIntoIndex(triple.getThree())));
Expand All @@ -70,6 +75,27 @@ class Wordle
this.string = string.toLowerCase();
}

public String guessForEachInBoth(String guess)
{
CharAdapter guessChars = Strings.asChars(guess.toLowerCase());
CharAdapter hiddenChars = Strings.asChars(this.string);
MutableCharBag remaining = CharBags.mutable.empty();
hiddenChars.forEachInBoth(guessChars, (h, g) -> remaining.add(h == g ? '.' : h));
MutableCharList result = CharLists.mutable.empty();
guessChars.forEachInBoth(hiddenChars, (g, h) -> result.add(this.guessMatch(g, h, remaining)));
return result.makeString("");
}

private char guessMatch(char guessChar, char hiddenChar, MutableCharBag remaining)
{
return guessChar == hiddenChar ? Character.toUpperCase(guessChar) : this.guessInDifferentPosition(guessChar, remaining);
}

private char guessInDifferentPosition(char guessChar, MutableCharBag remaining)
{
return remaining.remove(guessChar) ? guessChar : '.';
}

public String guessInjectIntoIndex(String guess)
{
CharAdapter guessChars = Strings.asChars(guess.toLowerCase());
Expand All @@ -78,9 +104,7 @@ public String guessInjectIntoIndex(String guess)
hiddenChars.injectIntoWithIndex(
CharBags.mutable.empty(),
(bag, each, i) -> guessChars.get(i) == each ? bag : bag.with(each));
return guessChars.collectWithIndex((each, i) -> hiddenChars.get(i) == each
? Character.toUpperCase(each) : remaining.remove(each) ? each : '.')
.makeString("");
return guessChars.collectWithIndex((each, i) -> this.guessMatch(each, hiddenChars.get(i), remaining)).makeString("");
}

public String guessRejectWithIndex(String guess)
Expand All @@ -89,9 +113,7 @@ public String guessRejectWithIndex(String guess)
CharAdapter hiddenChars = Strings.asChars(this.string);
MutableCharBag remaining =
hiddenChars.rejectWithIndex((each, i) -> guessChars.get(i) == each, CharBags.mutable.empty());
return guessChars.collectWithIndex((each, i) -> hiddenChars.get(i) == each
? Character.toUpperCase(each) : remaining.remove(each) ? each : '.')
.makeString("");
return guessChars.collectWithIndex((each, i) -> this.guessMatch(each, hiddenChars.get(i), remaining)).makeString("");
}

public String guessSelectWithIndex(String guess)
Expand All @@ -100,9 +122,7 @@ public String guessSelectWithIndex(String guess)
CharAdapter hiddenChars = Strings.asChars(this.string);
MutableCharBag remaining =
hiddenChars.selectWithIndex((each, i) -> guessChars.get(i) != each, CharBags.mutable.empty());
return guessChars.collectWithIndex((each, i) -> hiddenChars.get(i) == each
? Character.toUpperCase(each) : remaining.remove(each) ? each : '.')
.makeString("");
return guessChars.collectWithIndex((each, i) -> this.guessMatch(each, hiddenChars.get(i), remaining)).makeString("");
}

public String guessZipCharReject(String guess)
Expand All @@ -114,9 +134,7 @@ public String guessZipCharReject(String guess)
.reject(pair -> pair.getOne() == pair.getTwo())
.collectChar(CharCharPair::getOne)
.toBag();
return charPairs.collectChar(pair -> pair.getOne() == pair.getTwo()
? Character.toUpperCase(pair.getTwo()) : remaining.remove(pair.getTwo()) ? pair.getTwo() : '.')
.makeString("");
return charPairs.collectChar(pair -> this.guessMatch(pair.getTwo(), pair.getOne(), remaining)).makeString("");
}
}
}

0 comments on commit 22748ac

Please sign in to comment.