📄 abstractiterationstate.java
字号:
package com.reddragon2046.base.utilities.data.collections;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.*;
// Referenced classes of package com.reddragon2046.base.utilities.data.collections:
// IterationState
abstract class AbstractIterationState
implements IterationState
{
public abstract Object clone();
public abstract Iterator getIterator();
public abstract Collection getCollection();
public abstract ListIterator getListIterator();
protected AbstractIterationState(Collection c, Object currentObject, int index)
{
if(c == null)
throw new IllegalArgumentException("Collection cannot be null");
if(c.size() == 0)
{
m_object = null;
m_index = 0;
m_atBegin = true;
m_atEnd = true;
} else
{
m_index = index;
if(m_index == 0)
m_atBegin = true;
else
m_atBegin = false;
if(m_index < c.size())
{
m_atEnd = false;
m_object = currentObject;
} else
{
m_atEnd = true;
m_object = null;
}
}
m_lastDirection = 0;
}
protected AbstractIterationState(Collection c, Iterator iterator, int index)
{
if(c == null)
throw new IllegalArgumentException("Collection cannot be null");
if(iterator == null && index < c.size())
throw new IllegalArgumentException("Iterator cannot be null, except finish iterator.");
if(c.size() == 0)
{
m_object = null;
m_index = 0;
m_atBegin = true;
m_atEnd = true;
} else
{
m_index = index;
if(m_index == 0)
m_atBegin = true;
else
m_atBegin = false;
if(m_index < c.size() && iterator != null && iterator.hasNext())
{
m_atEnd = false;
m_object = iterator.next();
} else
{
m_atEnd = true;
m_object = null;
}
}
m_lastDirection = 0;
}
protected AbstractIterationState(IterationState other)
{
m_index = other.getIndex();
m_object = other.getObject();
m_atBegin = other.getAtBegin();
m_atEnd = other.getAtEnd();
m_lastDirection = other.getLastDirection();
}
public String toString()
{
StringWriter buf = new StringWriter();
PrintWriter writer = new PrintWriter(buf);
writer.print("index=" + m_index + ", dir=" + m_lastDirection + ", atBegin=" + m_atBegin + ", atEnd=" + m_atEnd + ", obj=" + m_object);
return buf.toString();
}
public boolean getAtBegin()
{
return m_atBegin;
}
public void setAtBegin(boolean atBegin)
{
m_atBegin = atBegin;
}
public boolean getAtEnd()
{
return m_atEnd;
}
public void setAtEnd(boolean atEnd)
{
m_atEnd = atEnd;
}
public int getIndex()
{
return m_index;
}
public void setIndex(int index)
{
int originalIndex = m_index;
m_index = index;
int distance = m_index - originalIndex;
if(distance > 0)
m_lastDirection = 1;
else
if(distance < 0)
m_lastDirection = -1;
else
m_lastDirection = 0;
}
public void incrementIndex()
{
m_index++;
m_lastDirection = 1;
}
public void decrementIndex()
{
m_index--;
m_lastDirection = -1;
if(m_index == 0)
setAtBegin(true);
}
public int getLastDirection()
{
return m_lastDirection;
}
public Object getObject()
{
return m_object;
}
public void setObject(Object object)
{
m_object = object;
}
protected boolean m_atBegin;
protected boolean m_atEnd;
protected Object m_object;
protected int m_index;
protected int m_lastDirection;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -