Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 9x 9x 1x 1x 1x 1x 1x 1x 1x 1x 25x 25x 188x 188x 1x 1x 1x 141x 141x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 239x 239x 19x 19x 220x 220x 239x 239x 239x 11x 11x 228x 228x 228x 228x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 6x 6x 2x 1x 1x 1x 2x 1x 1x 1x | CLASS zcl_abapgit_string_map DEFINITION PUBLIC FINAL CREATE PUBLIC . PUBLIC SECTION. TYPES: BEGIN OF ty_entry, k TYPE string, v TYPE string, END OF ty_entry . TYPES: ty_entries TYPE SORTED TABLE OF ty_entry WITH UNIQUE KEY k . DATA mt_entries TYPE ty_entries READ-ONLY . CLASS-METHODS create IMPORTING !iv_case_insensitive TYPE abap_bool DEFAULT abap_false RETURNING VALUE(ro_instance) TYPE REF TO zcl_abapgit_string_map . METHODS constructor IMPORTING !iv_case_insensitive TYPE abap_bool DEFAULT abap_false . METHODS get IMPORTING !iv_key TYPE string RETURNING VALUE(rv_val) TYPE string . METHODS has IMPORTING !iv_key TYPE string RETURNING VALUE(rv_has) TYPE abap_bool . METHODS set IMPORTING !iv_key TYPE string !iv_val TYPE csequence OPTIONAL RETURNING VALUE(ro_map) TYPE REF TO zcl_abapgit_string_map RAISING zcx_abapgit_exception . METHODS size RETURNING VALUE(rv_size) TYPE i . METHODS is_empty RETURNING VALUE(rv_yes) TYPE abap_bool . METHODS delete IMPORTING !iv_key TYPE string RAISING zcx_abapgit_exception . METHODS clear RAISING zcx_abapgit_exception . METHODS to_abap CHANGING !cs_container TYPE any RAISING zcx_abapgit_exception . METHODS strict IMPORTING !iv_strict TYPE abap_bool DEFAULT abap_true RETURNING VALUE(ro_instance) TYPE REF TO zcl_abapgit_string_map . METHODS freeze . METHODS merge IMPORTING !io_string_map TYPE REF TO zcl_abapgit_string_map RETURNING VALUE(ro_instance) TYPE REF TO zcl_abapgit_string_map RAISING zcx_abapgit_exception . PROTECTED SECTION. PRIVATE SECTION. DATA mv_read_only TYPE abap_bool. DATA mv_is_strict TYPE abap_bool. DATA mv_case_insensitive TYPE abap_bool. ENDCLASS. CLASS ZCL_ABAPGIT_STRING_MAP IMPLEMENTATION. METHOD clear. IF mv_read_only = abap_true. zcx_abapgit_exception=>raise( 'Cannot clear. This string map is immutable' ). ENDIF. CLEAR mt_entries. ENDMETHOD. METHOD constructor. mv_is_strict = abap_true. mv_case_insensitive = iv_case_insensitive. ENDMETHOD. METHOD create. CREATE OBJECT ro_instance EXPORTING iv_case_insensitive = iv_case_insensitive. ENDMETHOD. METHOD delete. IF mv_read_only = abap_true. zcx_abapgit_exception=>raise( 'Cannot delete. This string map is immutable' ). ENDIF. DELETE mt_entries WHERE k = iv_key. ENDMETHOD. METHOD freeze. mv_read_only = abap_true. ENDMETHOD. METHOD get. DATA lv_key LIKE iv_key. FIELD-SYMBOLS <ls_entry> LIKE LINE OF mt_entries. IF mv_case_insensitive = abap_true. lv_key = to_upper( iv_key ). ELSE. lv_key = iv_key. ENDIF. READ TABLE mt_entries ASSIGNING <ls_entry> WITH KEY k = lv_key. IF sy-subrc IS INITIAL. rv_val = <ls_entry>-v. ENDIF. ENDMETHOD. METHOD has. READ TABLE mt_entries TRANSPORTING NO FIELDS WITH KEY k = iv_key. rv_has = boolc( sy-subrc IS INITIAL ). ENDMETHOD. METHOD is_empty. rv_yes = boolc( lines( mt_entries ) = 0 ). ENDMETHOD. METHOD merge. FIELD-SYMBOLS <ls_entry> LIKE LINE OF mt_entries. LOOP AT io_string_map->mt_entries ASSIGNING <ls_entry>. set( iv_key = <ls_entry>-k iv_val = <ls_entry>-v ). ENDLOOP. ro_instance = me. ENDMETHOD. METHOD set. DATA lv_key LIKE iv_key. DATA ls_entry LIKE LINE OF mt_entries. FIELD-SYMBOLS <ls_entry> LIKE LINE OF mt_entries. IF mv_read_only = abap_true. zcx_abapgit_exception=>raise( 'Cannot set. This string map is immutable' ). ENDIF. IF mv_case_insensitive = abap_true. lv_key = to_upper( iv_key ). ELSE. lv_key = iv_key. ENDIF. READ TABLE mt_entries ASSIGNING <ls_entry> WITH KEY k = lv_key. IF sy-subrc IS INITIAL. <ls_entry>-v = iv_val. ELSE. ls_entry-k = lv_key. ls_entry-v = iv_val. INSERT ls_entry INTO TABLE mt_entries. ENDIF. ro_map = me. ENDMETHOD. METHOD size. rv_size = lines( mt_entries ). ENDMETHOD. METHOD strict. mv_is_strict = iv_strict. ro_instance = me. ENDMETHOD. METHOD to_abap. DATA lo_type TYPE REF TO cl_abap_typedescr. DATA lv_field TYPE string. FIELD-SYMBOLS <ls_entry> LIKE LINE OF mt_entries. FIELD-SYMBOLS <lv_val> TYPE any. lo_type = cl_abap_typedescr=>describe_by_data( cs_container ). IF lo_type->type_kind <> cl_abap_typedescr=>typekind_struct1 AND lo_type->type_kind <> cl_abap_typedescr=>typekind_struct2. zcx_abapgit_exception=>raise( 'Only structures supported' ). ENDIF. LOOP AT mt_entries ASSIGNING <ls_entry>. lv_field = to_upper( <ls_entry>-k ). ASSIGN COMPONENT lv_field OF STRUCTURE cs_container TO <lv_val>. IF sy-subrc = 0. " TODO check target type ? <lv_val> = <ls_entry>-v. ELSEIF mv_is_strict = abap_false. CONTINUE. ELSE. zcx_abapgit_exception=>raise( |Component { lv_field } not found in target| ). ENDIF. ENDLOOP. ENDMETHOD. ENDCLASS. |