Created
August 17, 2017 22:06
-
-
Save naosim/500abf02fd4c2881027411765f120cf7 to your computer and use it in GitHub Desktop.
Table
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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