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


Java Stack类代码示例

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


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

示例1: writeStack

import java.util.Stack; //导入依赖的package包/类
/**
 * Writes an <code>Stack</code> to a <code>DataOutput</code>. Note that even though
 * <code>list</code> may be an instance of a subclass of <code>Stack</code>,
 * <code>readStack</code> will always return an instance of <code>Stack</code>, <B>not</B> an
 * instance of the subclass. To preserve the class type of <code>list</code>,
 * {@link #writeObject(Object, DataOutput)} should be used for data serialization.
 *
 * @throws IOException A problem occurs while writing to <code>out</code>
 *
 * @see #readStack
 * @since GemFire 5.7
 */
public static void writeStack(Stack<?> list, DataOutput out) throws IOException {

  InternalDataSerializer.checkOut(out);

  int size;
  if (list == null) {
    size = -1;
  } else {
    size = list.size();
  }
  InternalDataSerializer.writeArrayLength(size, out);
  if (logger.isTraceEnabled(LogMarker.SERIALIZER)) {
    logger.trace(LogMarker.SERIALIZER, "Writing Stack with {} elements: {}", size, list);
  }
  if (size > 0) {
    for (int i = 0; i < size; i++) {
      writeObject(list.get(i), out);
    }
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:33,代码来源:DataSerializer.java

示例2: rollbackTransactionToTheLatestSavepoint

import java.util.Stack; //导入依赖的package包/类
/**
 * 将事务回滚到最近的一个保存点,若没有保存点则回滚到开始事务处
 */
public static void rollbackTransactionToTheLatestSavepoint() {
    Connection connection = tl_conn.get();
    if (connection == null) {
        throw new RuntimeException("You do not start a Transaction so you can not rollback a transaction!");
    }
    try {
        Stack<Savepoint> stack_sp = tl_sp.get();
        if (stack_sp.empty()) {
            JDBCUtils.rollbackTransaction();
            return;
        }
        connection.rollback(stack_sp.pop());
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:FlyingHe,项目名称:UtilsMaven,代码行数:20,代码来源:JDBCUtils.java

示例3: getFirstRTextAreaDescendant

import java.util.Stack; //导入依赖的package包/类
/**
 * Returns the first descendant of a component that is an
 * <code>RTextArea</code>.  This is primarily here to support
 * <code>javax.swing.JLayer</code>s that wrap <code>RTextArea</code>s.
 *
 * @param comp The component to recursively look through.
 * @return The first descendant text area, or <code>null</code> if none
 *         is found.
 */
private static RTextArea getFirstRTextAreaDescendant(Component comp) {
	Stack<Component> stack = new Stack<Component>();
	stack.add(comp);
	while (!stack.isEmpty()) {
		Component current = stack.pop();
		if (current instanceof RTextArea) {
			return (RTextArea)current;
		}
		if (current instanceof Container) {
			Container container = (Container)current;
			stack.addAll(Arrays.asList(container.getComponents()));
		}
	}
	return null;
}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:25,代码来源:RTextScrollPane.java

示例4: BSTInOrder

import java.util.Stack; //导入依赖的package包/类
public static List<Integer> BSTInOrder(BinaryTree<Integer> node) {
    ArrayList<Integer> list = new ArrayList<>();
    Stack<BinaryTree<Integer>> stack = new Stack<>();
    while (!node.isVisited || !stack.isEmpty()) {
        if (node.isVisited)
            node = stack.pop();
        if (node.left != null && !node.left.isVisited) {
            stack.push(node);
            node = node.left;
        } else {
            list.add(node.data);
            node.isVisited = true;
            if (node.right != null)
                node = node.right;
        }
    }
    return list;
}
 
开发者ID:gardncl,项目名称:elements-of-programming-interviews-solutions,代码行数:19,代码来源:InorderIterative.java

示例5: beginEdits

import java.util.Stack; //导入依赖的package包/类
/**
 * Initialize the buffer
 */
void beginEdits(int offset, int length) {
    this.offset = offset;
    this.length = length;
    this.endOffset = offset + length;
    pos = offset;
    if (changes == null) {
        changes = new Vector<ElemChanges>();
    } else {
        changes.removeAllElements();
    }
    if (path == null) {
        path = new Stack<ElemChanges>();
    } else {
        path.removeAllElements();
    }
    fracturedParent = null;
    fracturedChild = null;
    offsetLastIndex = offsetLastIndexOnReplace = false;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:23,代码来源:DefaultStyledDocument.java

示例6: pushOverride

import java.util.Stack; //导入依赖的package包/类
public void pushOverride(String path, int index)
{
	if( overrides == null )
	{
		overrides = new Stack<PathOverride>();
	}

	PropBagEx base = bag;
	if( !overrides.isEmpty() )
	{
		base = overrides.peek().override;
	}

	PropBagEx subtree = null;
	if( base != null )
	{
		subtree = base.getSubtree(path + '[' + index + ']');
	}

	overrides.add(new PathOverride(ensureNoSlash(ensureSlash(path)), subtree));
}
 
开发者ID:equella,项目名称:Equella,代码行数:22,代码来源:PropBagWrapper.java

示例7: consumeOneArgument

import java.util.Stack; //导入依赖的package包/类
private int consumeOneArgument(ArgSpec argSpec,
                               Range arity,
                               Stack<String> args,
                               Class<?> type,
                               List<Object> result,
                               int index,
                               String argDescription) throws Exception {
    String[] values = argSpec.splitValue(trim(args.pop()));
    ITypeConverter<?> converter = getTypeConverter(type, argSpec, 0);

    for (int j = 0; j < values.length; j++) {
        result.add(tryConvert(argSpec, index, converter, values[j], type));
        if (tracer.isInfo()) {
            tracer.info("Adding [%s] to %s for %s%n", String.valueOf(result.get(result.size() - 1)), argSpec.toString(), argDescription);
        }
    }
    //checkMaxArityExceeded(arity, max, field, values);
    return ++index;
}
 
开发者ID:remkop,项目名称:picocli,代码行数:20,代码来源:CommandLine.java

示例8: ChorusCache

import java.util.Stack; //导入依赖的package包/类
public ChorusCache(World world, BlockPos current) {
    this.world = world;
    this.chorus = new ArrayList<>();
    Stack<BlockPos> chorus = new Stack<>();
    chorus.push(current);
    while (!chorus.isEmpty()) {
        BlockPos checking = chorus.pop();
        if (BlockUtils.isChorus(world, checking)) {
            Iterable<BlockPos> area = BlockPos.getAllInBox(checking.offset(EnumFacing.DOWN).offset(EnumFacing.SOUTH).offset(EnumFacing.WEST), checking.offset(EnumFacing.UP).offset(EnumFacing.NORTH).offset(EnumFacing.EAST));
            for (BlockPos blockPos : area) {
                if (BlockUtils.isChorus(world, blockPos) && !this.chorus.contains(blockPos) && blockPos.distanceSq(current.getX(), current.getY(), current.getZ()) <= 1000) {
                    chorus.push(blockPos);
                    this.chorus.add(blockPos);
                }
            }
        }
    }
}
 
开发者ID:Buuz135,项目名称:Industrial-Foregoing,代码行数:19,代码来源:ChorusCache.java

示例9: clitic_7

import java.util.Stack; //导入依赖的package包/类
static boolean clitic_7(Stack s)
{
	byte[] topElmt = ((Entry)s.peek()).getPart();
	byte[] oldTopElmt = topElmt;

	byte[] clitic = BooleanMethod.endsWith_Clitic_7(topElmt);
	if(clitic != null)
	{
		//System.out.println(x + "Clitic 7 - Avathu");
		s.pop();
		s.push(new Entry(clitic,Tag.Clitic));
		topElmt = ByteMeth.subArray(topElmt,0,topElmt.
			length-clitic.length);
		s.push(new Entry(topElmt,-1,oldTopElmt));
		Sandhi.clitic(s);
		return true;
	}
	return false;
}
 
开发者ID:tacola-auceg,项目名称:spellchecker_ta,代码行数:20,代码来源:Clitic.java

示例10: convertFahrenheitToCelsius

import java.util.Stack; //导入依赖的package包/类
private int convertFahrenheitToCelsius(String fahrenheit) {
	Stack<Integer> stack = new Stack<Integer>();

	// Subtract 32 from the temperature
	ldc.execute(stack, fahrenheit);
	bipush.execute(stack, 32);
	isub.execute(stack);
	
	// Multiply by 5
	bipush.execute(stack, 5);
	imul.execute(stack);

	// Divide by 9
	ldc.execute(stack, "Nine");
	idiv.execute(stack);
	
	// Pull the answer from the stack
	Integer celsius = stack.get(0);
	return celsius;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-systemtest,代码行数:21,代码来源:TestLambdaMultithreaded.java

示例11: create

import java.util.Stack; //导入依赖的package包/类
public void create()
{
    enemyStack = new Stack<Enemy>();


    Timer.schedule(new Task()
    {
        @Override
        public void run()
        {
            int choiceToMove = MathUtils.random(3);
            for(int i = 0; i < 5; i++)
            {
                enemyStack.add(new WeakEnemy(choiceToMove, xOffset * i, yOffset * i));
            }
            //Timer.instance().clear();
        }
    }, 0.5f, intervalBetweenSpawn);
}
 
开发者ID:UdealInferno,项目名称:Parasites-of-HellSpace,代码行数:20,代码来源:SpawningEnemy.java

示例12: _getStyleInfoStack

import java.util.Stack; //导入依赖的package包/类
/**
 * Returns the Stack for a Style info, creating it, if necessary.
 */
@SuppressWarnings("unchecked")
private static Stack<Object> _getStyleInfoStack(
  Stack[] styleInfo,
  int     stackIndex
  )
{
  Stack<Object> styleInfoStack = styleInfo[stackIndex];

  if (styleInfoStack == null)
  {
    // create new stack
    styleInfoStack = new Stack<Object>();

    // push on initial default
    styleInfoStack.push(_STYLE_DEFAULTS[stackIndex]);

    // save away new stack
    styleInfo[stackIndex] = styleInfoStack;
  }

  return styleInfoStack;
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:26,代码来源:XhtmlLafUtils.java

示例13: startTransaction

import java.util.Stack; //导入依赖的package包/类
/**
 * 开始一个事务,该事务连接是线程安全的。
 */
public static void startTransaction() {
    Connection connection = tl_conn.get();
    if (connection != null) {
        throw new RuntimeException(
                "You have started a Transaction and can not start transaction repeatedly for the same connection!");
    }

    try {
        connection = JDBCUtils.getConnection();
        connection.setAutoCommit(false);
        tl_conn.set(connection);
        tl_sp.set(new Stack<Savepoint>());
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:FlyingHe,项目名称:UtilsMaven,代码行数:20,代码来源:JDBCUtils.java

示例14: unsetLoggingContext

import java.util.Stack; //导入依赖的package包/类
/** Remove the elements from the Message Driven Context (MDC) of Log4J, that may have been added by the call to setLoggingContext().
 * @param payload Any serializable object.
 * @param messageInfo the corresponding MessageInfo object, as specified in the configuration file.
 */
public static void unsetLoggingContext(Object payload, MessageInfo messageInfo) {
    Stack<Map<String, Object>> stack = t_loggingContext.get();
    if (stack == null || stack.size() == 0)
        throw new UnsupportedOperationException("The unsetLoggingContext() method can only be called after a setLoggingContext()");

    // Remove the current context
    if (MDC.getContext() != null) {
        Set<String> keys = new HashSet<String>(MDC.getContext().keySet());
        for (String key : keys)
            MDC.remove(key);
    }

    // Now add the elements of the previous logging context into the MDC
    Map<String, Object> previousLoggingContext = stack.pop();
    for (Map.Entry<String, Object> me : previousLoggingContext.entrySet())
        MDC.put(me.getKey(), me.getValue());
}
 
开发者ID:jaffa-projects,项目名称:jaffa-framework,代码行数:22,代码来源:LoggingService.java

示例15: getNamingContextName

import java.util.Stack; //导入依赖的package包/类
/**
 * Get naming context full name.
 */
private String getNamingContextName() {
if (namingContextName == null) {
    Container parent = getParent();
    if (parent == null) {
    namingContextName = getName();
    } else {
    Stack<String> stk = new Stack<String>();
    StringBuilder buff = new StringBuilder();
    while (parent != null) {
        stk.push(parent.getName());
        parent = parent.getParent();
    }
    while (!stk.empty()) {
        buff.append("/" + stk.pop());
    }
    buff.append(getName());
    namingContextName = buff.toString();
    }
}
return namingContextName;
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:25,代码来源:StandardContext.java


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