All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sun.msv.util.LightStack Maven / Gradle / Ivy

There is a newer version: 2.2.5.1
Show newest version
/*
 * @(#)$Id: LightStack.java,v 1.5 2003/06/09 20:37:40 kk122374 Exp $
 *
 * Copyright 2001 Sun Microsystems, Inc. All Rights Reserved.
 * 
 * This software is the proprietary information of Sun Microsystems, Inc.  
 * Use is subject to license terms.
 * 
 */
package com.sun.msv.util;

/**
 * light-weight stack implementation.
 * 
 * This one is unsynchronized, and never shrink its memory footprint, but fast.
 * 
 * @author Kohsuke KAWAGUCHI
 */
public final class LightStack {
    
    private Object[] buf = new Object[8];
    private int len = 0;
    
    public void push( Object o ) {
        try {
            buf[len] = o;
            len++;
        } catch( ArrayIndexOutOfBoundsException e ) {
            Object[] nbuf = new Object[buf.length*2];
            System.arraycopy( buf, 0, nbuf, 0, buf.length );
            buf = nbuf;
            buf[len++] = o;
        }
    }
    
    public Object pop() {
        return buf[--len];
    }
    
    public Object top() {
        return buf[len-1];
    }
    
    public int size() {
        return len;
    }
    
    public boolean contains( Object o ) {
        for( int i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy