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

com.apollographql.apollo.internal.util.SimpleStack Maven / Gradle / Ivy

/**
 * Copyright 2018-2019 Amazon.com,
 * Inc. or its affiliates. All Rights Reserved.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

package com.apollographql.apollo.internal.util;

import java.util.ArrayList;
import java.util.List;

/**
 * Simple stack data structure which accepts null elements. Backed by list.
 * @param 
 */
public class SimpleStack {

  private List backing;

  public SimpleStack() {
    backing = new ArrayList<>();
  }

  public SimpleStack(int initialSize) {
    backing = new ArrayList<>(initialSize);
  }

  public void push(E element) {
    backing.add(element);
  }

  public E pop() {
    if (isEmpty()) {
      throw new IllegalStateException("Stack is empty.");
    }
    return backing.remove(backing.size() - 1);
  }

  public boolean isEmpty() {
    return backing.isEmpty();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy