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

edu.stanford.protege.webprotege.csv.CSVGrid Maven / Gradle / Ivy

The newest version!
package edu.stanford.protege.webprotege.csv;



import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static com.google.common.base.Preconditions.checkElementIndex;
import static com.google.common.base.Preconditions.checkNotNull;

/**
 * Author: Matthew Horridge
* Stanford University
* Bio-Medical Informatics Research Group
* Date: 19/05/2013 */ public class CSVGrid { private final List grid = new ArrayList(); private int columnCount; private CSVGrid() { } private CSVGrid(List grid) { this.grid.addAll(checkNotNull(grid)); int maxRowSize = 0; for (CSVRow row : grid) { final int rowSize = row.size(); if (rowSize > maxRowSize) { maxRowSize = rowSize; } } columnCount = maxRowSize; } public List getRows() { return new ArrayList(grid); } public int getRowCount() { return grid.size(); } public int getColumnCount() { return columnCount; } /** * Gets the value at a given row and column. * @param rowIndex The row index. Must be greater or equal to zero and less than the row count. * @param columnIndex The column index. Must be greater or equal to zero and less than the column count. * @return The value at the specified row and column. Not {@code null}. * @throws IndexOutOfBoundsException if the row or column indexes are out of bounds. */ public String getValueAt(int rowIndex, int columnIndex) { checkElementIndex(rowIndex, getRowCount()); checkElementIndex(columnIndex, getColumnCount()); CSVRow rowValues = grid.get(rowIndex); if(columnIndex >= rowValues.size()) { return ""; } else { return rowValues.getColumnValue(columnIndex); } } public static Builder builder() { return new Builder(); } public static class Builder { private final List rows = new ArrayList(); public void addRow(CSVRow row) { checkNotNull(row); rows.add(row); } public void addRow(String ... rowItems) { addRow(Arrays.asList(rowItems)); } public void addRow(List rowItems) { rows.add(new CSVRow(rowItems)); } public CSVGrid build() { return new CSVGrid(rows); } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy