/*
 * List.java  $Revision: 1.1 $  $Date: 2007/10/02 03:42:04 $
 *
 * Copyright (c) Meldcraft, Inc. 2006
 */
package com.meldcraft.marsviewer;

/**
 * @version $Revision: 1.1 $ $Date: 2007/10/02 03:42:04 $
 * @author Rob Richards
 */
public class List
{
    private String[]    mItems;
    private int         mIndex = 0;

    public void setItems(String[] items)
    {
        mItems = items;
    }

    public synchronized String next()
    {
        String ret = null;

        String[] items = mItems;
        if ((items != null) && (items.length > 0))
        {
            mIndex = (mIndex + 1) % items.length;
            ret = items[mIndex];
        }

        return ret;
    }

    public synchronized String previous()
    {
        String ret = null;

        String[] items = mItems;
        if ((items != null) && (items.length > 0))
        {
            if (mIndex > items.length)
            {
                mIndex = items.length;
            }

            if (mIndex == 0)
            {
                mIndex = items.length - 1;
            }
            else
            {
                mIndex--;
            }

            ret = items[mIndex];
        }

        return ret;
    }

    public synchronized String current()
    {
        String ret = null;

        String[] items = mItems;
        if ((items != null) && (items.length > 0))
        {
            int idx = (mIndex >= items.length) ? items.length-1 : mIndex;
            ret = items[idx];
        }

        return ret;
    }
}



