Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package com.spec.comparators;
- import com.spec.model.Person;
- import java.util.Comparator;
- /**
- *
- * @author Admin
- */
- public class PersonAgeComparator implements Comparator<Person> {
- // >0 => o1 больше o2
- // 0 => o1 равен o2
- // <0 => o1 меньше o2
- @Override
- public int compare(Person o1, Person o2) {
- if (o1.getAge() > o2.getAge()) {
- return 1;
- } else if (o1.getAge() < o2.getAge()) {
- return -1;
- } else {
- return 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement