Skip to content

Commit

Permalink
Merge pull request eugenp#14093 from sam-gardner/BAEL-6334-check-list…
Browse files Browse the repository at this point in the history
…-element-in-other-list

BAEL-6334 Make object properties example clearer
  • Loading branch information
vinipx authored May 22, 2023
2 parents c513e7e + ece652e commit 0044a8f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
public class Country {

private final String name;
private final String capital;
private final String language;

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ public void givenValuesToCompare_whenUsingApacheCollectionUtils_thenDetectElemen

@Test
public void givenPropertiesInObjectsToCompare_whenUsingStreams_thenDetectElementsInTwoLists() {
Country france = new Country("France", "Paris");
Country belgium = new Country("Belgium", "Brussels");
Country spain = new Country("Spain", "Madrid");
List<Country> franceAndBelgium = Arrays.asList(france, belgium);
List<Country> belgiumAndSpain = Arrays.asList(belgium, spain);

boolean shouldBeTrue = franceAndBelgium.stream()
.map(Country::getCapital)
.anyMatch(belgiumAndSpain.stream()
.map(Country::getCapital)
Country france = new Country("France", "French");
Country mexico = new Country("Mexico", "Spanish");
Country spain = new Country("Spain", "Spanish");
List<Country> franceAndMexico = Arrays.asList(france, mexico);
List<Country> franceAndSpain = Arrays.asList(france, spain);

boolean shouldBeTrue = franceAndMexico.stream()
.map(Country::getLanguage)
.anyMatch(franceAndSpain.stream()
.map(Country::getLanguage)
.collect(toSet())::contains);

assertTrue(shouldBeTrue);
Expand Down

0 comments on commit 0044a8f

Please sign in to comment.