-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCategory.java
More file actions
48 lines (41 loc) · 1005 Bytes
/
Copy pathCategory.java
File metadata and controls
48 lines (41 loc) · 1005 Bytes
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
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package xml_parser;
/**
*
* @author Lbd
*/
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class Category {
public String name;
public int count;
public static int total = 0;
Category(String n)
{
this.name = n;
this.count = 1;
total++;
}
public String getName() { return this.name; }
public int getCount() { return this.count; }
public void addCount() { this.count++; }
}
class SortByCount implements Comparator {
@Override
public int compare(Object o1, Object o2) {
Category c1 = (Category) o1;
Category c2 = (Category) o2;
if (c1.getCount() > c2.getCount()) {
return 1;
}
if (c1.getCount() < c2.getCount()) {
return -1;
}
return 0;
}
}