?? sortedlist.java~1~
字號:
package chapter1;
public class SortedList extends List {
/**
*
* @uml.property name="comp"
* @uml.associationEnd multiplicity="(1 1)"
*/
//排序時(shí)用來進(jìn)行比較時(shí)用的接口
private Comparable comp;
//類的構(gòu)造函數(shù),以Comparable為參數(shù)
public SortedList(Comparable _comp) {
comp = _comp;
}
//類的構(gòu)造函數(shù),以可以存儲(chǔ)的最大對象個(gè)數(shù)_maxItems和_comp為參數(shù)
public SortedList(int _maxItems, Comparable _comp) {
super(_maxItems);
comp = _comp;
}
//向數(shù)組中添加一個(gè)對象的同時(shí),對數(shù)組中的對象進(jìn)行排序
public void add(Object obj) {
super.add(obj);
FlexSorter.sort(list, getSize(), comp);
}
//返回對象在數(shù)組中的位子,否則返回-1
public int indexOf(Object obj) {
for (int i = 0; i < getSize(); i++)
if (comp.compare(get(i), obj) == 0)
return i;
return -1;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -