class ListDiscoverer {

    public int findEntityColumn(Document document, String entityXPath) {
        int entityColumn = 0; // 0 means all columns are uniform and can be taken for extraction


        // find out how many columns the table has
        int columnCount = PageAnalyzer.getNumberOfTableColumns(document, entityXPath);

        List<Integer> uniformColumns = new ArrayList<Integer>();

        // for each column, get all entries in an array and check whether they look similar
        // List<Node> trNodes = XPathHelper.getNodesNS(document,pa.getParentNode(entityXPath));
        // Node firstTR = trNodes.get(0);
        for (int i = 1; i <= columnCount; i++) {
            List<String> columnEntries = new ArrayList<String>();
            List<Node> columnNodes = XPathHelper.getXhtmlNodes(document, setIndex(entityXPath, "td", i));
            List<Node> pureColumnNodes = XPathHelper.getXhtmlNodes(document,
                    PageAnalyzer.getTableCellPath(setIndex(entityXPath, "td", i)));
            for (int j = 0; j < columnNodes.size(); j++) {
                columnEntries.add(columnNodes.get(j).getTextContent());
            }
            if (entriesUniform(columnEntries, true) && columnEntries.size() > 0 || pureColumnNodes.size() <= 1) {
                uniformColumns.add(i);
                LOGGER.info("Column " + i + "/" + columnCount + " is uniform");
            } else {
                LOGGER.info("Column " + i + "/" + columnCount + " is not uniform");
            }
        }

        // no column is uniform, table should not be used for extraction
        if (uniformColumns.size() == 0) {
            LOGGER.info("No uniform columns found");
            return -1;
        }

        // all columns are uniform, no index required
        if (uniformColumns.size() == columnCount) {
            LOGGER.info("All columns are uniform");
            return 0;
        }

        // take the first uniform column, since the sought entity possibly appear in one of the first columns
        entityColumn = uniformColumns.get(0);

        return entityColumn;
    }

    public  ListDiscoverer();

}