Commit 859f5ca0 authored by Ravinder Pannala's avatar Ravinder Pannala

Second commit

parent e3ac972c
......@@ -4,28 +4,10 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="8f863ec8-1d44-4b4b-b95d-fc49f43d843d" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/src/com/java8/features/FunctionalInterfaces/streams/Peek.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/com/java8/features/FunctionalInterfaces/streams/SortedEx.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/com/java8/features/FunctionalInterfaces/streams/SortedEx2.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/com/java8/features/FunctionalInterfaces/streams/SortedEx3.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/com/java8/features/FunctionalInterfaces/streams/ToArray.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/com/java8/features/LamdaExpressions/SupplierEx.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/com/java8/features/LamdaExpressions/predicate/Test.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/com/java8/features/Optional/Optional2.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/com/java8/features/Optional/OptionalEx.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/com/java8/features/Utils/Address.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/com/java8/features/Utils/Student.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/com/java8/features/Utils/StudentUtils.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/com/java8/features/foreach/forEachEx.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/com/java8/features/foreach/foreachOrderedEx.java" afterDir="false" />
<list default="true" id="8f863ec8-1d44-4b4b-b95d-fc49f43d843d" name="Changes" comment="Second commit">
<change afterPath="$PROJECT_DIR$/src/com/java8/features/groupBy/Employee.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/com/java8/features/groupBy/GroupByEx.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/com/java8/features/EmployeeUtils.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/java8/features/EmployeeUtils.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/com/java8/features/FunctionalInterfaces/Collectors/Joining.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/java8/features/Joiner/Joining.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/com/java8/features/FunctionalInterfaces/streams/AnyMatchEx.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/java8/features/FunctionalInterfaces/streams/AnyMatchEx.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/com/java8/features/FunctionalInterfaces/streams/FlatMapEx.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/java8/features/FunctionalInterfaces/streams/FlatMapEx.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/com/java8/features/FunctionalInterfaces/streams/SkipAndLimit.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/java8/features/FunctionalInterfaces/streams/SkipAndLimit.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/com/java8/features/FunctionalInterfaces/streams/StreamCreation.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/java8/features/FunctionalInterfaces/streams/StreamCreation.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
......@@ -59,7 +41,7 @@
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
"last_opened_file_path": "C:/Users/rpannala/Downloads/springMongoDBDemo"
"last_opened_file_path": "C:/Users/rpannala/Downloads/spring-boot-r2dbc-h2-example-master"
}
}]]></component>
<component name="RecentsManager">
......@@ -67,13 +49,13 @@
<recent name="C:\Users\rpannala\Downloads\Java8POC\src\com\java8\features\Utils" />
</key>
</component>
<component name="RunManager" selected="Application.Joining">
<configuration name="Joining" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="com.java8.features.Joiner.Joining" />
<component name="RunManager" selected="Application.GroupByEx">
<configuration name="GroupByEx" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="com.java8.features.groupBy.GroupByEx" />
<module name="Java8POC" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="com.java8.features.Joiner.*" />
<option name="PATTERN" value="com.java8.features.groupBy.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
......@@ -81,12 +63,12 @@
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="SortedEx" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="com.java8.features.FunctionalInterfaces.streams.SortedEx" />
<configuration name="Joining" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="com.java8.features.Joiner.Joining" />
<module name="Java8POC" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="com.java8.features.FunctionalInterfaces.streams.*" />
<option name="PATTERN" value="com.java8.features.Joiner.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
......@@ -94,8 +76,8 @@
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="SortedEx2" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="com.java8.features.FunctionalInterfaces.streams.SortedEx2" />
<configuration name="SortedEx" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="com.java8.features.FunctionalInterfaces.streams.SortedEx" />
<module name="Java8POC" />
<extension name="coverage">
<pattern>
......@@ -107,8 +89,8 @@
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="SortedEx3" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="com.java8.features.FunctionalInterfaces.streams.SortedEx3" />
<configuration name="SortedEx2" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="com.java8.features.FunctionalInterfaces.streams.SortedEx2" />
<module name="Java8POC" />
<extension name="coverage">
<pattern>
......@@ -120,8 +102,8 @@
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="StreamCreation" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="com.java8.features.FunctionalInterfaces.streams.StreamCreation" />
<configuration name="SortedEx3" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="com.java8.features.FunctionalInterfaces.streams.SortedEx3" />
<module name="Java8POC" />
<extension name="coverage">
<pattern>
......@@ -135,11 +117,11 @@
</configuration>
<recent_temporary>
<list>
<item itemvalue="Application.GroupByEx" />
<item itemvalue="Application.Joining" />
<item itemvalue="Application.SortedEx3" />
<item itemvalue="Application.SortedEx2" />
<item itemvalue="Application.SortedEx" />
<item itemvalue="Application.StreamCreation" />
</list>
</recent_temporary>
</component>
......@@ -152,9 +134,19 @@
<option name="presentableId" value="Default" />
<updated>1677763733236</updated>
</task>
<task id="LOCAL-00001" summary="Second commit">
<created>1678103647018</created>
<option name="number" value="00001" />
<option name="presentableId" value="LOCAL-00001" />
<option name="project" value="LOCAL" />
<updated>1678103647018</updated>
</task>
<option name="localTasksCounter" value="2" />
<servers />
</component>
<component name="VcsManagerConfiguration">
<option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" />
<MESSAGE value="Second commit" />
<option name="LAST_COMMIT_MESSAGE" value="Second commit" />
</component>
</project>
\ No newline at end of file
package com.java8.features.groupBy;
public class Employee {
private int id;
private String name;
private String designation;
private String gender;
private long salary;
public Employee(int id, String name, String designation, String gender, long salary) {
super();
this.id = id;
this.name = name;
this.designation = designation;
this.gender = gender;
this.salary = salary;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDesignation() {
return designation;
}
public void setDesignation(String designation) {
this.designation = designation;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public long getSalary() {
return salary;
}
public void setSalary(long salary) {
this.salary = salary;
}
@Override
public String toString() {
return "Employee [id=" + id + ", name=" + name + ", designation=" + designation + ", gender=" + gender
+ ", salary=" + salary + "]";
}
}
\ No newline at end of file
package com.java8.features.groupBy;
import com.java8.features.Utils.Student;
import com.java8.features.Utils.StudentUtils;
import java.util.*;
import java.util.stream.Collectors;
public class GroupByEx {
public static void main(String[] args) {
List<Employee> employeesList = new ArrayList<>();
employeesList.add(new Employee(101, "Glady", "Manager", "Male", 25_00_000));
employeesList.add(new Employee(102, "Vlad", "Software Engineer", "Female", 15_00_000));
employeesList.add(new Employee(103, "Shine", "Lead Engineer", "Female", 20_00_000));
employeesList.add(new Employee(104, "Nike", "Manager", "Female", 25_00_000));
employeesList.add(new Employee(105, "Slagan", "Software Engineer", "Male", 15_00_000));
employeesList.add(new Employee(106, "Murekan", "Software Engineer", "Male", 15_00_000));
employeesList.add(new Employee(107, "Gagy", "Software Engineer", "Male", 15_00_000));
//Group by one Field
Map<String, List<Employee>> collect = employeesList.stream()
.collect(Collectors.groupingBy(Employee::getDesignation));
System.out.println(collect);
//Group by multiple Fields and find the count
Map<String, Map<String, Long>> collect1 = employeesList.stream()
.collect(Collectors.groupingBy(Employee::getDesignation, Collectors.groupingBy(Employee::getGender, Collectors.counting())));
System.out.println(collect1);
//Getting Employees who are belongs to Designation
Map<String, List<String>> collect2 = employeesList.stream().
collect(Collectors.groupingBy(Employee::getDesignation, Collectors.mapping(Employee::getName, Collectors.toList())));
System.out.println(collect2);
//Grouping by Multiple Values
Map<String, Map<String, List<Employee>>> collect3 = employeesList
.stream()
.collect(Collectors.groupingBy(Employee::getDesignation, Collectors.groupingBy(Employee::getGender)));
System.out.println(collect3);
//Collectors.groupingBy() with a Classification Function, Downstream Collector and Supplier
LinkedHashMap<String, List<String>> collect4 = employeesList
.stream()
.collect(Collectors.groupingBy(Employee::getDesignation, LinkedHashMap::new, Collectors.mapping(Employee::getName, Collectors.toList())));
System.out.println(collect4);
LinkedHashMap<String, List<String>> collect5 = collect4.entrySet()
.stream()
.sorted(Map.Entry.comparingByKey())
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
System.out.println(collect5);
//Maximum salary based on group by
Map<String, Optional<Employee>> collect6 = employeesList
.stream()
.collect(Collectors.groupingBy(Employee::getDesignation, Collectors.maxBy(Comparator.comparingLong(Employee::getSalary))));
System.out.println(collect6);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment