I will give you a java method and it's test class. Firs method it will be with original class: 
public class UtilitiesToRefact {
public static Map<String, List<Person>> filterAndClassify(List<Person> persons) {
        Map<String, List<Person>> categoriesMap = new Hashtable<>();
        List<Person> person1 = new ArrayList<>();
        List<Person> person2 = new ArrayList<>();
        List<Person> person3 = new ArrayList<>();

        for (Person person : persons) {
            if ("STUDENT".equals(person.getCategory())) {
                person1.add(person);
            } else if ("WORKER".equals(person.getCategory())) {
                person2.add(person);
            } else {
                person3.add(person);
            }
        }
        if (person1.isEmpty() || person2.isEmpty() || person3.isEmpty()) {
            Stream<Boolean> stream = person1.stream().map(person -> person.getCategory().equals("STUDENT"));
            if (stream.findAny().isEmpty()) {
                Stream<Boolean> stream2 = person2.stream().map(person -> person.getCategory().equals("WORKER"));
                if (stream2.findAny().isEmpty()) {
                    person3.forEach(person -> person.setSalary(person.getSalary() * 1));
                }
            }
        }
        categoriesMap.put("Student", person1);
        categoriesMap.put("Worker", person2);
        categoriesMap.put("Other", person3);

        person1.stream().filter(student -> student.getSchoolNote() >= 18)
                .max(Comparator.comparing(Person::getSchoolNote))
                .ifPresent(student -> System.out.println("Student with highest school note: " + student.getName()));
        for (Person worker : person2) {
            double salary = worker.getSalary();
            salary = salary * 1;
            worker.setSalary(salary);
        }
        return categoriesMap;
    }} Make sure your entire response is wrapped in JSON format.
user