Guide to Guava Table 을 보며 정리한 내용입니다. 예제는 그대로 사용했으며, 자세한 내용은 링크를 확인하세요:)
1) HashBasedTable
Table<String, String, Integer> universityCourseSeatTable = HashBasedTable.create();
2) TreeBasedTable : 정렬 사용시
Table<String, String, Integer> universityCourseSeatTable = TreeBasedTable.create();
3) ArrayTable : 행, 열 및 테이블 크기 고정시
List<String> universityRowTable = Lists.newArrayList("Mumbai", "Harvard");
List<String> courseColumnTables = Lists.newArrayList("Chemical", "IT", "Electrical");
Table<String, String, Integer> universityCourseSeatTable = ArrayTable.create(universityRowTable, courseColumnTables);
4) ImmutableTable : 불변의 Table 인스턴스
Table<String, String, Integer> universityCourseSeatTable
= ImmutableTable.<String, String, Integer> builder().put("Mumbai", "Chemical", 120).build();
1) 검색
universityCourseSeatTable.put("Mumbai", "Chemical", 120);
int seatCount = universityCourseSeatTable.get("Mumbai", "Chemical"); //120
2) 항목 있는지 확인
universityCourseSeatTable.put("Mumbai", "Chemical", 120);
boolean entryIsPresent = universityCourseSeatTable.contains("Mumbai", "Chemical"); //true
boolean courseIsPresent = universityCourseSeatTable.containsColumn("IT"); //false
boolean universityIsPresent = universityCourseSeatTable.containsRow("Mumbai"); //true
boolean seatCountIsPresent = universityCourseSeatTable.containsValue(60); //false
3) 제거
universityCourseSeatTable.put("Mumbai", "Chemical", 120);
int seatCount = universityCourseSeatTable.remove("Mumbai", "Chemical"); //120
4) 행 기준으로 셀값 맵
universityCourseSeatTable.put("Mumbai", "IT", 60);
universityCourseSeatTable.put("Havard", "IT", 120);
universityCourseSeatTable.put("Mumbai", "Chemical", 120);
Map<String, Integer> universitySeatMap = universityCourseSeatTable.column("IT");
/*
IT 기준으로 맵으로 만들어짐
"Mumbai", 60
"Havard", 120
*/
Map<String, Map<String, Integer>> courseKeyUniversitySeatMap = universityCourseSeatTable.columnMap();
/* 행 기준으로 만들어짐
"IT", <"Mumbai", 60>
"IT", <"Havard", 120>
"Chemical", <"Mumbai",120>
*/
5) 열 기준으로 셀값 맵
universityCourseSeatTable.put("Mumbai", "IT", 60);
universityCourseSeatTable.put("Havard", "IT", 120);
universityCourseSeatTable.put("Mumbai", "Chemical", 120);
Map<String, Integer> courseSeatMap = universityCourseSeatTable.row("Mumbai");
/*
Mumbai 기준으로 만들어짐
"IT", 60
"Chemical", 120
*/
6) 키 가져오기
universityCourseSeatTable.put("Mumbai", "Chemical", 120);
universityCourseSeatTable.put("Mumbai", "IT", 60);
universityCourseSeatTable.put("Harvard", "Electrical", 60);
universityCourseSeatTable.put("Harvard", "IT", 120);
//행 키 : Mumbai , Harvard
Set<String> universitySet = universityCourseSeatTable.rowKeySet();
//열 키 : Chemical, IT, Electrical
Set<String> courseSet = universityCourseSeatTable.columnKeySet();