11package com .comphenix .rema1000 .io ;
22
3- import com .google .common .collect .BiMap ;
4- import com .google .common .collect .HashBiMap ;
5-
63import java .io .IOException ;
7- import java .util .Collections ;
8- import java .util .Objects ;
9- import java .util .Set ;
4+ import java .util .*;
105
116public abstract class AbstractTableWriter implements TableWriter {
127 // Index of the current column (initially -1)
138 private int columnIndex = -1 ;
14- protected BiMap <String , Integer > headerLookup = HashBiMap .create ();
9+ protected Map <String , Integer > headerIndexLookup = new HashMap <>();
10+ protected Map <Integer , String > headerNameLookup = new HashMap <>();
1511
1612 protected boolean closed ;
1713
1814 @ Override
1915 public int getHeaderIndex (String header ) {
20- return headerLookup .getOrDefault (header , -1 );
16+ return headerIndexLookup .getOrDefault (header , -1 );
2117 }
2218
2319 @ Override
2420 public String getHeaderName (int index ) {
25- return headerLookup . inverse () .get (index );
21+ return headerNameLookup .get (index );
2622 }
2723
2824 @ Override
@@ -32,19 +28,20 @@ public int getHeaderCount() {
3228
3329 @ Override
3430 public Set <String > headers () {
35- return Collections .unmodifiableSet (headerLookup .keySet ());
31+ return Collections .unmodifiableSet (headerIndexLookup .keySet ());
3632 }
3733
3834 @ Override
3935 public int createHeader (String headerName ) throws IOException {
4036 checkClosed ();
41- Integer existing = headerLookup .get (headerName );
37+ Integer existing = headerIndexLookup .get (headerName );
4238
4339 if (existing == null ) {
4440 int column = ++columnIndex ;
4541
4642 onHeaderCreated (headerName , column );
47- headerLookup .put (headerName , column );
43+ headerIndexLookup .put (headerName , column );
44+ headerNameLookup .put (column , headerName );
4845 return column ;
4946 }
5047 return existing ;
0 commit comments