This file contains hidden or 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
| /** | |
| How Do We Create an Immutable Class | |
| In order to create an immutable class, you should follow the below steps: | |
| Make your class final, so that no other classes can extend it. | |
| Make all your fields final, so that they’re initialized only once inside the constructor and never modified afterward. |
This file contains hidden or 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
| package com.example.tdd; | |
| import java.math.BigDecimal; | |
| public class UtilizationController { | |
| private CalculatesAverage calculatesAverage; | |
| private CountsHoursInMonth countsHoursInMonth; | |
| private AccumulatesActualsInMonth accumulatesActualsInMonth; | |
This file contains hidden or 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
| /** | |
| * Check if the two strings are an anagram of each other. | |
| * For example: LISTEN is an Anagram of SILENT. | |
| * | |
| * Two strings are an anagram of each other if the characters | |
| * and the numbers of characters that are composing them, | |
| * are exactly the same. So for example, SUE and USE are anagrams | |
| * because both words have one E, one S and one U, | |
| * hence: ESU = ESU. |
This file contains hidden or 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
| /** | |
| * Reverses a given List | |
| * using Collections.reverse() method | |
| * @param list | |
| * @author Jon Bonso | |
| */ | |
| public static void reverse(List<?> list) { | |
| Collections.reverse(list); | |
| } | |
This file contains hidden or 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
| import java.util.Arrays; | |
| public class App { | |
| public static void main( String[] args ) { | |
| int[] inArray = {1, 3, 3, 5, 7}; | |
| int baseNum = 6; | |
| System.out.println("Number List: " + Arrays.toString(inArray) ); |
This file contains hidden or 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
| /** | |
| * Example of Java's Stream API - ForEach | |
| * @author jonbonso | |
| * @param args | |
| */ | |
| public static void main(String... args) { | |
| System.out.println("Iterate using the traditional for loop..."); | |
| int[] numArray = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; | |
This file contains hidden or 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
| private Map<Integer, ? extends Address> getAddressIndex(Optional<SubjectData> currentSubjectData) { | |
| return currentSubjectData | |
| .map((SubjectData subjectData) -> | |
| subjectData.getAddresses().stream() | |
| .filter((Address address) -> address.getEsoId() != null) | |
| .collect(toMap(Address::getEsoId, identity())) | |
| ).orElse(emptyMap()); | |
| } |
This file contains hidden or 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
| interface Caps { | |
| public String capitalize(String name); | |
| } | |
| @Koan | |
| public void simpleLambda() { | |
| Caps caps = (String n) -> { | |
| return n.toUpperCase(); | |
| }; | |
| String capitalized = caps.capitalize("James"); |
This file contains hidden or 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
| @java.lang.FunctionalInterface | |
| interface Math | |
| { | |
| public int calc(int a, int b); | |
| } | |
| public class LambdaExample | |
| { | |
| public static void main(String[] args) { | |
| // define your function |
This file contains hidden or 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
| Runnable thingy = new Runnable() { | |
| public void run() { | |
| System.out.println("Annonymous class"); | |
| } | |
| } | |
| somethingElse(thingy); |