-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompareType.java
More file actions
43 lines (35 loc) · 843 Bytes
/
CompareType.java
File metadata and controls
43 lines (35 loc) · 843 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
package Collection;
import java.util.Random;
import Collection.Generator.Generator;
//比较,,实现compareTo方法
public class CompareType implements Comparable<CompareType>{
private int i;
private int j;
private static int count=1;
public CompareType(int i,int j){
this.i=i;
this.j=j;
}
public String toSting(){
String result="[i="+i+",j="+j+"]";
if(count++%3==0)
result+="\n";
return result;
}
public int compareTo(CompareType o) {
return (i<o.i?-1:(i==o.i?0:1));
}
//生成器
private static Random random=new Random(47);
public static Generator<CompareType> generator(){
return new Generator<CompareType>() {
@Override
public CompareType next() {
return new CompareType(random.nextInt(100),random.nextInt(100));
}
};
}
private void mian() {
//CompareType[] a=Genera;
}
}