java indexof 源码_Java Stack.indexOf方法代码示例

import java.util.Stack; //导入方法依赖的package包/类

public void addCycle(Stack stack, SootMethod sm) {

// check that there is a cycle with m

if (stack.search(sm) == -1)

throw new RuntimeException("error: method not in stack. No cycle!"+ printMethodAndStack(sm, stack));

// check that there are not more than one

if (stack.lastIndexOf(sm) != stack.indexOf(sm))

throw new RuntimeException("error: a method cannot be more than twice in the stack! "+ printMethodAndStack(sm, stack));

// two cycles with the same method is not possible since we memorize already computed methods

//if (cycle2Methods.containsKey(sm))

// throw new RuntimeException("error: there already exist a cycle with the same method! "+ printMethodAndStack(sm, stack));

// At this point the stack looks like this:

// 0 1 2 n-1

// M1|M2|M3|.....|Mn

// sm = M3

// sm is at depth n in the stack, but is not in the stack.

// Methods M3, M4, ... Mn have to be saved to be later

// updated with the correct permission set of M3.

Set methods = new HashSet();

int startIndex = stack.indexOf(sm);

for (int i=startIndex+1; i

methods.add(stack.elementAt(i));

CycleKey ck = new CycleKey(sm, stack.size()+1); // +1 since sm is not in the stack

if (cycle2Methods.keySet().contains(ck)){

cycle2Methods.get(ck).addAll(methods);

}

else{

cycle2Methods.put(ck, methods);

}

cache.addAll(methods);

System.out.println("[cycle] add at depth '"+ stack.size() +"' for method '"+ sm +"'");

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值