Advertisement
sergAccount

Untitled

Sep 5th, 2020
1,237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.73 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package com.spec.comparators;
  7.  
  8. import com.spec.model.Person;
  9. import java.util.Comparator;
  10.  
  11. /**
  12.  *
  13.  * @author Admin
  14.  */
  15. public class PersonAgeComparator implements Comparator<Person> {
  16.  
  17.     // >0 => o1 больше o2
  18.     // 0  => o1 равен o2
  19.     // <0 => o1 меньше o2
  20.     @Override
  21.     public int compare(Person o1, Person o2) {
  22.         if (o1.getAge() > o2.getAge()) {
  23.             return 1;
  24.         } else if (o1.getAge() < o2.getAge()) {
  25.             return -1;
  26.         } else {
  27.             return 0;
  28.         }
  29.     }
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement