Repository navigation
Expand file tree
/
Copy pathItem.java
More file actions
78 lines (64 loc) · 1.79 KB
/
Copy pathItem.java
File metadata and controls
78 lines (64 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* 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.javaquery.bean;
import java.util.Comparator;
public class Item {
private Long id;
private String name;
private Double price;
public Item() {
}
public Item(String name, Double price) {
this.name = name;
this.price = price;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Double getPrice() {
return price;
}
public void setPrice(Double price) {
this.price = price;
}
public Comparator<Item> orderByNameASC(){
return new Comparator<Item>() {
@Override
public int compare(Item o1, Item o2) {
if(o1 != null && o1.getName() != null
&& o2 != null && o2.getName() != null){
return o1.getName().compareTo(o2.getName());
}
return -1;
}
};
}
public Comparator<Item> orderByNameDESC(){
return new Comparator<Item>() {
@Override
public int compare(Item o1, Item o2) {
if(o1 != null && o1.getName() != null
&& o2 != null && o2.getName() != null){
return o2.getName().compareTo(o1.getName());
}
return -1;
}
};
}
@Override
public String toString() {
return "Item{" + "name=" + name + ", price=" + price + '}';
}
}