@@ -858,6 +858,12 @@ public Optional<O> findOptionByKey(String key) {
858
858
.findFirst ();
859
859
}
860
860
861
+ private Optional <AbstractMenuItem <T >> findMenuItemByKey (String key ) {
862
+ return optionsMenu .getFlatMenuItems ().stream ()
863
+ .filter (menuItem -> Objects .equals (key , menuItem .getKey ()))
864
+ .findFirst ();
865
+ }
866
+
861
867
/**
862
868
* Searches for an option by its value within the select component.
863
869
*
@@ -872,6 +878,12 @@ public Optional<O> findOptionByValue(T value) {
872
878
.findFirst ();
873
879
}
874
880
881
+ private Optional <AbstractMenuItem <T >> findMenuItemByValue (T value ) {
882
+ return optionsMenu .getFlatMenuItems ().stream ()
883
+ .filter (menuItem -> Objects .equals (value , menuItem .getValue ()))
884
+ .findFirst ();
885
+ }
886
+
875
887
/**
876
888
* Searches for an option by its index within the select component.
877
889
*
@@ -880,9 +892,12 @@ public Optional<O> findOptionByValue(T value) {
880
892
* found.
881
893
*/
882
894
public Optional <O > findOptionByIndex (int index ) {
895
+ return findMenuItemByIndex (index ).map (item -> OptionMeta .<T , E , O >get (item ).get ().getOption ());
896
+ }
897
+
898
+ private Optional <AbstractMenuItem <T >> findMenuItemByIndex (int index ) {
883
899
if (index < optionsMenu .getFlatMenuItems ().size () && index >= 0 ) {
884
- AbstractMenuItem <T > menuItem = optionsMenu .getFlatMenuItems ().get (index );
885
- return Optional .ofNullable (OptionMeta .<T , E , O >get (menuItem ).get ().getOption ());
900
+ return Optional .ofNullable (optionsMenu .getFlatMenuItems ().get (index ));
886
901
}
887
902
return Optional .empty ();
888
903
}
@@ -1001,7 +1016,7 @@ public C deselectAt(int index) {
1001
1016
* @return an instance of the concrete class.
1002
1017
*/
1003
1018
public C deselectAt (int index , boolean silent ) {
1004
- findOptionByIndex (index ).ifPresent (o -> onOptionDeselected ( o , silent ));
1019
+ findMenuItemByIndex (index ).ifPresent (item -> item . deselect ( silent ));
1005
1020
return (C ) this ;
1006
1021
}
1007
1022
@@ -1026,7 +1041,7 @@ public C deselectByKey(String key) {
1026
1041
* @return an instance of the concrete class.
1027
1042
*/
1028
1043
public C deselectByKey (String key , boolean silent ) {
1029
- findOptionByKey (key ).ifPresent (o -> onOptionDeselected ( o , silent ));
1044
+ findMenuItemByKey (key ).ifPresent (item -> item . deselect ( silent ));
1030
1045
return (C ) this ;
1031
1046
}
1032
1047
@@ -1050,7 +1065,7 @@ public C deselectByValue(T value) {
1050
1065
* @return an instance of the concrete class.
1051
1066
*/
1052
1067
public C deselectByValue (T value , boolean silent ) {
1053
- findOptionByValue (value ).ifPresent (o -> onOptionDeselected ( o , silent ));
1068
+ findMenuItemByValue (value ).ifPresent (item -> item . deselect ( silent ));
1054
1069
return (C ) this ;
1055
1070
}
1056
1071
0 commit comments