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

org.aksw.commons.collections.stacks.GenericNestedStack Maven / Gradle / Ivy

There is a newer version: 0.9.9
Show newest version
package org.aksw.commons.collections.stacks;

import java.util.AbstractCollection;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

public class GenericNestedStack>
    extends AbstractCollection
{
    protected P parent;
    protected T value;

    // The depth corresponds to the size of the collection
    protected int size;

    public GenericNestedStack(P parent, T value) {
        super();
        this.parent = parent;
        this.value = value;

        size = parent == null ? 1 : parent.size + 1;
    }

    public P getParent() {
        return parent;
    }

    public T getValue() {
        return value;
    }


    public List asList() {
        List result = new ArrayList(this);
//
//        NestedStack current = this;
//        while(current != null) {
//            result.add(current.getValue());
//            current = current.parent;
//        }
//
        Collections.reverse(result);

        return result;
    }

    @Override
    public Iterator iterator() {
        Iterator result = new NestedStackIterator(this);
        return result;
    }

    @Override
    public int size() {
        return size;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy