下面列出了java.util.AbstractList#get ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Search for compound names.
* @param expressions list of expressions
* @param idx start index of the expression list
* @return compound name or null
*/
public CompoundName searchCompoundName(AbstractList<Expression> expressions, int idx) {
Expression first = expressions.get(idx);
Set<CompoundName> candidates = compoundNames.get(first.getOriginal().toLowerCase());
if (candidates != null) {
TreeSet<CompoundName> candidatesSortedFromLongestToShortest = new TreeSet<CompoundName>(new ArrayLengthDescSorter<CompoundName>());
candidatesSortedFromLongestToShortest.addAll(candidates);
for (CompoundName compName : candidatesSortedFromLongestToShortest) {
if (compName.matches(expressions, idx)) {
return compName;
}
}
}
return null;
}
/**
* Compare this compound name with the words in the expressions list starting at index idx.
* @param expressions
* @param idx
* @return true for matching between expressions and the compound name
*/
public boolean matches(AbstractList<Expression> expressions, int idx) {
for(int i=0; i<size(); ++idx,++i) {
if (idx >= expressions.size()) {
return false;
}
Expression curr = expressions.get(idx);
String word = get(i);
// compare the current word in a case insensitive way
if (!curr.getOriginal().equalsIgnoreCase(word)) {
return false;
}
// don't merge if the break flag is set in-between the compound name
if (i<size()-1 && curr.getBreakFlag()) {
return false;
}
}
return true;
}
/**
* Sorts a vector of comparable objects into increasing order.
*/
public static void sort(AbstractList array) {
Object temp;
int j, n = array.size();
// turn input array into a heap
for (j = n / 2; j > 0; j--) {
adjust(array, j, n);
}
// remove largest elements and put them at the end
// of the unsorted region until you are finished
for (j = n - 1; j > 0; j--) {
temp = array.get(0);
array.set(0, array.get(j));
array.set(j, temp);
adjust(array, 1, j);
}
}
/**
* helps sort an vector of comparable objects.
* Assumes that array[lower+1] through to array[upper] is
* already in heap form and then puts array[lower] to
* array[upper] in heap form.
*/
private static void adjust(AbstractList array, int lower, int upper) {
int j, k;
Object temp;
j = lower;
k = lower * 2;
while (k <= upper) {
if ((k < upper) && (((Comparable) array.get(k - 1)).compareTo(array.get(k)) < 0)) {
k += 1;
}
if (((Comparable) array.get(j - 1)).compareTo(array.get(k - 1)) < 0) {
temp = array.get(j - 1);
array.set(j - 1, array.get(k - 1));
array.set(k - 1, temp);
}
j = k;
k *= 2;
}
}