-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Employee interface and CompanyEmployee class to use Java rec…
…ords In the Employee interface, getter method names were altered for brevity and to align better with the Java record conventions used in the following change. The getters `getFirst()` and `getLast()` were altered to simply `first()` and `last()`. The CompanyEmployee class was changed from a regular class to a Java record. This change makes for more concise code and eliminates the need for explicit getter methods and a constructor. As part of this change, the `getFirst()` and `getLast()` methods were removed, because they are implicitly provided by the record. The StringExercise class was edited to include various stream operations and examples of their use for sorting and filtering collections. The Golfer class inside the sorting package was updated to use `Objects.equals()` for comparison in the equals method, for better readability and null-safety. Overall, these changes modernize the codebase to take advantage of newer Java features and to improve code readability.
- Loading branch information
Showing
4 changed files
with
66 additions
and
30 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
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 |
---|---|---|
@@ -1,13 +1,13 @@ | ||
package interfaces; | ||
|
||
public interface Employee { | ||
String getFirst(); | ||
String first(); | ||
|
||
String getLast(); | ||
String last(); | ||
|
||
void doWork(); | ||
|
||
default String getName() { | ||
return String.format("%s %s", getFirst(), getLast()); | ||
return String.format("%s %s", first(), last()); | ||
} | ||
} |
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
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