Skip to content

Commit

Permalink
Fix issue eclipse#288 - added implementation of duplicatesAndUnique m…
Browse files Browse the repository at this point in the history
…ethod and test case for the same

Added implementations of duplicatesAndUnique method in haiku-kata-solutions

Updated duplicatesAndUnique method

Updated with a different approach to get duplicate chars and unique chars from MutableCharBag
  • Loading branch information
AnujaP2020 committed Sep 22, 2023
1 parent 0152f62 commit a5bc068
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,17 @@ public String distinctLetters()

public Triple<CharBag, CharBag, CharSet> duplicatesAndUnique()
{
// TODO: Find all of the alphabetic letters from this.getHaikuAsCharAdapter(), convert them to lowercase
// and store them in a MutableCharBag.
// Hint: Look at select, collectChar, and toBag
MutableCharBag chars = null;

// TODO: Find all the chars with duplicates
// Hint: Find a method on MutableCharBag that returns duplicates
CharBag duplicates = null;

// TODO: Find all the unique chars
// Hint: Find a method on MutableCharBag that returns unique chars
CharSet unique = null;
// Find all of the alphabetic letters, convert them to lowercase
MutableCharBag chars = this.getHaikuAsCharAdapter()
.select(Character::isAlphabetic)
.collectChar(Character::toLowerCase)
.toBag();

// Find all the chars with duplicates
CharBag duplicates = chars.selectDuplicates();

// Find all the unique chars
CharSet unique = chars.selectUnique();

return Tuples.triple(chars, duplicates, unique);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public void distinctLetters()
Assertions.assertEquals("breakingthoupvmwcdflsy", distinctLetters);
}

// @Test // Uncomment once duplicatesAndUnique is implemented for EC
// @Tag("SOLUTION")
@Test
@Tag("SOLUTION")
public void duplicatesAndUnique()
{
Triple<CharBag, CharBag, CharSet> triple = new TextProcessorEC().duplicatesAndUnique();
Expand Down

0 comments on commit a5bc068

Please sign in to comment.