本文整理汇总了Java中sim.util.IntBag.get方法的典型用法代码示例。如果您正苦于以下问题:Java IntBag.get方法的具体用法?Java IntBag.get怎么用?Java IntBag.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sim.util.IntBag
的用法示例。
在下文中一共展示了IntBag.get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deduplicate
import sim.util.IntBag; //导入方法依赖的package包/类
public IntBag deduplicate(IntBag b){
IntBag d = new IntBag();
for (int i = 0; i < b.numObjs; i++){
int o = b.get(i);
if (!d.contains(o)){
d.add(o);
}
}
return d;
}
示例2: position
import sim.util.IntBag; //导入方法依赖的package包/类
public int position(IntBag b, int num){
int pos = -1;
for (int i = 0; i < b.numObjs; i++){
int bNum = b.get(i);
if (bNum == num){
pos = i;
break;
}
}
return pos;
}
示例3: sortOrder
import sim.util.IntBag; //导入方法依赖的package包/类
public IntBag sortOrder(DoubleBag b){
IntBag sortOrd = new IntBag();
// THIS SHOULD BE ACCEPTABLE IN SPEED FOR SHORT LISTS (TO 150)
IntBag order = new IntBag(b.numObjs);
for (int i = 0; i < b.numObjs; i++){
order.add(0);
}
if (b.numObjs == 1){
return order;
} else {
DoubleBag sortedB = new DoubleBag();
DoubleBag unsortedB = new DoubleBag();
unsortedB.addAll(b);
sortedB.addAll(b);
sortedB.sort();
IntBag unmatchedElements = new IntBag();
for (int i = 0; i < b.numObjs; i++){
unmatchedElements.add(i); // initially, all elements are unmatched. Remove them once matched.
// This handles duplicates and it also cuts down iteration time, below
}
// iterate through the unmatched elements in the unsorted bag
for (int i = 0; i < b.numObjs; i++){
// look for match in the sorted bag and record the index number
for (int k = 0; k < unmatchedElements.numObjs; k++ ){
int j = unmatchedElements.get(k);
if (sortedB.get(j)>=0 &&
unsortedB.get(i) == sortedB.get(j)) {
order.set(i, j);
// since this element is matched, remove it from the unmatched list
unmatchedElements.removeNondestructively(k);
}
}
}
if (order.numObjs < b.numObjs){
System.err.println("ERROR in sorting");
System.exit(0);
}
return order;
}
}