package com.changhong.epc.demo;
|
|
import java.util.Collection;
|
import java.util.HashMap;
|
import java.util.Iterator;
|
import java.util.LinkedList;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.Objects;
|
|
public class SelectList implements Collection<Map> {
|
|
protected List<Map> list = new LinkedList<>();
|
|
protected boolean distory = false;
|
|
protected Map first;
|
|
protected Map newObj;
|
|
@Override
|
public boolean add(Map e) {
|
if(first == null || Objects.equals(first.get("rowNo"), e.get("rowNo"))){
|
getNewObj()
|
.put(e.get("eleCode"), e.get("eleValue"));
|
}else{
|
list.add(getNewObj());
|
newObj = null;
|
getNewObj()
|
.put(e.get("eleCode"), e.get("eleValue"));
|
}
|
first = e;
|
return false;
|
}
|
|
public Map getNewObj(){
|
return newObj == null ? (newObj = new HashMap<>()) : newObj;
|
}
|
|
// protected abstract R newInstanceR();
|
|
@Override
|
public int size() {
|
return list.size();
|
}
|
|
@Override
|
public boolean isEmpty() {
|
return list.isEmpty();
|
}
|
|
@Override
|
public boolean contains(Object o) {
|
return list.contains(o);
|
}
|
|
@Override
|
public Iterator<Map> iterator() {
|
return null;
|
}
|
|
@Override
|
public Object[] toArray() {
|
distory();
|
return list.toArray();
|
}
|
|
@Override
|
public <T> T[] toArray(T[] a) {
|
distory();
|
return list.toArray(a);
|
}
|
|
private void distory() {
|
if(!distory){
|
toArrayFilter();
|
distory = true;
|
}
|
}
|
|
/**
|
* 获得返回数组
|
*/
|
protected void toArrayFilter(){
|
list.add(getNewObj());
|
newObj = null;
|
}
|
|
/**
|
* 获得整理后的list
|
* @return
|
*/
|
public List<Map> getList(){
|
distory();
|
return list;
|
}
|
|
@Override
|
public boolean remove(Object o) {
|
return list.remove(o);
|
}
|
|
@Override
|
public boolean containsAll(Collection<?> c) {
|
return list.containsAll(c);
|
}
|
|
@Override
|
public boolean addAll(Collection<? extends Map> c) {
|
return false;
|
}
|
|
@Override
|
public boolean removeAll(Collection<?> c) {
|
return list.removeAll(c);
|
}
|
|
@Override
|
public boolean retainAll(Collection<?> c) {
|
return list.retainAll(c);
|
}
|
|
@Override
|
public void clear() {
|
list.clear();
|
}
|
|
|
|
}
|