Code Monkey home page Code Monkey logo

eclipse-collections-kata's Introduction


Eclipse Collections Kata

A kata is an exercise in martial arts. A code kata is an exercise in programming which helps hone your skills through practice and repetition. The Eclipse Collections Kata is a fun way to help you learn idiomatic Eclipse Collections usage. This particular kata is set up as a series of unit tests which fail. Your task is to make them pass, using Eclipse Collections.

What you will need to build the katas

  1. JDK 11 (use pom.xml to build project) or JDK 17 (use pom-jdk17.xml to build project)
  2. Maven 3.6.1+
  3. IDE of your choice that has support for JDK 11 or JDK 17

Initialize Kata

Clone this repo or simply download and extract the master zip file, then follow the instructions below for your IDE/platform.

Eclipse users

You can import the project from "Import" => "General" => "Existing Projects into Workspace". Select "eclipse-collections-kata" directory as root directory, make sure to choose "Search for nested projects" option and finish.

IntelliJ IDEA users

Initialize IntelliJ IDEA project with the command below.

You can open the project from "File" => "Open..." => choose "eclipse-collections-kata" folder.

NetBeans users

Linux/Mac/Windows:

Open as a Maven project

You can open the project directly from "File" => "Open Project..." => choose "eclipse-collections-kata" folder. In the "Open Project" dialog you might select the option "Open Required Projects" to automatically open the two modules.

Work on Kata exercises

There are seven separate Java 11 katas under different directories:

  1. Pet Kata
  2. Company Kata
  3. Candy Kata
  4. Converter Method Kata
  5. Top Methods Kata
  6. Lost and Found Kata
  7. Jackson Kata

There are also Java 17 katas supported as well:

  1. Records Kata
  2. Haiku Kata
  3. Wordle Kata

By default, the project is set up to build JDK 11 compatible katas. To work on katas that use Java 17, use/import pom-jdk17.xml instead to build the project.

To get started, you can refer to slides for the Instruction and Pet Kata to learn how to set-up Kata, basic features of Eclipse Collections corresponding to each Pet Kata exercise and then solutions. Check out the pet kata solutions module tests for your reference.

To learn wider range of functionalities, slides for Company Kata are now available online as well.

To learn more about the Bag data structure, take a look at the Candy Kata.

Check out Lost and Found Kata and solutions to learn more advanced data structures and APIs in Eclipse Collections, many of which will have no equivalent in the JDK today.

Enjoy happy learning with Eclipse Collections Kata!

How to Contribute

We welcome contributions! We accept contributions via pull requests here in GitHub. Please see How To Contribute (from the Eclipse Collections project) to get started.

Reference Guide

The Eclipse Collections Reference Guide is a great way to get an overview of the extensive features available in the framework.

Presentations

The API Design of Eclipse Collections covers the design decisions that went into making Eclipse Collections and guiding its evolution from Java 4 through Java 17. The content of the presentation is also available in a convenient to read markdown format.

eclipse-collections-kata's People

Contributors

anujap2020 avatar aqsa505 avatar bazzani avatar cguntur-bnym avatar chiiia12 avatar donraab avatar emilie-robichaud avatar goldbal330 avatar gracianor avatar harshavardhi123 avatar harshitha-ravi avatar itohro avatar jinjin1919 avatar lavanyagopal avatar motlin avatar mydeveloperplanet avatar nikhilnanivadekar avatar niveditamishracoding avatar podost avatar prathasirisha avatar ramvaidya avatar rashmi29 avatar richardduffett avatar rosebernardsha avatar rzrobin213 avatar samuelhockenberry avatar scottbnym avatar superhindupur avatar willkil avatar xiangdong-xu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

eclipse-collections-kata's Issues

Add implementation to TextProcessorEC.distinctLetters() for haiku-kata-solutions module

The method distinctLetters() in the TextProcessorEC class for the haiku-kata-solutions module is not yet implemented. Follow the TODOs and hints given in the method. Please do not add solutions to the non-solution modules. After writing the code, uncomment the test and tag annotations and check that the test case distinctLetters() in the TextProcessorECTest passes for the haiku-kata-solutions module. Make sure to adhere to our contribution guide.

Please note that this issue is created for GHC 2023 Open Source Day, thus priority will be given to the attendees of this event. After the event, this issue will be open to anyone.

Upgrade Eclipse Collections version

The current Eclipse Collections (org.eclipse.collections:eclipse-collections-api and org.eclipse.collections:eclipse-collections) version is 11.1.0. Upgrade it to 12.0.0.M3.

Can't import projects to Eclipse for Java EE

Eclipse shows "No projects are found" when following the steps described for Eclipse users in Initialize Kata section.

About the IDE:
Eclipse IDE for Enterprise Java and Web Developers
Version: 2021-03 (4.19.0)
Build id: 20210312-0638

Add implementation to TextProcessorEC.getHaikuAsCharAdapter() for haiku-kata-solutions module

The method getHaikuAsCharAdapter() in the TextProcessorEC class for the haiku-kata-solutions module is not yet implemented. Follow the TODOs and hints given in the method. Please do not add solutions to the non-solution modules. Make sure to adhere to our contribution guide.

Please note that this issue is created for GHC 2023 Open Source Day, thus priority will be given to the attendees of this event. After the event, this issue will be open to anyone.

Add README to pet-kata

Pet kata doesn't currently have a README. A README that describes the domain of the pet kata and has links to the appropriate slides.md for the kata could be very helpful.

There could be a link to this README in the main repo README so that it's easier to navigate to and read about the pet kata.

Add implementation to TextProcessorEC.findWordleWords() for haiku-kata-solutions module

The method findWordleWords() in the TextProcessorEC class for the haiku-kata-solutions module is not yet implemented. Follow the TODOs and hints given in the method. Please do not add solutions to the non-solution modules. After writing the code, uncomment the test and tag annotations and check that the test case findWordleWords() in the TextProcessorECTest passes for the haiku-kata-solutions module. Make sure to adhere to our contribution guide.

Please note that this issue is created for GHC 2023 Open Source Day, thus priority will be given to the attendees of this event. After the event, this issue will be open to anyone.

Add implementation to TextProcessorEC.topVowelAndConsonant() for haiku-kata-solutions module

The method topVowelAndConsonant() in the TextProcessorEC class for the haiku-kata-solutions module is not yet implemented. Follow the TODOs and hints given in the method. Please do not add solutions to the non-solution modules. After writing the code, uncomment the test and tag annotations and check that the test case topVowelAndConsonant() in the TextProcessorECTest passes for the haiku-kata-solutions module. Make sure to adhere to our contribution guide.

Please note that this issue is created for GHC 2023 Open Source Day, thus priority will be given to the attendees of this event. After the event, this issue will be open to anyone.

Create solutions module for Candy Kata

There exists no solutions module for the candy kata today. Follow the model for the solutions model currently checked in for the Pet Kata.

Start out by checking in unfinished tests for the CandyKataTest. Solutions for the test should be a separate pull request.

Add implementation to WordleEC.guess(String guess) for wordle-kata-solutions module

The method guess(String guess) in the WordleEC record for the wordle-kata-solutions module is not yet implemented. This is a more difficult exercise as it involves more EC APIs and has less guiding hints. Please complete the haiku-kata first if you're struggling with this issue. Follow the TODOs and hints given in the method. Please do not add solutions to the non-solution modules. After writing the code, uncomment the test and tag annotations and check that the test case matchWordWithGuess() in the WordleECTest class passes for the wordle-kata-solutions module. Make sure to adhere to our contribution guide.

Please note that this issue is created for GHC 2023 Open Source Day, thus priority will be given to the attendees of this event. After the event, this issue will be open to anyone.

Add README to company-kata

Company kata doesn't currently have a README. A README that describes the domain of the company kata and has links to the appropriate slides.md for the kata could be very helpful.

There could be a link to this README in the main repo README so that it's easier to navigate to and read about the company kata.

Add implementation to TextProcessorEC.duplicatesAndUnique() for haiku-kata-solutions module

The method duplicatesAndUnique() in the TextProcessorEC class for the haiku-kata-solutions module is not yet implemented. Follow the TODOs and hints given in the method. Please do not add solutions to the non-solution modules. After writing the code, uncomment the test and tag annotations and check that the test case duplicatesAndUnique() in the TextProcessorECTest passes for the haiku-kata-solutions module. Make sure to adhere to our contribution guide.

Please note that this issue is created for GHC 2023 Open Source Day, thus priority will be given to the attendees of this event. After the event, this issue will be open to anyone.

Add code coverage report

A code coverage report is a nice addition to Eclipse Collections. It allows the community to find areas that need improvement and it's a good source of future work

Do we need `var` in the Kata?

Since Eclipse Collections is compatible with Java 8, the Kata should work with Java 8 as well. If we want to use features of versions higher than Java 8 we might want to have a separate module for it. The reason for this is two fold:

  1. Incorrect impression of users that Java 11 is required to use the library
  2. For the majority of folks who are in Java 8, it means setting up their environment for Java 11 to use the Kata

Thoughts?

Add README to candy-kata

Candy kata doesn't currently have a README. A README that describes the domain of the candy kata would be very helpful.

There could be a link to this README in the main repo README so that it's easier to navigate to and read about the candy kata.

Create solutions module for Company Kata

There exists no solutions module for the company kata today. Follow the model for the solutions model currently checked in for the Pet Kata.

Start out by checking in unfinished tests for each exercise. Solutions for each exercise should be separate pull requests. This will allow multiple developers to potentially complete them.

Unit tests not running

erik@msi:~$ git clone https://github.com/eclipse/eclipse-collections-kata.git
Cloning into 'eclipse-collections-kata'...
remote: Enumerating objects: 2554, done.
remote: Counting objects: 100% (886/886), done.
remote: Compressing objects: 100% (407/407), done.
remote: Total 2554 (delta 266), reused 716 (delta 160), pack-reused 1668
Receiving objects: 100% (2554/2554), 2.60 MiB | 6.61 MiB/s, done.
Resolving deltas: 100% (956/956), done.

erik@msi:~$ cd eclipse-collections-kata/pet-kata
erik@msi:~/eclipse-collections-kata/pet-kata$ mvn test
Apache Maven 3.6.3
Maven home: /usr/share/maven
Java version: 17, vendor: Private Build, runtime: /usr/lib/jvm/java-17-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.13.0-22-generic", arch: "amd64", family: "unix"
22:00:58:704 [INFO] Error stacktraces are turned on.
22:00:58:757 [INFO] Scanning for projects...
22:00:58:829 [INFO] 
22:00:58:830 [INFO] ---------------< org.eclipse.collections.kata:pet-kata >----------------
22:00:58:832 [INFO] Building pet-kata 7.1.0-SNAPSHOT
22:00:58:832 [INFO] --------------------------------[ jar ]---------------------------------
22:00:59:007 [INFO] 
22:00:59:007 [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ pet-kata ---
22:00:59:209 [INFO] Using 'UTF-8' encoding to copy filtered resources.
22:00:59:210 [INFO] skip non existing resourceDirectory /home/erik/eclipse-collections-kata/pet-kata/src/main/resources
22:00:59:211 [INFO] 
22:00:59:211 [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ pet-kata ---
22:00:59:465 [INFO] Changes detected - recompiling the module!
22:00:59:470 [INFO] Compiling 3 source files to /home/erik/eclipse-collections-kata/pet-kata/target/classes
22:00:59:492 [WARNING] Unable to autodetect 'javac' path, using 'javac' from the environment.
22:01:00:543 [INFO] 
22:01:00:543 [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ pet-kata ---
22:01:00:545 [INFO] Using 'UTF-8' encoding to copy filtered resources.
22:01:00:545 [INFO] skip non existing resourceDirectory /home/erik/eclipse-collections-kata/pet-kata/src/test/resources
22:01:00:546 [INFO] 
22:01:00:546 [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ pet-kata ---
22:01:00:551 [INFO] Changes detected - recompiling the module!
22:01:00:551 [INFO] Compiling 6 source files to /home/erik/eclipse-collections-kata/pet-kata/target/test-classes
22:01:00:553 [WARNING] Unable to autodetect 'javac' path, using 'javac' from the environment.
22:01:02:214 [INFO] 
22:01:02:214 [INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ pet-kata ---
22:01:02:362 [INFO] Surefire report directory: /home/erik/eclipse-collections-kata/pet-kata/target/surefire-reports
22:01:02:533 [INFO] 
22:01:02:534 [INFO] -------------------------------------------------------
22:01:02:535 [INFO]  T E S T S
22:01:02:535 [INFO] -------------------------------------------------------
22:01:03:322 [INFO] 
22:01:03:323 [INFO] Results:
22:01:03:323 [INFO] 
22:01:03:325 [INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
22:01:03:325 [INFO] 
22:01:03:329 [INFO] ------------------------------------------------------------------------
22:01:03:329 [INFO] BUILD SUCCESS
22:01:03:329 [INFO] ------------------------------------------------------------------------
22:01:03:331 [INFO] Total time:  4.600 s
22:01:03:331 [INFO] Finished at: 2021-12-13T22:01:03+01:00
22:01:03:331 [INFO] ------------------------------------------------------------------------

Eclipse Collections is sometimes worse than Java 8 Stream?

Pet kata:

Exercise2Test:

My Pet.java is like this:

public @Slf4j record Pet(PetType type, String name, int age) {
  public String name() {
    log.trace("Pet type: {}, name: {}", type, name);
    return name;
  }
}

My Person.java is like this (I don't change anything except that I put a message logging in the getPets method):

public @Slf4j class Person {
  ...
  public MutableList<Pet> getPets() {
    log.trace("Person: first name: {}, last name: {}", firstName, lastName);
    return pets;
  }
}

findPetNamedSerpy() in Eclipse Collections:

Pet serpy =
    people
        .flatCollect(Person::getPets)
        .detectWith((pet, name) -> pet.name().equals(name), "Serpy");
assertTrue(serpy.type().toString().startsWith("snake "));

prints 13 method accesses

16:04:08.464 orker TRACE llection.pet.Person.getPets      - Person: first name: Mary, last name: Smith
16:04:08.474 orker TRACE llection.pet.Person.getPets      - Person: first name: Bob, last name: Smith
16:04:08.475 orker TRACE llection.pet.Person.getPets      - Person: first name: Ted, last name: Smith
16:04:08.475 orker TRACE llection.pet.Person.getPets      - Person: first name: Jake, last name: Snake
16:04:08.476 orker TRACE llection.pet.Person.getPets      - Person: first name: Barry, last name: Bird
16:04:08.476 orker TRACE llection.pet.Person.getPets      - Person: first name: Terry, last name: Turtle
16:04:08.477 orker TRACE llection.pet.Person.getPets      - Person: first name: Harry, last name: Hamster
16:04:08.477 orker TRACE llection.pet.Person.getPets      - Person: first name: John, last name: Doe
16:04:08.478 orker TRACE _collection.pet.Pet.name         - Pet type: cat ↺, name: Tabby
16:04:08.479 orker TRACE _collection.pet.Pet.name         - Pet type: cat ↺, name: Dolly
16:04:08.480 orker TRACE _collection.pet.Pet.name         - Pet type: dog ⇪, name: Spot
16:04:08.480 orker TRACE _collection.pet.Pet.name         - Pet type: dog ⇪, name: Spike
16:04:08.481 orker TRACE _collection.pet.Pet.name         - Pet type: snake ↭, name: Serpy

findPetNamedSerpy() in Java 8 Stream:

Optional<Pet> serpyOptional =
    people.stream()
        .flatMap(person -> person.getPets().stream())
        .filter(pet -> pet.name().equals("Serpy"))
        .findAny();
assertTrue(serpyOptional.isPresent());
assertTrue(serpyOptional.get().type().toString().startsWith("snake "));

prints 9 method accesses:

16:04:08.488 orker TRACE llection.pet.Person.getPets      - Person: first name: Mary, last name: Smith
16:04:08.489 orker TRACE _collection.pet.Pet.name         - Pet type: cat ↺, name: Tabby
16:04:08.490 orker TRACE llection.pet.Person.getPets      - Person: first name: Bob, last name: Smith
16:04:08.490 orker TRACE _collection.pet.Pet.name         - Pet type: cat ↺, name: Dolly
16:04:08.490 orker TRACE _collection.pet.Pet.name         - Pet type: dog ⇪, name: Spot
16:04:08.491 orker TRACE llection.pet.Person.getPets      - Person: first name: Ted, last name: Smith
16:04:08.491 orker TRACE _collection.pet.Pet.name         - Pet type: dog ⇪, name: Spike
16:04:08.492 orker TRACE llection.pet.Person.getPets      - Person: first name: Jake, last name: Snake
16:04:08.492 orker TRACE _collection.pet.Pet.name         - Pet type: snake ↭, name: Serpy

Is there any way in Eclipse Collections that makes this at least as good as Java 8 Stream?

I guess that Eclipse Collections is worse than Java 8 Stream whenever it has to create an intermediate collection. Is there any example to prove that my guessing is wrong?

How does `AbstractMutableBagIterable.topOccurences(int n)` work?

The code I see is:

int keySize = Math.min(n, this.sizeDistinct());
MutableList<ObjectIntPair<T>> sorted = this.toListWithOccurrences().sortThisByInt(function);
MutableList<ObjectIntPair<T>> results = sorted.subList(0, keySize).toList();

If this.toListWithOccurrences() returns 100 pairs (100 /*number of occurrencies*/, Object), (1, Object), ... and to pickup the top 3 pairs, we have to sort all 100 pairs? If that's true, it's quite inefficient in this case. If that's untrue, how does it work for this case?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.