⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 limitedlist.java

📁 SAP这个系统的一个转换器
💻 JAVA
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   LimitedList.java

package com.sap.mw.jco.util;

import java.io.Serializable;

// Referenced classes of package com.sap.mw.jco.util:
//            ObjectList

public class LimitedList
    implements Cloneable, Serializable
{

    public LimitedList()
    {
        this(0);
    }

    public LimitedList(int limit)
    {
        m_list = null;
        m_first = 0;
        m_end = 0;
        if(limit < 0)
        {
            throw new IllegalArgumentException("limit < 0 [" + limit + "<0]");
        } else
        {
            m_list = new Object[limit];
            return;
        }
    }

    public LimitedList(Object objectArray[])
    {
        m_list = null;
        m_first = 0;
        m_end = 0;
        if(objectArray == null)
            throw new IllegalArgumentException("objectArray == null");
        for(int i = 0; i < objectArray.length; i++)
            if(objectArray[i] == null)
                throw new IllegalArgumentException("objectArray[" + i + "] == null");

        m_list = (Object[])objectArray.clone();
    }

    public final void clear()
    {
        for(int i = 0; i < m_list.length; i++)
            m_list[i] = null;

        m_first = m_end = 0;
    }

    public final void setLimit(int limit)
    {
        int size = size();
        if(limit < size)
            throw new IllegalArgumentException("limit is less than current size");
        Object oldList[] = m_list;
        m_list = new Object[limit];
        if(size == 0)
            return;
        if(m_end > m_first)
            System.arraycopy(((Object) (oldList)), m_first, ((Object) (m_list)), 0, m_end - m_first);
        else
        if(m_end <= m_first)
        {
            System.arraycopy(((Object) (oldList)), m_first, ((Object) (m_list)), 0, oldList.length - m_first);
            System.arraycopy(((Object) (oldList)), 0, ((Object) (m_list)), oldList.length - m_first, m_end);
        }
        m_first = 0;
        m_end = size;
    }

    public final int getLimit()
    {
        return m_list.length;
    }

    public final int size()
    {
        int size;
        if(m_end >= m_first)
        {
            size = m_end - m_first;
            if(size == 0 && m_list[m_first] != null)
                size = m_list.length;
        } else
        {
            size = (m_list.length - m_first) + m_end;
        }
        return size;
    }

    public final Object clone()
    {
        try
        {
            ObjectList cloned = (ObjectList)super.clone();
            cloned.m_list = (Object[])m_list.clone();
            return cloned;
        }
        catch(CloneNotSupportedException ex)
        {
            return null;
        }
    }

    public final boolean contains(Object object)
    {
        return indexOf(object, 0, true) > -1;
    }

    public final Object get(int index)
    {
        if(index < 0)
            throw new IndexOutOfBoundsException("index < 0 [" + index + "<0]");
        if(index >= size())
            throw new IndexOutOfBoundsException("index >= size() [" + index + ">=" + size() + "]");
        else
            return m_list[(index + m_first) % m_list.length];
    }

    public final int indexOf(Object object)
    {
        return indexOf(object, 0, true);
    }

    public final int indexOf(Object object, int startIndex)
    {
        return indexOf(object, startIndex, true);
    }

    public final int indexOf(Object object, int startIndex, boolean searchForward)
    {
        if(startIndex < 0)
            throw new IndexOutOfBoundsException("startIndex < 0 [" + startIndex + "<0]");
        if(startIndex > 0 && startIndex >= size())
            throw new IndexOutOfBoundsException("startIndex >= size() [" + startIndex + ">=" + size() + "]");
        if(object != null)
            if(searchForward)
            {
                int size = size();
                for(int i = startIndex; i < size; i++)
                    if(m_list[(i + m_first) % m_list.length].equals(object))
                        return i;

            } else
            {
                for(int i = size(); i >= 0; i--)
                    if(m_list[(i + m_first) % m_list.length].equals(object))
                        return i;

            }
        return -1;
    }

    public final boolean isEmpty()
    {
        return m_first == m_end && m_list[m_first] == null;
    }

    public final int lastIndexOf(Object object)
    {
        if(isEmpty())
            return -1;
        else
            return indexOf(object, size() - 1, false);
    }

    public final Object pop()
    {
        if(isEmpty())
            return null;
        if(--m_end < 0)
            m_end = m_list.length - 1;
        Object to_pop = m_list[m_end];
        m_list[m_end] = null;
        return to_pop;
    }

    public final Object push(Object object)
    {
        if(object == null)
            throw new IllegalArgumentException("object == null");
        Object removed = m_list[m_end];
        m_list[m_end] = object;
        m_end++;
        if(m_end == m_list.length)
            m_end = 0;
        if(removed != null)
        {
            m_first++;
            if(m_first == m_list.length)
                m_first = 0;
            return removed;
        } else
        {
            return null;
        }
    }

    public final Object remove(int index)
    {
        if(index < 0)
            throw new IndexOutOfBoundsException("index < 0 [" + index + "<0]");
        if(index >= size())
            throw new IndexOutOfBoundsException("index >= size() [" + index + ">=" + size() + "]");
        index = (m_first + index) % m_list.length;
        Object removed = m_list[index];
        m_list[index] = m_list[m_first];
        m_list[m_first] = null;
        m_first++;
        if(m_first == m_list.length)
            m_first = 0;
        return removed;
    }

    public final boolean remove(Object object)
    {
        int index = indexOf(object, 0, true);
        if(index >= 0)
            remove(index);
        return index >= 0;
    }

    public final Object set(int index, Object object)
    {
        if(index < 0)
            throw new IndexOutOfBoundsException("index < 0 [" + index + "<0]");
        if(index >= size())
            throw new IndexOutOfBoundsException("index >= size() [" + index + ">=" + size() + "]");
        if(object == null)
        {
            throw new IllegalArgumentException("object == null");
        } else
        {
            index = (m_first + index) % m_list.length;
            Object replaced = m_list[index];
            m_list[index] = object;
            return replaced;
        }
    }

    public final Object[] toArray()
    {
        Object array[] = new Object[size()];
        System.arraycopy(((Object) (m_list)), 0, ((Object) (array)), 0, size());
        return array;
    }

    public static void main(String a[])
    {
        LimitedList l = new LimitedList(10);
        for(Object obj = null; obj == null; obj = l.push(new Integer(10)));
        l.size();
        l.pop();
    }

    protected Object m_list[];
    protected int m_first;
    protected int m_end;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -