Skip to content

Instantly share code, notes, and snippets.

@naosim
Created August 17, 2017 22:06
Show Gist options
  • Save naosim/500abf02fd4c2881027411765f120cf7 to your computer and use it in GitHub Desktop.
Save naosim/500abf02fd4c2881027411765f120cf7 to your computer and use it in GitHub Desktop.
Table
package com.naosim.table;
import java.util.HashMap;
import java.util.Map;
public class Table<ROW, CLM, CELL> {
private final Map<CLM, Integer> columnIndex;
private final Map<ROW, CELL[]> rows;
public Table(CLM ...columns) {
this.rows = new HashMap<>();
this.columnIndex = new HashMap<>();
for(int i = 0; i < columns.length; i++) {
columnIndex.put(columns[i], i);
}
}
public Table put(ROW row, CELL ...cells) {
rows.put(row, cells);
return this;
}
public CELL get(ROW row, CLM column) {
return rows.get(row)[columnIndex.get(column)];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment