package com.ruifeng.core.util;
import java.util.Arrays;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
/**
* 数组 遍历器
*
* <pre>
* Object[] objects=new Object[5];
* objects[0]="string";
* objects[1]=new Integer(1);
* objects[2]=new Double(1d);
* obejcts[3]=new Date();
* objects[4]=new Boolean(false);
* 正常访问:
* String str=(String)objects[0];
* Integer i=(Integer)objects[1];
* Double d=(Double)objects[2];
* Date date=(Date)objects[3];
* Boolean bool=(Boolean)objects[4];
* Example:
* ObjectQueue queue=new ObjectQueue(objects);
* String str=queue.getString();
* Integer i=queue.getInteger();
* Double d=queue.getDouble();
* Date date=queue.getDate();
* Boolean bool=queue.getBoolean();
*
*
* </pre>
*
*
* @author Administrator
*
*/
public class ObjectQueue {
private Iterator<Object> iterator;
/**
* convert Object To object[]
*
* @param objects
*/
public ObjectQueue(Object objects) {
super();
iterator = Arrays.asList((Object[]) objects).iterator();
}
public ObjectQueue(Object[] objects) {
super();
iterator = Arrays.asList(objects).iterator();
}
public ObjectQueue(List<Object> objects) {
super();
iterator = objects.iterator();
}
public Integer getInteger() {
if (iterator.hasNext())
return NumberUtil.parseInt(iterator.next());
return null;
}
public Double getDouble() {
if (iterator.hasNext()) {
return NumberUtil.parseDouble(iterator.next());
}
return null;
}
public Float getFloat() {
if (iterator.hasNext()) {
return NumberUtil.parseFloat(iterator.next());
}
return null;
}
public String getString() {
if (iterator.hasNext()) {
return (String) iterator.next();
}
return null;
}
public Date getDate() {
if (iterator.hasNext()) {
return (Date) iterator.next();
}
return null;
}
public Short getShort() {
if (iterator.hasNext()) {
return NumberUtil.parseShort(iterator.next());
}
return null;
}
public Boolean getBoolean() {
if (iterator.hasNext()) {
return (Boolean) iterator.next();
}
return null;
}
public Long getLong() {
if (iterator.hasNext()) {
return NumberUtil.parseLong(iterator.next());
}
return null;
}
public Byte getByte() {
if (iterator.hasNext()) {
return (Byte) iterator.next();
}
return null;
}
public Object getObject() {
if (iterator.hasNext()) {
return iterator.next();
}
return null;
}
}