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

org.jharks.workflow.QueueWrapper Maven / Gradle / Ivy

package org.jharks.workflow;

import java.io.Serializable;
import java.util.Iterator;

import org.apache.commons.collections.UnboundedFifoBuffer;

/**
 * This class represents a basic stackable survey element. This class is a 
 * simple wrapper for Objects to be queued and allows for an 
 * assignment of a category type to the stackable element.  The 
 * QueueWrapper class facilitates the ability to handle 
 * inner loops on the same queue within the workflow.
 *  
 * @author Michael J. Rizzo
 * @version 1.0
 */
public class QueueWrapper implements Stackable, WorkFlowConstants, Serializable {

	private static final long serialVersionUID = 1L;

	/** The element type */
    private String elementType = GEN_CATEGORY;
    
    /** Value to which to set a property when iterating */
    private String propertyValue = null;
    
    /** The object to be added to the queue */
    private Object queueObject;
    
    /** Underlying queue of stackable queue element. */
    protected UnboundedFifoBuffer queue = null;
    
    /** 
     * Default public constructor.
     */
    public QueueWrapper() {
        queue = new UnboundedFifoBuffer();
    }
    
    /**
     * Public constructor that sets element type according to passed string.
     * @param elementType the passed category type.
     */
    public QueueWrapper(String elementType) {
        queue = new UnboundedFifoBuffer();
        this.elementType = elementType;
    }
    
    /**
     * Public constructor that sets element type according to passed string.
     * @param elementType the passed category type.
     * @param value the passed value to which to set the transitional property.
     */
    public QueueWrapper(String elementType, String value) {
        queue = new UnboundedFifoBuffer();
        this.elementType = elementType;
        this.propertyValue = value;
    }
    
    /**
     * @see org.jharks.workflow.Stackable#getElementType()
     */
    public String getElementType() {
        return this.elementType;
    }
    
    /**
     * Sets the element type.
     * @param elementType the type as a string to which 
     *        to set the element type.
     */
    public void setElementType(String elementType) {
        this.elementType = elementType;
    }
    
    /**
     * @see org.jharks.workflow.Stackable#getPropertyValue()
     */
    public String getPropertyValue() {
        return this.propertyValue;
    }
    
    /**
     * Sets the transitional property value.
     * @param value the value to which to set the tranisional property.
     */
    public void setPropertyValue(String value) {
        this.propertyValue = value;
    }

    /**
     * @see org.jharks.workflow.Stackable#setStackObject(Object item)
     */
    public void setStackObject(Object item) {
        this.queueObject = item;
    }
    
    /**
     * @see org.jharks.workflow.Stackable#getStackObject()
     */
    public Object getStackObject() {
        return this.queueObject;
    }
    
    public boolean add(Object obj) {
        return queue.add(obj);
    }
    
    public Object get() {
        return queue.get();
    }
    
    public Object remove() {
        return queue.remove();
    }
    
    public int queueSize() {
        return queue.size();
    }
    
    public boolean isEmpty() {
        return queue.isEmpty();
    }
    
    @SuppressWarnings("unchecked")
	public Iterator queueIterator() {
        return queue.iterator();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy