Created
August 17, 2017 22:24
-
-
Save naosim/93218301cf91db80f83c2c414d4ac4f3 to your computer and use it in GitHub Desktop.
VariousColumnTable
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 VariousColumnTable<ROW> { | |
private final Map<Class, Integer> columnIndex; | |
private final Map<ROW, Object[]> rows; | |
public VariousColumnTable(Class ...columns) { | |
this.rows = new HashMap<>(); | |
this.columnIndex = new HashMap<>(); | |
for(int i = 0; i < columns.length; i++) { | |
columnIndex.put(columns[i], i); | |
} | |
} | |
public VariousColumnTable put(ROW row, Object ...cells) { | |
rows.put(row, cells); | |
return this; | |
} | |
public <T> T get(ROW row, Class<T> column) { | |
Object result = rows.get(row)[columnIndex.get(column)]; | |
return column.cast(result); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment