当前位置: 首页>>代码示例>>Java>>正文


Java Stack.push方法代码示例

本文整理汇总了Java中java.util.Stack.push方法的典型用法代码示例。如果您正苦于以下问题:Java Stack.push方法的具体用法?Java Stack.push怎么用?Java Stack.push使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.Stack的用法示例。


在下文中一共展示了Stack.push方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: execute

import java.util.Stack; //导入方法依赖的package包/类
/**
 * Execute the inheriting instruction.
 *
 * @param frame The currently executed frame.
 */
@Override
public void execute(Frame frame) {
	Stack<Object> stack = frame.getOperandStack();
	Float value2 = (Float) stack.pop();
	Float value1 = (Float) stack.pop();
	if (value1.isNaN() || value2.isNaN()) {
		stack.push(getPushValueForNaN());
	} else if (value1 > value2) {
		stack.push(Integer.valueOf(1));
	} else if (value1 < value2) {
		stack.push(Integer.valueOf(-1));
	} else {
		stack.push(Integer.valueOf(0));
	}
}
 
开发者ID:wwu-pi,项目名称:tap17-muggl-javaee,代码行数:21,代码来源:CompareFloat.java

示例2: isPalindrome2

import java.util.Stack; //导入方法依赖的package包/类
public static Boolean isPalindrome2(Node head) {
	if (head == null)
		return false;
	Node slow = head;
	Node fast = head;
	Stack<Integer> sta = new Stack<Integer>();
	while (fast != null && fast.next != null) {
		sta.push(slow.value);
		slow = slow.next;
		fast = fast.next.next;
	}
	if (fast != null)// 如果有奇数个节点,slow再往后移动一个
		slow = slow.next;

	while (!sta.isEmpty()) {
		if (sta.pop() != slow.value)
			return false;
		slow = slow.next;
	}
	return true;
}
 
开发者ID:selfconzrr,项目名称:LinkedList_learning,代码行数:22,代码来源:LinkedList.java

示例3: getTreePath

import java.util.Stack; //导入方法依赖的package包/类
public static TreePath getTreePath(JTreeOperator treeOperator, String targetNode, NodeConverter converter) {
    Stack<TreeNode> lifo = new Stack<TreeNode>();        
    lifo.push((TreeNode) treeOperator.getRoot());
    while(!lifo.isEmpty()) {
        TreeNode actNode = lifo.pop();
        if(targetNode.equals(converter.getDisplayName(actNode))) {
            List<TreeNode> path = new LinkedList<TreeNode>();
            path.add(actNode);
            actNode = actNode.getParent();
            while(actNode!=null) {
                path.add(0,actNode);
                actNode = actNode.getParent();
            }
            TreeNode[] res = path.toArray(new TreeNode[path.size()]);                
            return new TreePath(res);
        }
        final Enumeration children = actNode.children();            
        while(children.hasMoreElements()) {
            lifo.add((TreeNode)children.nextElement());
        }            
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:BeansTestCase.java

示例4: unmatchedQuotesIn

import java.util.Stack; //导入方法依赖的package包/类
private boolean unmatchedQuotesIn(final String str) {
    final Stack<Character> quoteStack = new Stack<>();
    for (int i = 0; i < str.length(); i++) {
        final char c = str.charAt(i);
        for (final char q : this.quotes) {
            if (c == q) {
                if (quoteStack.isEmpty()) {
                    quoteStack.push(c);
                } else {
                    final char top = quoteStack.pop();
                    if (top != c) {
                        quoteStack.push(top);
                        quoteStack.push(c);
                    }
                }
            }
        }
    }

    return !quoteStack.isEmpty();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:QuotedStringTokenizer.java

示例5: type5

import java.util.Stack; //导入方法依赖的package包/类
static boolean type5(Stack s)
{
	//5 - doubling
	byte[] topElmt = ((Entry)s.peek()).getPart();
	byte[] oldTopElmt = topElmt;
	byte[] sandhi = BooleanMethod.endswith_doubling_Letter(topElmt);
	if(sandhi != null)
	{
		//System.out.println(x + "type 5");
		s.pop();
		topElmt = ByteMeth.subArray(topElmt,0,
			topElmt.length-sandhi.length);
		s.push(new Entry(sandhi,Tag.Sandhi));
		s.push(new Entry(topElmt,-1,oldTopElmt));
		return true;
	}
	return false;
}
 
开发者ID:tacola-auceg,项目名称:spellchecker_ta,代码行数:19,代码来源:Sandhi.java

示例6: 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
@SuppressWarnings("unused")
public void execute(Frame frame) throws ExecutionException {
	Stack<Object> stack = frame.getOperandStack();
	stack.push(((Float) stack.pop()).longValue());
}
 
开发者ID:wwu-pi,项目名称:tap17-muggl-javaee,代码行数:12,代码来源:F2l.java

示例7: hasEndTag

import java.util.Stack; //导入方法依赖的package包/类
/**
 * Checks to see if an end tag exists for a start tag at a given offset.
 * @param document
 * @param offset
 * @return true if an end tag is found for the start, false otherwise.
 */
public static boolean hasEndTag(Document document, int offset, String startTag) {
    AbstractDocument doc = (AbstractDocument)document;
    doc.readLock();
    try {
        TokenHierarchy th = TokenHierarchy.get(doc);
        TokenSequence ts = th.tokenSequence();
        Token token = findTokenAtContext(ts, offset);
        Stack<String> stack = new Stack<String>();
        while(ts.moveNext()) {
            Token t = ts.token();
            if(XMLTokenId.TAG != t.id())
                continue;
            String tag = t.text().toString();
            if(">".equals(tag))
                continue;
            if(stack.empty()) {
                if(("</"+startTag).equals(tag)) {
                    stack.empty();
                    stack = null;
                    return true;
                }
            } else {                
                if(tag.equals("/>") || ("</"+stack.peek()).equals(tag)) {
                    stack.pop();
                    continue;
                }
            }
            stack.push(tag.substring(1));
        }            
    } finally {
        doc.readUnlock();
    }
    
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:42,代码来源:XMLBraceMatcher.java

示例8: executeSymbolically

import java.util.Stack; //导入方法依赖的package包/类
/**
 * Execute the instruction symbolically.
 * @param frame The currently executed frame.
 * @throws SymbolicExecutionException Thrown in case of fatal problems during the symbolic execution.
 */
@Override
public void executeSymbolically(Frame frame) throws SymbolicExecutionException {
	try {
		Stack<Object> stack = frame.getOperandStack();
		Object value1 = stack.pop();
		Object value2 = stack.pop();
		if (!checkCategory2(value1) && checkCategory2(value2)) {
			// Form 2: value1 is a type of category 1, while value2 is a type of category 2.
			stack.push(value2);
			stack.push(value1);
		} else {
			Object value3 = stack.pop();
			if (!(checkCategory2(value1) || checkCategory2(value2) || checkCategory2(value3))) {
				// Form 1: All three values are types of category 1.
				stack.push(value1);
				stack.push(value3);
				stack.push(value2);
				stack.push(value1);
			} else {
				// Recovery.
				stack.push(value3);
				stack.push(value2);
				stack.push(value1);
				throw new ExecutionException("When using " + getName() + " either the three topmost values of the operand stack must not be category 2 types, or the topmost value must be a category 1 type, while the second one must be a category 2 type.");
			}
		}
	} catch (ExecutionException e) {
		symbolicExecutionFailedWithAnExecutionException(e);
	}
}
 
开发者ID:wwu-pi,项目名称:tap17-muggl-javaee,代码行数:36,代码来源:Dup_x2.java

示例9: 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
@SuppressWarnings("unused")
public void execute(Frame frame) throws ExecutionException {
	Stack<Object> stack = frame.getOperandStack();
	stack.push((Double) stack.pop() * -1D);
}
 
开发者ID:wwu-pi,项目名称:tap17-muggl-javaee,代码行数:12,代码来源:DNeg.java

示例10: preorderTraverse

import java.util.Stack; //导入方法依赖的package包/类
public void preorderTraverse() {
    Stack<TreeNode<String>> stack = new Stack<>();
    stack.push(root);
    while (!stack.isEmpty()) {
        TreeNode<String> node = stack.pop();
        if (null == node) continue;
        System.out.print(node.getValue() + " ");
        stack.push(node.getRight());
        stack.push(node.getLeft());
    }
}
 
开发者ID:ApolloZhu,项目名称:APCSAB,代码行数:12,代码来源:BXT.java

示例11: checkReaderEnumContainsAllWriterEnumSymbols

import java.util.Stack; //导入方法依赖的package包/类
private SchemaCompatibilityResult checkReaderEnumContainsAllWriterEnumSymbols(
    final Schema reader, final Schema writer, final Stack<String> location) {
  SchemaCompatibilityResult result = SchemaCompatibilityResult.compatible();
  location.push("symbols");
  final Set<String> symbols = new TreeSet<String>(writer.getEnumSymbols());
  symbols.removeAll(reader.getEnumSymbols());
  if (!symbols.isEmpty()) {
    result = SchemaCompatibilityResult.incompatible(
        SchemaIncompatibilityType.MISSING_ENUM_SYMBOLS, reader, writer,
        symbols.toString(), location);
  }
  // POP "symbols" literal
  location.pop();
  return result;
}
 
开发者ID:HotelsDotCom,项目名称:avro-compatibility,代码行数:16,代码来源:SchemaCompatibility.java

示例12: applyValueToSingleValuedField

import java.util.Stack; //导入方法依赖的package包/类
private int applyValueToSingleValuedField(Field field,
                                          Range arity,
                                          Stack<String> args,
                                          Class<?> cls,
                                          Set<Field> initialized) throws Exception {
    boolean noMoreValues = args.isEmpty();
    String value = args.isEmpty() ? null : trim(args.pop()); // unquote the value
    int result = arity.min; // the number or args we need to consume

    // special logic for booleans: BooleanConverter accepts only "true" or "false".
    if ((cls == Boolean.class || cls == Boolean.TYPE) && arity.min <= 0) {

        // boolean option with arity = 0..1 or 0..*: value MAY be a param
        if (arity.max > 0 && ("true".equalsIgnoreCase(value) || "false".equalsIgnoreCase(value))) {
            result = 1;            // if it is a varargs we only consume 1 argument if it is a boolean value
        } else {
            if (value != null) {
                args.push(value); // we don't consume the value
            }
            Boolean currentValue = (Boolean) field.get(command);
            value = String.valueOf(currentValue == null ? true : !currentValue); // #147 toggle existing boolean value
        }
    }
    if (noMoreValues && value == null) {
        return 0;
    }
    if (initialized != null) {
        if (initialized.contains(field) && !isOverwrittenOptionsAllowed()) {
            throw new OverwrittenOptionException(optionDescription("", field, 0) +  " should be specified only once");
        }
        initialized.add(field);
    }
    ITypeConverter<?> converter = getTypeConverter(cls);
    Object objValue = tryConvert(field, -1, converter, value, cls);
    field.set(command, objValue);
    return result;
}
 
开发者ID:alisianoi,项目名称:lyra2-java,代码行数:38,代码来源:CommandLine.java

示例13: 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
@SuppressWarnings("unused")
public void execute(Frame frame) throws ExecutionException {
	Stack<Object> stack = frame.getOperandStack();
	Long value2 = (Long) stack.pop();
	Long value1 = (Long) stack.pop();
	stack.push(value1 + value2);
}
 
开发者ID:wwu-pi,项目名称:tap17-muggl-javaee,代码行数:14,代码来源:LAdd.java

示例14: execute

import java.util.Stack; //导入方法依赖的package包/类
/**
 * Execute the instruction.
 * @param frame The currently executed frame.
 */
@Override
public void execute(Frame frame) {
	Stack<Object> stack = frame.getOperandStack();
	stack.push((Long) stack.pop() | (Long) stack.pop());
}
 
开发者ID:wwu-pi,项目名称:tap17-muggl-javaee,代码行数:10,代码来源:LOr.java

示例15: disable

import java.util.Stack; //导入方法依赖的package包/类
/**
 * Disable this behaviour for the curent thread
 */
public void disable() 
{
    Stack<Integer> stack = disabled.get();
    stack.push(hashCode());
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:9,代码来源:BaseBehaviour.java


注:本文中的java.util.Stack.push方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。