All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.leeonky.dal.runtime.AutoMappingList Maven / Gradle / Ivy

package com.github.leeonky.dal.runtime;

import java.util.ArrayList;
import java.util.Collection;
import java.util.function.Function;

public class AutoMappingList extends ArrayList {
    private final int firstIndex;

    public  AutoMappingList(int firstIndex, Collection collection, Function mapper) {
        this.firstIndex = firstIndex;
        collection.forEach(obj -> {
            try {
                add(mapper.apply(obj));
            } catch (PropertyAccessException e) {
                throw new ElementAccessException(size() + this.firstIndex, e);
            } catch (Exception e) {
                throw new ElementAccessException(size() + this.firstIndex, new PropertyAccessException(e.getMessage(), e));
            }
        });
    }

    public int firstIndex() {
        return firstIndex;
    }
}