Commit 1d0e68fa authored by Syed Javed Ali's avatar Syed Javed Ali

Intial Commit: Main and model class for exercise

parents
package com.nisum.example.client;
import com.nisum.example.model.Person;
import java.util.*;
import java.util.stream.Collectors;
/**
* Main class for setting object data and getting results
*/
public class ClientApp {
public static void main(String[] args) {
Person p1= new Person(1201,"HARI",8700,"HYD","DEV","40582678416578",
Arrays.asList("7722448815","9966778844","9944668877"));
Person p2= new Person
(1202,"SHAM",5500,"PUNE","QA",
"69382678416578", Arrays.asList("8855447788","7547871478","0147248784"));
Person p3= new Person
(1203,"SAI",7500,"BANGLORE","DEV",
"14782678413689", Arrays.asList("7755447788","6767714785","01452487845"));
Person p4= new Person
(1204,"KIRAN",9500,"CHENNAI","DEV",
"89782678413689", Arrays.asList("8855447788","7667714785","01252487845"));
Person p5= new Person
(1203,"KHAN",4500,"CHENNAI","PROD",
"60582678413689", Arrays.asList("9955447788","1467714785","02352487845"));
List<Person> persons=Arrays.asList(p1,p2,p3,p4,p5);
// find the person id with highest salary in a given department
Optional<Person> optionalPerson= persons.stream().filter(p -> p.getDepartment().equals("DEV"))
.collect(Collectors.maxBy(Comparator.comparingInt(f-> f.getSalary())));
System.out.println
(optionalPerson.isPresent()?
"Person ID with highest salary :"+optionalPerson.get().getId():
"Record with highest salary not exist");
// print the no of employees at each location.
Map<String,Long> locationCount= persons.stream().collect(Collectors.groupingBy(Person::getLocation,Collectors.counting()));
for(String s:locationCount.keySet()){
System.out.println(s+"-"+locationCount.get(s));
}
}
}
package com.nisum.example.model;
import lombok.*;
import java.util.List;
/**
* Model class holds data of person
*/
@NoArgsConstructor
@AllArgsConstructor
@Setter
@Getter
@ToString
public class Person {
private int id;
private String name;
private int salary;
private String location;
private String department;
private String timestamp;
private List<String> phones;
}
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