Guest User

Untitled

a guest
May 20th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. package com.java.lang.oop.lesson4.comparable;
  2.  
  3. public class Item implements Comparable {
  4. private Integer size;
  5.  
  6. public Item(int size) {
  7. this.size = size;
  8. }
  9.  
  10. public Integer getSize() {
  11. return size;
  12. }
  13.  
  14. public void setSize(int size) {
  15. this.size = size;
  16. }
  17.  
  18. public int compareTo(Object o) {
  19. if (o == null) {
  20. return -1;
  21. }
  22. Item anotherItem = (Item) o;
  23. return this.getSize().compareTo(anotherItem.getSize());
  24. }
  25.  
  26. @Override
  27. public String toString() {
  28. return "Item{" +
  29. "size=" + size +
  30. '}';
  31. }
  32. }
Add Comment
Please, Sign In to add comment