-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #272 from donraab/master
Add new Haiku Kata and unfinished solutions module.
- Loading branch information
Showing
14 changed files
with
987 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Copyright (c) 2023 The Bank of New York Mellon. | ||
~ 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. | ||
~ The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html | ||
~ and the Eclipse Distribution License is available at | ||
~ http://www.eclipse.org/org/documents/edl-v10.php. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>eclipse-collections-kata-parent-17</artifactId> | ||
<groupId>org.eclipse.collections.kata</groupId> | ||
<version>7.1.0-SNAPSHOT</version> | ||
<relativePath>../pom-jdk17.xml</relativePath> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>haiku-kata-solutions</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.eclipse.collections</groupId> | ||
<artifactId>eclipse-collections-api</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.eclipse.collections</groupId> | ||
<artifactId>eclipse-collections</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.eclipse.collections</groupId> | ||
<artifactId>eclipse-collections-testutils</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
39 changes: 39 additions & 0 deletions
39
haiku-kata-solutions/src/main/java/org/eclipse/collections/haikukata/HaikuCollection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (c) 2023 The Bank of New York Mellon. | ||
* 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. | ||
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html | ||
* and the Eclipse Distribution License is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
*/ | ||
|
||
package org.eclipse.collections.haikukata; | ||
|
||
public class HaikuCollection | ||
{ | ||
private final String text = """ | ||
Breaking Through Pavement Wakin' with Bacon Homeward Found | ||
---------------- -------- ----------------- -------------- | ||
The wall disappears Beautiful pavement! Wakin' with Bacon House is where I am | ||
As soon as you break through the Imperfect path before me On a Saturday morning Home is where I want to be | ||
Intimidation Thank you for the ride Life’s little pleasures Both may be the same | ||
Winter Slip and Slide Simple Nothings With Deepest Regrets | ||
--------------------- --------------- -------------------- | ||
Run up the ladder A simple flower With deepest regrets | ||
Swoosh down the slide in the snow Petals shine vibrant and pure That which you have yet to write | ||
Winter slip and slide Stares into the void At death, won't be wrote | ||
Caffeinated Coding Rituals Finding Solace Curious Cat Eleven | ||
-------------------------- -------------- ----------- ------ | ||
I arrange my desk, Floating marshmallows I see something move This is how many | ||
refactor some ugly code, Cocoa brewed hot underneath What it is, I am not sure Haiku I write before I | ||
and drink my coffee. Comfort in a cup Should I pounce or not? Write a new tech blog. | ||
"""; | ||
|
||
public String getText() | ||
{ | ||
return this.text; | ||
} | ||
} |
113 changes: 113 additions & 0 deletions
113
haiku-kata-solutions/src/main/java/org/eclipse/collections/haikukata/TextProcessorEC.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
* Copyright (c) 2023 The Bank of New York Mellon. | ||
* 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. | ||
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html | ||
* and the Eclipse Distribution License is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
*/ | ||
|
||
package org.eclipse.collections.haikukata; | ||
|
||
import org.eclipse.collections.api.bag.primitive.CharBag; | ||
import org.eclipse.collections.api.bag.primitive.MutableCharBag; | ||
import org.eclipse.collections.api.list.ListIterable; | ||
import org.eclipse.collections.api.list.MutableList; | ||
import org.eclipse.collections.api.set.MutableSet; | ||
import org.eclipse.collections.api.set.primitive.CharSet; | ||
import org.eclipse.collections.api.tuple.Triple; | ||
import org.eclipse.collections.api.tuple.primitive.CharCharPair; | ||
import org.eclipse.collections.api.tuple.primitive.CharIntPair; | ||
import org.eclipse.collections.impl.factory.Lists; | ||
import org.eclipse.collections.impl.factory.Strings; | ||
import org.eclipse.collections.impl.string.immutable.CharAdapter; | ||
import org.eclipse.collections.impl.tuple.Tuples; | ||
import org.eclipse.collections.impl.tuple.primitive.PrimitiveTuples; | ||
import org.eclipse.collections.impl.utility.StringIterate; | ||
|
||
public class TextProcessorEC | ||
{ | ||
private String getHaiku() | ||
{ | ||
return new HaikuCollection().getText(); | ||
} | ||
|
||
public CharAdapter getHaikuAsCharAdapter() | ||
{ | ||
// TODO: Wrap this.getHaiku() in a CharAdapter | ||
// Hint: Look a the Strings class. | ||
return null; | ||
} | ||
|
||
public ListIterable<CharIntPair> topLetters() | ||
{ | ||
// TODO: Collect the alphabetic chars from this.getHaikuAsCharAdapter() to lowercase into a CharBag | ||
// Hint: Look at select, collectChar and toBag | ||
CharBag chars = null; | ||
|
||
// TODO: Return the top three occurrences of the letters in the CharBag | ||
return null; | ||
} | ||
|
||
public String distinctLetters() | ||
{ | ||
// TODO: Return all of the distinct alphabetic letters from this.getHaikuAsCharAdapter() converted to lowercase as a String | ||
// Note: The letters should be returned in encounter order from the original Haiku String | ||
// Hint: Look at select, collectChar, distinct and toString | ||
return null; | ||
} | ||
|
||
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; | ||
|
||
return Tuples.triple(chars, duplicates, unique); | ||
} | ||
|
||
public CharCharPair topVowelAndConsonant() | ||
{ | ||
// TODO: Find all of the alphabetic letters from this.getHaikuAsCharAdapter(), convert them to lowercase, | ||
// TODO: put them in a bag and then get the top 26 occurrences | ||
// Hint: Look at select, collectChar, toBag, and topOccurrences | ||
// Bonus: See if the same solution will work using asLazy | ||
MutableList<CharIntPair> charIntPairs = null; | ||
|
||
// TODO: Find the top vowel | ||
// Hint: Use the detect method on MutableList with the isVowel method below to find the top vowel char value | ||
char topVowel = 'a'; | ||
// TODO: Find the top consonant | ||
// Hint: Use the detect method on MutableList with the isVowel method below to find the top consonant char value | ||
char topConsonant = 'b'; | ||
|
||
return PrimitiveTuples.pair(topVowel, topConsonant); | ||
} | ||
|
||
public boolean isVowel(char character) | ||
{ | ||
return Strings.asChars("aeiouAEIOU").contains(character); | ||
} | ||
|
||
public MutableSet<String> findWordleWords() | ||
{ | ||
MutableList<String> words = Lists.mutable.empty(); | ||
StringIterate.forEachToken(this.getHaiku(), " ,.-!?\t\n\r\f", words::add); | ||
// TODO: Filter out the five letter words from the MutableList<String> named words | ||
// TODO: Exclude contractions, and convert the words to lowercase | ||
// Hint: Look at reject, select, collect and toSet | ||
MutableSet<String> wordleWords = null; | ||
|
||
return wordleWords; | ||
} | ||
} |
137 changes: 137 additions & 0 deletions
137
haiku-kata-solutions/src/main/java/org/eclipse/collections/haikukata/TextProcessorJDK.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
/* | ||
* Copyright (c) 2023 The Bank of New York Mellon. | ||
* 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. | ||
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html | ||
* and the Eclipse Distribution License is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
*/ | ||
|
||
package org.eclipse.collections.haikukata; | ||
|
||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Scanner; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.IntStream; | ||
|
||
import org.eclipse.collections.impl.block.factory.Functions; | ||
|
||
public class TextProcessorJDK | ||
{ | ||
public String getHaiku() | ||
{ | ||
return new HaikuCollection().getText(); | ||
} | ||
|
||
public IntStream getHaikuAsChars() | ||
{ | ||
// TODO: Create an IntStream representing the chars from this.getHaiku() | ||
// Hint: Look at the chars() method on the String class | ||
return null; | ||
} | ||
|
||
public List<Map.Entry<Character, Long>> topLetters() | ||
{ | ||
// TODO: Map the alphabetic chars from this.getHaikuAsChars() to lowercase into a Map | ||
// TODO: of Character objects to their counts | ||
// Hint: Look at IntStream's filter, map, mapToObject, collect methods | ||
// Hint: Also loo at Collectors.groupingBy, Collectors.counting | ||
Map<Character, Long> chars = null; | ||
|
||
// TODO: Sort the entries in the Map by their values in reverseOrder | ||
// TODO: Take the top three entries and convert them to a List | ||
// Hint: Look at entrySet, stream, sorted, Map.Entry.comparingByValue, Comparator.reverseOrder() | ||
// Hint: On Stream look at limit and toList. | ||
return null; | ||
} | ||
|
||
public String distinctLetters() | ||
{ | ||
// TODO: Return all of the distinct alphabetic letters from this.getHaikuAsChars() converted to lowercase as a String | ||
// Note: The letters should be returned in encounter order from the original Haiku String | ||
// Hint: Look at IntStream's filter, map, distinct, mapToObject, collect, and toString | ||
return null; | ||
} | ||
|
||
/** | ||
* A Record implementation to act as a strongly typed "Triple" for duplicatesAndUnique | ||
*/ | ||
public record CharCountsDuplicatesUnique( | ||
Map<Character, Long> chars, | ||
Map<Character, Long> duplicates, | ||
Set<Character> unique | ||
) {}; | ||
|
||
public CharCountsDuplicatesUnique duplicatesAndUnique() | ||
{ | ||
// TODO: Find all of the alphabetic letters from this.getHaikuAsChars(), convert them to lowercase | ||
// and count and store them in a Map<Character, Long>. | ||
// Hint: Look at IntStream's filter, map, mapToObj | ||
// Hint: Also Look at Stream.collect, Collectors.groupingBy, Collectors.counting | ||
Map<Character, Long> chars = null; | ||
|
||
// TODO: Find all the Characters with duplicates in the map (value > 1) | ||
// Hint: Look at entrySet, stream, filter, collect | ||
// Hint: Also look at Collectors.toMap and using Map.Entry.getKey and Map.Entry.getValue as method references | ||
Map<Character, Long> duplicates = null; | ||
|
||
// TODO: Find all the unique Characters in the Map (value < 2) | ||
// Hint: Look at entrySet, stream, filter, map, Map.Entry.getKey, collect, Collectors.toSet | ||
Set<Character> unique = null; | ||
|
||
// Returns a specialized "triple" type implemented as a Java Record (see CharCountsDuplicatesUnique above) | ||
return new CharCountsDuplicatesUnique(chars, duplicates, unique); | ||
} | ||
|
||
/** | ||
* A Record implementation to act as a strongly typed "Pair" for topVowelAndConsonant | ||
*/ | ||
public record TopVowelAndConsonant(char vowel, char consonant) {}; | ||
|
||
public TopVowelAndConsonant topVowelAndConsonant() | ||
{ | ||
// TODO: Find all of the alphabetic letters from this.getHaikuAsChars(), convert them to lowercase, | ||
// TODO: count the Character values in a Map and create a List of top 26 occurrences in | ||
// TODO: Map.Entry<Character, Long> instances sorted in reverse order by count | ||
// Hint: Look at filter, map, mapToObj, collect, Collectors.groupingBy, Collectors.counting | ||
// Hint: Also look at entrySet, stream, sorted, Map.Entry.comparingByValue, Comparator.reverseorder, toList | ||
List<Map.Entry<Character, Long>> entries = null; | ||
|
||
// TODO: Find the top vowel | ||
// Hint: Use the filter method with findFirst, orElseThrow on Stream with the isVowel method below to find | ||
// Hint: the top vowel Character value using getKey on Map.Entry. | ||
char topVowel = 'a'; | ||
|
||
// TODO: Find the top consonant | ||
// Hint: Use the filter method with findFirst, orElseThrow on Stream with the isVowel method below to find | ||
// Hint: the top consonant Character value using getKey on Map.Entry. | ||
char topConsonant = 'b'; | ||
|
||
// Return a specialized "pair" instance named TopVowelAndConsonant implemented via a Java Record | ||
return new TopVowelAndConsonant(topVowel, topConsonant); | ||
} | ||
|
||
public boolean isVowel(char character) | ||
{ | ||
// TODO: Use a Switch Expression to test for lowercase and uppercase vowels. | ||
return switch (character) | ||
{ | ||
case 'a', 'b', 'c' -> false; | ||
default -> true; | ||
}; | ||
} | ||
|
||
public Set<String> findWordleWords() | ||
{ | ||
List<String> words = new Scanner(this.getHaiku()).useDelimiter("[\\s,.!?-]+").tokens().toList(); | ||
// TODO: Filter out the five letter words from the List<String> named words | ||
// TODO: Exclude contractions, and convert the words to lowercase | ||
// Hint: Look at filter, map, collect and Collectors.toSet | ||
Set<String> wordleWords = null; | ||
return wordleWords; | ||
} | ||
} |
Oops, something went wrong.