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

com.zebrunner.carina.utils.parser.xls.AbstractTable Maven / Gradle / Ivy

The newest version!
package com.zebrunner.carina.utils.parser.xls;

import com.zebrunner.carina.dataprovider.DataProviderParameterGenerator;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;

public abstract class AbstractTable {

    protected List headers;
    protected List> dataRows;
    protected String executeColumn;
    protected String executeValue;

    protected AbstractTable() {
        headers = Collections.synchronizedList(new LinkedList());
        dataRows = Collections.synchronizedList(new LinkedList>());
    }

    protected AbstractTable(String executeColumn, String executeValue) {
        this();
        this.executeColumn = executeColumn;
        this.executeValue = executeValue;
    }

    public List getHeaders() {
        return headers;
    }

    public List> getDataRows() {
        return dataRows;
    }

    public String getExecuteColumn() {
        return executeColumn;
    }

    public void setExecuteColumn(String executeColumn) {
        this.executeColumn = executeColumn;
    }

    public String getExecuteValue() {
        return executeValue;
    }

    public void setExecuteValue(String executeValue) {
        this.executeValue = executeValue;
    }

    public void setHeaders(Collection row) {
        headers.clear();
        headers.addAll(row);
    }

    public abstract void addDataRow(List row);

    public void processTable() {
        for (Map row : dataRows) {
            DataProviderParameterGenerator.processMap(row);
        }
    }

    public List>> getGroupedDataProviderMap(String fieldName) {
        // add unique group values
        Set groupValues = new LinkedHashSet<>();
        for (Map item : dataRows) {
            String value = item.get(fieldName);
            groupValues.add(value);
        }

        // group maps into lists, that has the same unique group value
        List>> groupedList = new ArrayList<>();
        for (String groupBy : groupValues) {
            List> groupOfRows = new ArrayList<>();
            for (Map item : dataRows) {
                String value = item.get(fieldName);
                if (value.equals(groupBy)) {
                    groupOfRows.add(item);
                }
            }
            groupedList.add(groupOfRows);
        }

        return groupedList;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy