diff --git a/.gradle/7.1/executionHistory/executionHistory.bin b/.gradle/7.1/executionHistory/executionHistory.bin index b8b58690fd5561f56d06f6b62fbc679448c3ff8a..8c4215e612dfea32c50c271597abfcdc0c17d447 100644 Binary files a/.gradle/7.1/executionHistory/executionHistory.bin and b/.gradle/7.1/executionHistory/executionHistory.bin differ diff --git a/.gradle/7.1/executionHistory/executionHistory.lock b/.gradle/7.1/executionHistory/executionHistory.lock index 7f2a7d61ab112334be133ae361ccafdfeefa532b..073b38e2a654e1c5eae26cdbb47f758638176b57 100644 Binary files a/.gradle/7.1/executionHistory/executionHistory.lock and b/.gradle/7.1/executionHistory/executionHistory.lock differ diff --git a/.gradle/7.1/fileHashes/fileHashes.bin b/.gradle/7.1/fileHashes/fileHashes.bin index 36a76e19f7208eb420e132f67cb1af05016192c7..effa45b8dfb1edf445cfa847c0d69de6fc06e205 100644 Binary files a/.gradle/7.1/fileHashes/fileHashes.bin and b/.gradle/7.1/fileHashes/fileHashes.bin differ diff --git a/.gradle/7.1/fileHashes/fileHashes.lock b/.gradle/7.1/fileHashes/fileHashes.lock index 6a423da5aaec22cb1e57be11ad6ec9d79928e4ad..d92e628b4b1a789e8eeb6bfaa4ae434d76fad77e 100644 Binary files a/.gradle/7.1/fileHashes/fileHashes.lock and b/.gradle/7.1/fileHashes/fileHashes.lock differ diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 17f3370ac40e774b372d80fcd65488a2f18aad2e..0a32a0621938c92af941dd57e382cb1887fc0eab 100644 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/.idea/sonarlint/issuestore/0/5/05efc8b1657769a27696d478ded1e95f38737233 b/.idea/sonarlint/issuestore/0/5/05efc8b1657769a27696d478ded1e95f38737233 new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/.idea/sonarlint/issuestore/2/a/2a45a911a8f1836b0b6c5b758962572012d8f8c3 b/.idea/sonarlint/issuestore/2/a/2a45a911a8f1836b0b6c5b758962572012d8f8c3 new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/.idea/sonarlint/issuestore/5/b/5bbfa66edb4db3c7c33c5181f43510990d3307f9 b/.idea/sonarlint/issuestore/5/b/5bbfa66edb4db3c7c33c5181f43510990d3307f9 new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/.idea/sonarlint/issuestore/f/0/f07866736216be0ee2aba49e392191aeae700a35 b/.idea/sonarlint/issuestore/f/0/f07866736216be0ee2aba49e392191aeae700a35 new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/.idea/sonarlint/issuestore/f/b/fbe448ebfc3eb2d4e308f6b8b043666f5b57235e b/.idea/sonarlint/issuestore/f/b/fbe448ebfc3eb2d4e308f6b8b043666f5b57235e new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/.idea/sonarlint/issuestore/index.pb b/.idea/sonarlint/issuestore/index.pb index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..52df6fbd3b207a2aef3453798a8b66713d2c1f2f 100644 --- a/.idea/sonarlint/issuestore/index.pb +++ b/.idea/sonarlint/issuestore/index.pb @@ -0,0 +1,11 @@ + +X +(gradle/wrapper/gradle-wrapper.properties,f/b/fbe448ebfc3eb2d4e308f6b8b043666f5b57235e +7 +gradlew,5/b/5bbfa66edb4db3c7c33c5181f43510990d3307f9 +< +build.gradle,f/0/f07866736216be0ee2aba49e392191aeae700a35 +? +settings.gradle,0/5/05efc8b1657769a27696d478ded1e95f38737233 +; +gradlew.bat,2/a/2a45a911a8f1836b0b6c5b758962572012d8f8c3 \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000000000000000000000000000000000000..e96534fb27b68192f27f985d3879e173ec77adb8 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="Palette2"> + <group name="Swing"> + <item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" /> + </item> + <item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" /> + </item> + <item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" /> + </item> + <item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true"> + <default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" /> + </item> + <item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" /> + <initial-values> + <property name="text" value="Button" /> + </initial-values> + </item> + <item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> + <initial-values> + <property name="text" value="RadioButton" /> + </initial-values> + </item> + <item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> + <initial-values> + <property name="text" value="CheckBox" /> + </initial-values> + </item> + <item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" /> + <initial-values> + <property name="text" value="Label" /> + </initial-values> + </item> + <item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> + <preferred-size width="150" height="-1" /> + </default-constraints> + </item> + <item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> + <preferred-size width="150" height="-1" /> + </default-constraints> + </item> + <item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> + <preferred-size width="150" height="-1" /> + </default-constraints> + </item> + <item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" /> + </item> + <item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3"> + <preferred-size width="200" height="200" /> + </default-constraints> + </item> + <item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3"> + <preferred-size width="200" height="200" /> + </default-constraints> + </item> + <item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" /> + </item> + <item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" /> + </item> + <item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" /> + </item> + <item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" /> + </item> + <item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1"> + <preferred-size width="-1" height="20" /> + </default-constraints> + </item> + <item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" /> + </item> + <item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" /> + </item> + </group> + </component> +</project> \ No newline at end of file diff --git a/build/classes/java/main/BinaryOperatorExamples.class b/build/classes/java/main/BinaryOperatorExamples.class index 888f34d3531f7be76c42f4a52e2a58ff9c69de1a..7e0d3c248a9a047a4b348bb67f330f3f53d5b372 100644 Binary files a/build/classes/java/main/BinaryOperatorExamples.class and b/build/classes/java/main/BinaryOperatorExamples.class differ diff --git a/build/classes/java/main/ConsumerExamples.class b/build/classes/java/main/ConsumerExamples.class index 7ef073030b42e00045d53f7dce248439b14777dd..6d1502c3d8d6ba8e6ed302fcc4e33e4b5a132758 100644 Binary files a/build/classes/java/main/ConsumerExamples.class and b/build/classes/java/main/ConsumerExamples.class differ diff --git a/build/classes/java/main/GroupByExamples.class b/build/classes/java/main/GroupByExamples.class index 15fa36547f6fb7261de89710113ece98e6eaa5d5..b29341d2fde3d650c5cd1de564585e6531bb755b 100644 Binary files a/build/classes/java/main/GroupByExamples.class and b/build/classes/java/main/GroupByExamples.class differ diff --git a/build/classes/java/main/PredicateExamples.class b/build/classes/java/main/PredicateExamples.class index a87317d177dec5da769dd4aba87e78d9af3bf69f..50e5e56f619e9380efacbd107aeaa280ab443fdf 100644 Binary files a/build/classes/java/main/PredicateExamples.class and b/build/classes/java/main/PredicateExamples.class differ diff --git a/build/classes/java/main/SortExample.class b/build/classes/java/main/SortExample.class index f27b8f64dcce247b97388ff5625350e5c8241ff1..29c2e8058f0c84b81e7446cade79f2c7262e0cd0 100644 Binary files a/build/classes/java/main/SortExample.class and b/build/classes/java/main/SortExample.class differ diff --git a/build/classes/java/main/domain/Address.class b/build/classes/java/main/domain/Address.class new file mode 100644 index 0000000000000000000000000000000000000000..3b664cbbfc86f1d9cc88461140cce0402a68d167 Binary files /dev/null and b/build/classes/java/main/domain/Address.class differ diff --git a/build/classes/java/main/domain/Employee.class b/build/classes/java/main/domain/Employee.class new file mode 100644 index 0000000000000000000000000000000000000000..b8267b2e9711bc2d36262d6dd5cc1e2d41a38981 Binary files /dev/null and b/build/classes/java/main/domain/Employee.class differ diff --git a/build/classes/java/main/enums/Gender.class b/build/classes/java/main/enums/Gender.class new file mode 100644 index 0000000000000000000000000000000000000000..d5a0676711fecc94253db770f4ff4f7f6f41cae6 Binary files /dev/null and b/build/classes/java/main/enums/Gender.class differ diff --git a/build/classes/java/main/reviewcomments/EmployeeUtil.class b/build/classes/java/main/reviewcomments/EmployeeUtil.class new file mode 100644 index 0000000000000000000000000000000000000000..4fa651071bd437c3724c61d7da07904dd6f28283 Binary files /dev/null and b/build/classes/java/main/reviewcomments/EmployeeUtil.class differ diff --git a/build/tmp/compileJava/previous-compilation-data.bin b/build/tmp/compileJava/previous-compilation-data.bin index 95ab3533e2745008f19fe0e3e72193a6e801e4ac..5bdc692dc5a872f95c896bacef7568d9324920b5 100644 Binary files a/build/tmp/compileJava/previous-compilation-data.bin and b/build/tmp/compileJava/previous-compilation-data.bin differ diff --git a/src/main/java/BinaryOperatorExamples.java b/src/main/java/BinaryOperatorExamples.java index 1715b8a2dfaa35000113088388b1d6ce25582703..18bc09bd5ab654774c56fa476a14eb9589c5c502 100644 --- a/src/main/java/BinaryOperatorExamples.java +++ b/src/main/java/BinaryOperatorExamples.java @@ -5,6 +5,7 @@ import java.util.Comparator; import java.util.List; import java.util.function.BiFunction; import java.util.function.BinaryOperator; +import java.util.function.Function; import java.util.stream.Collectors; public class BinaryOperatorExamples { diff --git a/src/main/java/ConsumerExamples.java b/src/main/java/ConsumerExamples.java index cd1fc1de4b63c5728e15af459c8d836b3580ee9c..2882da5a4aef55f56581a0f25f641987da0a5aff 100644 --- a/src/main/java/ConsumerExamples.java +++ b/src/main/java/ConsumerExamples.java @@ -12,16 +12,15 @@ public class ConsumerExamples { } private static void inbuiltBiConsumer() { - Map<String,String> map=new HashMap<>(); - map.put("1","1"); - map.put("2","2"); - map.forEach((x,y)->System.out.println("inbuiltBiConsumer"+x.concat(y))); + Map<String, String> map = new HashMap<>(); + map.put("1", "1"); + map.put("2", "2"); + map.forEach((x, y) -> System.out.println("inbuiltBiConsumer" + x.concat(y))); } private static void biConsumer() { - BiConsumer<String, String> biConsumer = (x, y) -> x.concat(y); - System.out.println(biConsumer); - + BiConsumer<String, String> biConsumer = (x, y) -> System.out.println(x.concat(y)); + biConsumer.accept("hi", "hello"); } private static void simpleConsumer() { diff --git a/src/main/java/GroupByExamples.java b/src/main/java/GroupByExamples.java index 4f74152528baeb4ec9123218f16b633e083e2c95..9612ab3755e8fbd20e1f592bd72add0e891180c0 100644 --- a/src/main/java/GroupByExamples.java +++ b/src/main/java/GroupByExamples.java @@ -19,13 +19,16 @@ public class GroupByExamples { public static void main(String[] args) { - List<Person> list = Arrays.asList(new Person(1, "Alex", 100d, new Department(1, "HR")), new Person(2, "Brian", - 200d, new Department(1, "HR")), new Person(3, "Charles", 900d, new Department(2, "Finance")), new Person(4, - "David", 200d, new Department(2, "Finance")), new Person(5, "Edward", 200d, new Department(2, "Finance")), - new Person(6, "Frank", 800d, new Department(3, "ADMIN")), new Person(7, "George", 900d, new Department(3, - "ADMIN"))); + List<Person> list = Arrays.asList( + new Person(1, "Alex", 100d, new Department(1, "HR")), + new Person(2, "Brian", 200d, new Department(1, "HR")), + new Person(3, "Charles", 900d, new Department(2, "Finance")), + new Person(4, "David", 200d, new Department(2, "Finance")), + new Person(5, "Edward", 200d, new Department(2, "Finance")), + new Person(6, "Frank", 800d, new Department(3, "ADMIN")), + new Person(7, "George", 900d, new Department(3, "ADMIN"))); - System.out.println("GroupByExamples by Simple Condition :" + simpleCondition(list)); + System.out.println("GroupByExamples by Simple Condition :" + simpleCondition(list)); System.out.println(" collect only the person ids in all departments" + personIds(list)); @@ -40,6 +43,12 @@ public class GroupByExamples { System.out.println("GroupByExamples with Filtering" + filter(list)); + //Reveiew suggestions + + // return map for complex grouping by + System.out.println("GroupByExamples by Complex Condition" + complexGroupBy(list)); + + Map<Integer, Department> departmentMap = list .stream() .collect(Collectors.toMap(Person::getId, Person::getDepartment)); @@ -66,14 +75,23 @@ public class GroupByExamples { return list.stream().collect(Collectors.groupingBy(Person::getDepartment, counting())); } + + private static Map<Object, List<Integer>> complex(final List<Person> list) { return list .stream() - .collect(Collectors.groupingBy(person -> new Pair<>(person.getSalary(), person.getSalary()), + .collect(Collectors.groupingBy(person -> new Pair<>(person.getSalary(), person.getDepartment()), Collectors.mapping(Person::getId, toList()))); + } + private static Map<Pair<Double, Department>, List<Person>> complexGroupBy(final List<Person> list) { + return list + .stream() + .collect(Collectors.groupingBy(person -> new Pair<>(person.getSalary(), person.getDepartment()))); } + + private static Map<Department, List<Integer>> personIds(final List<Person> list) { return list.stream().collect(Collectors.groupingBy(Person::getDepartment, mapping(Person::getId, toList()))); } diff --git a/src/main/java/PredicateExamples.java b/src/main/java/PredicateExamples.java index 1dee44012c850d2b992a100dfc0c7c03c0ec4e09..0022a66c7fd413b47244452c54cb8e91c7af0cfb 100644 --- a/src/main/java/PredicateExamples.java +++ b/src/main/java/PredicateExamples.java @@ -24,12 +24,10 @@ public class PredicateExamples { BiPredicate<String, Integer> biPredicate = (x, y) -> { return (x.equals("google.com") || y == 0); }; - System.out.println(domainList - .stream() - .filter(domain -> biPredicate.test(domain.getName(), domain.getScore())) - .collect(Collectors.toList())); + } + private static void biPredicate() { BiPredicate<String, Integer> biPredicate = (x, y) -> x.length() == y; System.out.println(biPredicate.test("Bat", 3)); diff --git a/src/main/java/SortExample.java b/src/main/java/SortExample.java index b8e658f5b9c1ade696a73b0e08c06121d315a5ad..c374cd6c2f0fa03d045a6b151dcdd9b5ae0f9ca2 100644 --- a/src/main/java/SortExample.java +++ b/src/main/java/SortExample.java @@ -5,7 +5,7 @@ import java.util.stream.Collectors; public class SortExample { public static void main(String[] args) { List<Integer> list = Arrays.asList(2, 4, 1, 3, 7, 5, 9, 6, 8); - list = list.stream().sorted((o1, o2) -> o2.compareTo(o1)).collect(Collectors.toList()); + list = list.stream().sorted((o1, o2) -> o1.compareTo(o1)).collect(Collectors.toList()); System.out.println(list); } } diff --git a/src/main/java/domain/Address.java b/src/main/java/domain/Address.java new file mode 100644 index 0000000000000000000000000000000000000000..14574a70e674633e922ca40a8f6c712a21a4a968 --- /dev/null +++ b/src/main/java/domain/Address.java @@ -0,0 +1,38 @@ +package domain; + +import java.util.Optional; + + +public class Address { + + private Optional<String> addressText; + + private Optional<Long> contactNumber; + + /** + * Parameterised constructor + * @param address + * @param contactNumber + */ + public Address(String address, long contactNumber) { + this.addressText = Optional.ofNullable(address); + this.contactNumber = Optional.ofNullable(contactNumber); + } + + public Optional<String> getAddressText() { + return addressText; + } + + public void setAddressText(Optional<String> addressText) { + this.addressText = addressText; + } + + public Optional<Long> getContactNumber() { + return contactNumber; + } + + public void setContactNumber(Optional<Long> contactNumber) { + this.contactNumber = contactNumber; + } + +} diff --git a/src/main/java/domain/Employee.java b/src/main/java/domain/Employee.java new file mode 100644 index 0000000000000000000000000000000000000000..a53e906a6d3e804a1bcfede7c3bd8bdaf33aa2dc --- /dev/null +++ b/src/main/java/domain/Employee.java @@ -0,0 +1,136 @@ +/** + * + */ +package domain; + + +import enums.Gender; + +import java.util.List; +import java.util.Optional; + + +public class Employee { + + private String firstName; + + private String lastName; + + private String fullName; + + private List<Address> addresses; + + private Long salary; + + private String departmentName; + + private Integer emplId; + + private Gender gender; + + /** + * Parameterised constructor. + * + * @param firstName first name + * @param lastName last name + * @param address addresses + * @param salary salary + * @param departmentName department name + * @param gender gender(male or female) + */ + public Employee(int emplId, String firstName, String lastName, List<Address> address, long salary, + String departmentName, Gender gender) { + + this.emplId = emplId; + this.firstName = firstName; + this.lastName = lastName; + this.addresses = address; + this.salary = salary; + this.departmentName = departmentName; + this.gender = gender; + } + + public Optional<String> getFirstName() { + return Optional.ofNullable(firstName); + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public Optional<String> getLastName() { + return Optional.ofNullable(lastName); + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public Optional<List<Address>> getAddresses() { + return Optional.ofNullable(addresses); + } + + public void setAddresses(List<Address> addresses) { + this.addresses = addresses; + } + + public Optional<Long> getSalary() { + return Optional.ofNullable(salary); + } + + public void setSalary(Long salary) { + this.salary = salary; + } + + public Optional<String> getFullName() { + return Optional.ofNullable(fullName); + } + + public void setFullName(String fullName) { + this.fullName = fullName; + } + + public Optional<String> getDepartmentName() { + return Optional.ofNullable(departmentName); + } + + public void setDepartmentName(String departmentName) { + this.departmentName = departmentName; + } + + public Optional<Integer> getEmplId() { + return Optional.ofNullable(emplId); + } + + public void setEmplId(Integer emplId) { + this.emplId = emplId; + } + + public Optional<Gender> getGender() { + return Optional.ofNullable(gender); + } + + public void setGender(Gender gender) { + this.gender = gender; + } + + /** + * Displays employee information. + * + * @return string which displays employee full name and salary + */ + public void displayEmployee() { + System.out.println(new StringBuilder() + .append("Employee Id : ") + .append(this.emplId) + .append("Employee Name:: ") + .append(this.firstName) + .append(this.lastName) + .append(" and Salary :: ") + .append(this.salary) + .append(" Dept ") + .append(this.departmentName) + .toString()); + } + +} diff --git a/src/main/java/enums/Gender.java b/src/main/java/enums/Gender.java new file mode 100644 index 0000000000000000000000000000000000000000..02ab654357e5f40b6c82e74cfb2ac54ec610b252 --- /dev/null +++ b/src/main/java/enums/Gender.java @@ -0,0 +1,15 @@ +/** + * + */ +package enums; + + +public enum Gender { + + MALE, FEMALE; + + public static void main(String[] args) { + Gender s = Gender.MALE; + System.out.println(s.name().toLowerCase()); + } +} diff --git a/src/main/java/reviewcomments/EmployeeUtil.java b/src/main/java/reviewcomments/EmployeeUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..8d4bac81ae54b8201425a778b7f2006c16654684 --- /dev/null +++ b/src/main/java/reviewcomments/EmployeeUtil.java @@ -0,0 +1,69 @@ +package reviewcomments; + + +import domain.Address; +import domain.Employee; +import enums.Gender; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; + + +public class EmployeeUtil { + + /** + * Fetch employees. + * + * @return employee optional object + */ + public static Optional<List<Employee>> fetchEmployees() { + + List<Employee> employeesList = new ArrayList<Employee>(); + + Address empAddress1 = new Address("Hyderabad, address1", 0); + Address empAddress2 = new Address("Hyderabad, address2", 0); + Address empAddress3 = new Address("Hyderabad, address3", 0); + List<Address> empAddresses = Arrays.asList(empAddress1, empAddress2, empAddress3); + Employee emp = new Employee(10101, "Naga ", "maheshwar", empAddresses, 9000, "computers", Gender.MALE); + + employeesList.add(emp); + Address emp2Address1 = new Address("Vikarabad, address1", 37468787); + Address emp2Address2 = new Address("Kondapur, address2", 387468); + Address emp2Address3 = new Address("Hyderabad, address3", 0); + List<Address> emp2Addresses = Arrays.asList(emp2Address1, emp2Address2, emp2Address3); + Employee emp2 = new Employee(202020, "Lakshmi", "K", emp2Addresses, 5000, "chemical", Gender.FEMALE); + employeesList.add(emp2); + + Address emp3Address1 = new Address("Miyapur, address1", 0); + Address emp3Address2 = new Address("Hitech city, address2", 37473657); + Address emp3Address3 = new Address("Gachibowli, address3", 0); + List<Address> emp3Addresses = Arrays.asList(emp3Address1, emp3Address2, emp3Address3); + Employee emp3 = new Employee(303030, "Nagalakshmi", "K", emp3Addresses, 6000, "civil", Gender.FEMALE); + employeesList.add(emp3); + + Address emp4Address1 = new Address("Anantapur, address1", 0); + Address emp4Address2 = new Address("Kurnool, address3", 0); + List<Address> emp4Addresses = Arrays.asList(emp4Address1, emp4Address2, empAddress3); + Employee emp4 = new Employee(4040404, "Naga Mohan", "M", emp4Addresses, 9000, "computers", Gender.MALE); + employeesList.add(emp4); + + Address emp5Address1 = new Address("Bangalore, address1", 0); + Address emp5Address2 = new Address("Chennai, address3", 0); + List<Address> emp5Addresses = Arrays.asList(emp5Address1, emp5Address2); + Employee emp5 = new Employee(203404, "Rajendran", "T", emp5Addresses, 7000, "civil", Gender.MALE); + employeesList.add(emp5); + + Address emp6Address1 = new Address("Delhi, address1", 0); + Address emp6Address2 = new Address("Pune", 0); + List<Address> emp6Addresses = Arrays.asList(emp6Address1, emp6Address2); + Employee emp6 = new Employee(101010, "Rajeshwari", "T", emp6Addresses, 17000, "civil", Gender.FEMALE); + employeesList.add(emp6); + + return Optional.of(employeesList); + } + + + +} diff --git a/src/main/java/reviewcomments/OptionalExample.java b/src/main/java/reviewcomments/OptionalExample.java new file mode 100644 index 0000000000000000000000000000000000000000..5e169293057be015914f658e5cc1390969b94f47 --- /dev/null +++ b/src/main/java/reviewcomments/OptionalExample.java @@ -0,0 +1,38 @@ +package reviewcomments; + +import domain.Employee; + +import java.util.Collections; +import java.util.Comparator; +import java.util.Optional; +import java.util.function.Function; + +public class OptionalExample { + + public static void main(String[] args) { + System.out.println("displayFirstEmployeeFromList" + displayFirstEmployeeFromList().get().getFirstName()); + maxEmployeeId(); + } + + + private static Function<Employee, Employee> employeeFullName = employee -> { + employee.setFirstName(employee.getFirstName().get().concat(employee.getLastName().get())); + return employee; + }; + + + private static Optional<Employee> displayFirstEmployeeFromList() { + return EmployeeUtil.fetchEmployees().orElseGet(Collections::emptyList).stream().findFirst(); + } + + + private static void maxEmployeeId() { + EmployeeUtil + .fetchEmployees() + .orElseGet(Collections::emptyList) + .stream() + .min(Comparator.comparing(o -> o.getEmplId().get())) + .ifPresent(employee -> System.out.println(employee.getEmplId())); + } + +} \ No newline at end of file