99import java .util .List ;
1010import java .util .Map ;
1111import java .util .Set ;
12+ import java .util .stream .Collectors ;
1213import javax .swing .JTable ;
1314import javax .swing .table .DefaultTableCellRenderer ;
1415import javax .swing .table .DefaultTableModel ;
@@ -22,9 +23,10 @@ public class IndexedTable extends DefaultTableModel {
2223
2324 public static final IndexGenerator DEFAULT_GENERATOR = new IndexGenerator ();
2425
26+ protected Map <String ,Integer > entryMap = new LinkedHashMap <>();
27+ protected Map <String ,String > entryTypes = new LinkedHashMap <>();
28+
2529 private IndexedList <IndexedEntry > entries = null ;
26- private Map <String ,Integer > entryMap = new LinkedHashMap <>();
27- private Map <String ,String > entryTypes = new LinkedHashMap <>();
2830 private List <String > entryNames = new ArrayList <>();
2931 private List <String > indexNames = new ArrayList <>();
3032 private String precisionFormat = "%.6f" ;
@@ -119,7 +121,7 @@ public void setIntValue(Integer value, String item, int... index){
119121 }
120122 }
121123 }
122-
124+
123125 public void setDoubleValue (Double value , String item , int ... index ){
124126 if (this .entries .hasItem (index )==false ){
125127 if (DEBUG_MODE >0 ) System .out .println ( "[IndexedTable] ---> error.. entry does not exist" );
@@ -133,38 +135,6 @@ public void setDoubleValue(Double value, String item, int... index){
133135 }
134136 }
135137
136- public int getIntValueByHash (int index , long hash ) {
137- if (this .entries .hasItemByHash (hash ))
138- return this .entries .getItemByHash (hash ).getValue (index ).intValue ();
139- return 0 ;
140- }
141-
142- public double getDoubleValueByHash (int index , long hash ) {
143- if (this .entries .hasItemByHash (hash ))
144- return this .entries .getItemByHash (hash ).getValue (index ).doubleValue ();
145- return 0 ;
146- }
147-
148- public int getIntValueByHash (String item , long hash ) {
149- if (this .entries .hasItemByHash (hash )) {
150- if (this .entryMap .containsKey (item )) {
151- int index = this .entryMap .get (item );
152- return this .entries .getItemByHash (hash ).getValue (index ).intValue ();
153- }
154- }
155- return 0 ;
156- }
157-
158- public double getDoubleValueByHash (String item , long hash ) {
159- if (this .entries .hasItemByHash (hash )) {
160- if (this .entryMap .containsKey (item )) {
161- int index = this .entryMap .get (item );
162- return this .entries .getItemByHash (hash ).getValue (index ).doubleValue ();
163- }
164- }
165- return 0 ;
166- }
167-
168138 public int getIntValue (String item , int ... index ){
169139 if (this .entries .hasItem (index )==false ){
170140 if (DEBUG_MODE >0 ) System .out .println ( "[IndexedTable] ---> error.. entry does not exist" );
@@ -193,14 +163,50 @@ public double getDoubleValue(String item, int... index){
193163 return 0 ;
194164 }
195165
166+ public void setIntValueByHash (Integer value , int column , long hash ) {
167+ this .entries .getItemByHash (hash ).setValue (column , value );
168+ }
169+
170+ public int getIntValueByHash (int index , long hash ) {
171+ return entries .getItemByHash (hash ).getValue (index ).intValue ();
172+ }
173+
174+ public double getDoubleValueByHash (int index , long hash ) {
175+ return entries .getItemByHash (hash ).getValue (index ).doubleValue ();
176+ }
177+
178+ public int getIntValueByHash (String item , long hash ) {
179+ return entries .getItemByHash (hash ).getValue (entryMap .get (item )).intValue ();
180+ }
181+
182+ public double getDoubleValueByHash (String item , long hash ) {
183+ return entries .getItemByHash (hash ).getValue (entryMap .get (item )).doubleValue ();
184+ }
185+
186+ public List <Number > getValuesByHash (long hash ) {
187+ return this .entries .getItemByHash (hash ).entryValues ;
188+ }
189+
190+ public List <Integer > getIntegersByHash (long hash ) {
191+ return getValuesByHash (hash ).stream ().map (x -> x .intValue ()).collect (Collectors .toList ());
192+ }
193+
194+ public List <Double > getDoublesByHash (long hash ) {
195+ return getValuesByHash (hash ).stream ().map (x -> x .doubleValue ()).collect (Collectors .toList ());
196+ }
197+
196198 public NamedEntry getNamedEntry (int ... index ) {
197199 return NamedEntry .create (entries .getItem (index ), entryNames , index );
198200 }
199201
200202 public IndexedList getList (){
201203 return this .entries ;
202204 }
203-
205+
206+ public Map <String ,Integer > getEntryMap (){
207+ return this .entryMap ;
208+ }
209+
204210 private void parseFormat (String format ){
205211 String [] tokens = format .split (":" );
206212 entryMap .clear ();
0 commit comments