本文整理汇总了Java中java.util.Stack.peek方法的典型用法代码示例。如果您正苦于以下问题:Java Stack.peek方法的具体用法?Java Stack.peek怎么用?Java Stack.peek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Stack
的用法示例。
在下文中一共展示了Stack.peek方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkPostPositions
import java.util.Stack; //导入方法依赖的package包/类
public boolean checkPostPositions(Stack s)
{
byte[][] pospos = {VVariables.moolam,VVariables.varai,VVariables.illaamal,VVariables.vasam,VVariables.thorum,VVariables.maththiyil,VVariables.pakkam,VVariables.mel,VVariables.kizh,VVariables.muthal,VVariables.vazhiyaaka,VVariables.parththu,VVariables.nokki,VVariables.sur1r1i,VVariables.thaandi,VVariables.thavira,VVariables.otti,VVariables.appaal,VVariables.appuram,VVariables.ul,VVariables.ullae,VVariables.pin,VVariables.pinnae,VVariables.piraku,VVariables.mun,VVariables.vel1iyae,VVariables.itaiyae,VVariables.vittu,VVariables.pola,VVariables.vita,VVariables.munnittu,VVariables.poruththavarai,VVariables.mattum,VVariables.maathiram,VVariables.naduvae,VVariables.arukil,VVariables.pathil,VVariables.uriya,VVariables.thakuntha,VVariables.maar1aaka,VVariables.neeraaka,VVariables.kurukkae,VVariables.patr1i,VVariables.kuriththu/*,VVariables.kondu,VVariables.kondu*/};
byte[] givenBytes = (byte[])s.peek();
boolean isHaving = false;
for(int i=0;i<pospos.length;i++)
if(bm.endswith(givenBytes,pospos[i]))
{
remove_PosPos(s,pospos[i]);
isHaving = true;
break;
}
return isHaving;
}
示例2: onItemUseFirst
import java.util.Stack; //导入方法依赖的package包/类
@Override
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos,
EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand)
{
TileEntity te = world.getTileEntity(pos);
if(te instanceof TileEntityInfusionRepair)
{
Stack<RecipeElement> pendingIngredients = ((TileEntityInfusionRepair)te).getPendingIngredients();
if(!pendingIngredients.isEmpty())
{
RecipeElement element = pendingIngredients.peek();
player.sendMessage(new TextComponentString(element.toFriendlyString()));
}
}
return EnumActionResult.SUCCESS;
}
示例3: buildTreeFromDB
import java.util.Stack; //导入方法依赖的package包/类
/**
* Builds a condition tree starting from a database cursor. The cursor
* should point to rows representing the nodes of the tree.
*
* @param cursor Cursor pointing to the first of a bunch or rows. Each rows
* should contains 1 tree node.
* @return A condition tree.
*/
public static ConditionsTreeNode buildTreeFromDB(Cursor cursor) {
Stack<ConditionsTreeNode> stack = new Stack<ConditionsTreeNode>();
ConditionsTreeNode tmp = null;
// root node
if (cursor.moveToFirst()) {
tmp = buildNodeFromRow(cursor);
stack.push(tmp);
}
// other nodes
while (cursor.moveToNext()) {
tmp = buildNodeFromRow(cursor);
if (tmp.mRightMPTTMarker < stack.peek().mRightMPTTMarker) {
stack.peek().mLeft = tmp;
stack.push(tmp);
} else {
while (stack.peek().mRightMPTTMarker < tmp.mRightMPTTMarker) {
stack.pop();
}
stack.peek().mRight = tmp;
}
}
return tmp;
}
示例4: isCanPop
import java.util.Stack; //导入方法依赖的package包/类
private static boolean isCanPop(Stack<Integer> push, int[] pop) {
Stack<Integer> stack = new Stack<>();
for (int i = 0; i < pop.length; i++) {
int p = pop[i];
Integer peek = null;
if (!stack.empty()) {
peek = stack.peek();
}
if (peek==null||peek != p) {//如果栈顶不是当前 要出栈的数字 ,那么入栈,直到
while (!push.empty()&&push.peek() != p) {
stack.push(push.pop());
}
if (!push.empty()) {//找到这个
continue;
} else { //已经空了
return false;
}
} else {
stack.pop();
}
}
return true;
}
示例5: join
import java.util.Stack; //导入方法依赖的package包/类
/**
* Joins two consecutive LiteralTokens into one LiteralToken to reduce
* method calls later on. A side effect is that line numbers aren't exact anymore because the joined token has
* either the line number of the first one or the second one.
* <p>
* This could be prevented by implementing fromLine-toLine instead of just line, but it's probably not worth it.
*
* @param tokens the list of tokens
* @return a list of tokens where consecutive literals are joined together
*/
private List<Token> join(List<Token> tokens) {
Stack<Token> joinedToken = new Stack<>();
for (Token token : tokens) {
if (!token.contents.isEmpty()) {
if (joinedToken.isEmpty()) {
joinedToken.push(token);
} else if (joinedToken.peek() instanceof Token.Literal && token instanceof Token.Literal) {
// If both are literals, they can be joined. The line number is taken from the lower one.
Token top = joinedToken.pop();
joinedToken.push(new Token.Literal(
top.contents + token.contents,
token.source,
token.line,
top.offs));
} else {
joinedToken.push(token);
}
}
}
return joinedToken;
}
示例6: printListReversingly
import java.util.Stack; //导入方法依赖的package包/类
public void printListReversingly (ListNode head) {
Stack<ListNode> stack = new Stack<ListNode>();
ListNode temp = head;
while (temp != null) {
stack.push(temp);
temp = temp.next;
}
while (!stack.empty()) {
ListNode node = stack.peek();
System.out.print(node.val + " ");
stack.pop();
}
}
示例7: startPrefixMapping
import java.util.Stack; //导入方法依赖的package包/类
/**
* Begin the scope of namespace prefix. Forward the event to the
* SAX handler only if the prefix is unknown or it is mapped to a
* different URI.
*/
private boolean startPrefixMapping(String prefix, String uri)
throws SAXException
{
boolean pushed = true;
Stack<String> uriStack = _nsPrefixes.get(prefix);
if (uriStack != null) {
if (uriStack.isEmpty()) {
_sax.startPrefixMapping(prefix, uri);
uriStack.push(uri);
} else {
final String lastUri = uriStack.peek();
if (!lastUri.equals(uri)) {
_sax.startPrefixMapping(prefix, uri);
uriStack.push(uri);
} else {
pushed = false;
}
}
} else {
_sax.startPrefixMapping(prefix, uri);
_nsPrefixes.put(prefix, uriStack = new Stack());
uriStack.push(uri);
}
return pushed;
}
示例8: bigNum
import java.util.Stack; //导入方法依赖的package包/类
/**
* Adds the given number as a push data chunk to the given index in the program.
* This is intended to use for negative numbers or values > 16, and although
* it will accept numbers in the range 0-16 inclusive, the encoding would be
* considered non-standard.
*
* @see #number(int)
*/
protected ScriptBuilder bigNum(int index, long num) {
final byte[] data;
if (num == 0) {
data = new byte[0];
} else {
Stack<Byte> result = new Stack<>();
final boolean neg = num < 0;
long absvalue = Math.abs(num);
while (absvalue != 0) {
result.push((byte) (absvalue & 0xff));
absvalue >>= 8;
}
if ((result.peek() & 0x80) != 0) {
// The most significant byte is >= 0x80, so push an extra byte that
// contains just the sign of the value.
result.push((byte) (neg ? 0x80 : 0));
} else if (neg) {
// The most significant byte is < 0x80 and the value is negative,
// set the sign bit so it is subtracted and interpreted as a
// negative when converting back to an integral.
result.push((byte) (result.pop() | 0x80));
}
data = new byte[result.size()];
for (int byteIdx = 0; byteIdx < data.length; byteIdx++) {
data[byteIdx] = result.get(byteIdx);
}
}
// At most the encoded value could take up to 8 bytes, so we don't need
// to use OP_PUSHDATA opcodes
return addChunk(index, new ScriptChunk(data.length, data));
}
示例9: toString
import java.util.Stack; //导入方法依赖的package包/类
/**
* Returns the String representation of the bean given in the constructor.
* <p>
* It uses the Class name as the prefix.
* <p>
* @return bean object String representation.
*
*/
public String toString() {
Stack stack = (Stack) PREFIX_TL.get();
String[] tsInfo = (String[]) ((stack.isEmpty()) ? null : stack.peek());
String prefix;
if (tsInfo==null) {
String className = _obj.getClass().getName();
prefix = className.substring(className.lastIndexOf(".")+1);
}
else {
prefix = tsInfo[0];
tsInfo[1] = prefix;
}
return toString(prefix);
}
示例10: toggleRemoveSelection
import java.util.Stack; //导入方法依赖的package包/类
private void toggleRemoveSelection(TreePath path) {
Stack stack = new Stack();
TreePath parent = path.getParentPath();
while (parent != null && !isPathSelected(parent)) {
stack.push(parent);
parent = parent.getParentPath();
}
if (parent != null) {
stack.push(parent);
} else {
super.removeSelectionPaths(new TreePath[]{path});
return;
}
while (!stack.isEmpty()) {
TreePath temp = (TreePath) stack.pop();
TreePath peekPath = stack.isEmpty() ? path : (TreePath) stack.peek();
Object node = temp.getLastPathComponent();
Object peekNode = peekPath.getLastPathComponent();
int childCount = model.getChildCount(node);
for (int i = 0; i < childCount; i++) {
Object childNode = model.getChild(node, i);
if (childNode != peekNode) {
super.addSelectionPaths(new TreePath[]{temp.pathByAddingChild(childNode)});
}
}
}
super.removeSelectionPaths(new TreePath[]{parent});
}
示例11: execute
import java.util.Stack; //导入方法依赖的package包/类
/**
* Execute the instruction.
* @param frame The currently executed frame.
* @throws ExecutionException Thrown in case of fatal problems during the execution.
*/
@Override
public void execute(Frame frame) throws ExecutionException {
try {
Stack<Object> stack = frame.getOperandStack();
Object object = stack.peek();
if (checkCategory2(object))
throw new ExecutionException("The top value of the operand stack must not be a category 2 type when using " + getName() + ".");
stack.push(object);
} catch (ExecutionException e) {
executionFailed(e);
}
}
示例12: main
import java.util.Stack; //导入方法依赖的package包/类
public static void main(String... args) throws IOException {
Stack s = new Stack();
if (args == null)
s.peek();
else {
Stack r = s;
r.pop();
}
}
示例13: iterativeTraverse
import java.util.Stack; //导入方法依赖的package包/类
/**
* Iteratively traverses a tree from the specified node in a post-order
* fashion, performing computations at each node.
* @param node The node the traversal starts from.
* @param pv The population vector to use for node computations.
*/
public void iterativeTraverse(Node root, PopulationVector pv) {
Stack<Node> s = new Stack<Node>();
s.push(root);
Node prev = null;
while (!s.empty()) {
Node curr = s.peek();
if (prev == null || prev.leftChild() == curr || prev.rightChild() == curr) {
if (curr.leftChild() != null)
s.push(curr.leftChild());
else if (curr.rightChild() != null)
s.push(curr.rightChild());
// If traversing up tree from left, traverse to right child if available.
} else if (curr.leftChild() == prev && curr.rightChild() != null) {
s.push(curr.rightChild());
}
// Otherwise traversing up tree from right, compute g arrays and pop.
else {
if (curr.isLeaf()) {
initLeafNode(curr, pv);
} else {
computeSubnetNode(curr, pv);
}
s.pop();
}
prev = curr;
}
}
示例14: isValid
import java.util.Stack; //导入方法依赖的package包/类
public boolean isValid(String s){
int length = s.length();
int i = 0;
Stack<Character> stack = new Stack<>();
while(i < length){
if(s.charAt(i) == '(' || s.charAt(i) == '[' || s.charAt(i) == '{'){
stack.push(s.charAt(i));
i++;
continue;
}
if(s.charAt(i) == ')' && !stack.empty() && stack.peek() == '('){
stack.pop();
i++;
continue;
}else{
stack.push(s.charAt(i));
}
if(s.charAt(i) == ']' && !stack.empty() && stack.peek() == '['){
stack.pop();
i++;
continue;
}else{
stack.push(s.charAt(i));
}
if(s.charAt(i) == '}' && !stack.empty() && stack.peek() == '{'){
stack.pop();
i++;
continue;
}else{
stack.push(s.charAt(i));
}
i++;
continue;
}
return stack.empty();
}
示例15: execute
import java.util.Stack; //导入方法依赖的package包/类
public void execute() {
Method mainMethod = methodArea.queryMainMethod(classFile).orElseThrow(() -> new RuntimeException("没有可执行的main方法"));
Stack<StackFrame> frames = new Stack<>();
frames.add(new StackFrame(mainMethod));
List<AbstractCommand> commands = mainMethod.getCodeAttribute().getCommands();
StackFrame frame = frames.peek();
for (int i = frame.getIndex(); i < commands.size(); ) {
AbstractCommand command = commands.get(i);
ExecutionResult result = new ExecutionResult();
command.execute(frame, result);
if (result.isRunNextCmd()) { // 运行下一条指令
frame.setIndex(i++);
} else if (result.isPauseAndRunNewFrame()) { // 调用另一个函数
// 保存当前函数下一条要执行的命令
frame.setIndex(i + 1);
frame = _generateStackFrame(frame, frame.getOperandStack(), result.getNextMethod());
frames.push(frame);
commands = frame.getCommands();
i = frame.getIndex();
} else if (result.isExitCurrentFrame()) {
frames.pop();
if (frames.isEmpty()) return;
frame = frames.peek();
commands = frame.getCommands();
i = frame.getIndex();
} else if(result.isJump()) {
frame.setIndex(result.getNextCmdOffset());
i = result.getNextCmdOffset();
}
}
}