gitlab.com/evatix-go/core@v1.3.55/keymk/KeyWithLegend.go (about)

     1  package keymk
     2  
     3  import (
     4  	"fmt"
     5  	"strconv"
     6  	"strings"
     7  
     8  	"gitlab.com/evatix-go/core/constants"
     9  	"gitlab.com/evatix-go/core/coreinterface/enuminf"
    10  )
    11  
    12  // KeyWithLegend
    13  //
    14  // Chain Sequence
    15  //  (Root-Package-Group-State-User-item) aka. LegendChainSample
    16  //  fixed chain (Root-Package) and variable chain (Group-State-User-item)
    17  //
    18  //  Chain example LegendChainSample
    19  //
    20  //  Depending on Options
    21  //  -   IsIgnoreLegendAttachments() calls or invokes -> OutputWithoutLegend()
    22  //  -   or else - calls compiles using legends
    23  //
    24  //  Chain may look like (Fixed chain "{root}-{package}"):
    25  //   - root-package-group-state-user-item (LegendChainSample)
    26  //   - Fixed chain "{root}-{package}" -- rest will depend on value given on parameter.
    27  //      - Given request to item will only print
    28  //          - "{root}-{package}-{item}"
    29  //      - Given request to state, item will only print
    30  //          - "{root}-{package}-{state}-{item}"
    31  //      - Given request to group will only print
    32  //          - "{root}-{package}-{group}"
    33  //
    34  // Ordering :
    35  //  - Root
    36  //  - Package
    37  //  - Group
    38  //  - State
    39  //  - User
    40  //  - ItemWithoutUser
    41  //
    42  // Example:
    43  //  - On any value empty in request will be
    44  //    ignored if Option.IsSkipEmptyEntry
    45  //
    46  // Conditions apply:
    47  //  - if Option.IsSkipEmptyEntry then empty input wil be ignored.
    48  type KeyWithLegend struct {
    49  	option                *Option
    50  	LegendName            LegendName
    51  	isAttachLegendNames   bool
    52  	rootName, packageName string
    53  	stateName, groupName  string
    54  }
    55  
    56  func (it *KeyWithLegend) IsIgnoreLegendAttachments() bool {
    57  	return !it.isAttachLegendNames
    58  }
    59  
    60  func (it *KeyWithLegend) RootName() string {
    61  	return it.rootName
    62  }
    63  
    64  func (it *KeyWithLegend) PackageName() string {
    65  	return it.packageName
    66  }
    67  
    68  func (it *KeyWithLegend) GroupName() string {
    69  	return it.groupName
    70  }
    71  
    72  func (it *KeyWithLegend) StateName() string {
    73  	return it.stateName
    74  }
    75  
    76  // OutputItemsArray
    77  //
    78  //  Chain example LegendChainSample
    79  //
    80  //  Depending on Options
    81  //  -   IsIgnoreLegendAttachments() calls or invokes -> OutputWithoutLegend()
    82  //  -   or else - calls compiles using legends
    83  //
    84  //  Chain may look like:
    85  //      - root-package-group-state-user-item (LegendChainSample)
    86  //
    87  // Ordering :
    88  //  - Root
    89  //  - Package
    90  //  - Group
    91  //  - State
    92  //  - User
    93  //  - ItemWithoutUser
    94  //
    95  // Example:
    96  //  - On any value empty in request will be
    97  //    ignored if Option.IsSkipEmptyEntry
    98  //
    99  // Conditions apply:
   100  //  - if Option.IsSkipEmptyEntry then empty input wil be ignored.
   101  func (it *KeyWithLegend) OutputItemsArray(request KeyLegendCompileRequest) []string {
   102  	if it.IsIgnoreLegendAttachments() {
   103  		return it.OutputWithoutLegend(request)
   104  	}
   105  
   106  	slice := make(
   107  		[]string,
   108  		0,
   109  		constants.ArbitraryCapacity14)
   110  
   111  	isAddRegardless := it.
   112  		option.
   113  		IsAddEntryRegardlessOfEmptiness()
   114  
   115  	slice = it.appendLegendNameValue(
   116  		isAddRegardless,
   117  		slice,
   118  		it.LegendName.Root,
   119  		it.rootName)
   120  
   121  	slice = it.appendLegendNameValue(
   122  		isAddRegardless,
   123  		slice,
   124  		it.LegendName.Package,
   125  		it.packageName)
   126  
   127  	slice = it.appendLegendNameValue(
   128  		isAddRegardless,
   129  		slice,
   130  		it.LegendName.Group,
   131  		request.GroupId)
   132  
   133  	slice = it.appendLegendNameValue(
   134  		isAddRegardless,
   135  		slice,
   136  		it.LegendName.State,
   137  		request.StateName)
   138  
   139  	slice = it.appendLegendNameValue(
   140  		isAddRegardless,
   141  		slice,
   142  		it.LegendName.User,
   143  		request.UserId)
   144  
   145  	slice = it.appendLegendNameValue(
   146  		isAddRegardless,
   147  		slice,
   148  		it.LegendName.Item,
   149  		request.ItemId)
   150  
   151  	return slice
   152  }
   153  
   154  func (it *KeyWithLegend) appendLegendNameValue(
   155  	isAddRegardless bool,
   156  	list []string,
   157  	legendName,
   158  	valueId string,
   159  ) []string {
   160  	if isAddRegardless || valueId != "" {
   161  		return append(
   162  			list,
   163  			legendName,
   164  			valueId)
   165  	}
   166  
   167  	return list
   168  }
   169  
   170  // Group
   171  //
   172  //  Returns up to state.
   173  //  Chain sample KeyWithLegend, LegendChainSample
   174  //
   175  //  State will be used from creation.
   176  //
   177  // Example:
   178  //  - "{root}-{package}-{group}-{state}"
   179  //
   180  // Missing:
   181  //  - "{user}-{item}"
   182  //
   183  // Conditions apply:
   184  //  - if Option.IsSkipEmptyEntry then empty input wil be ignored.
   185  func (it *KeyWithLegend) Group(group interface{}) string {
   186  	request := KeyLegendCompileRequest{
   187  		StateName: it.stateName,
   188  		GroupId: fmt.Sprintf(
   189  			constants.SprintValueFormat,
   190  			group),
   191  	}
   192  
   193  	return it.CompileUsingRequest(request)
   194  }
   195  
   196  // GroupString
   197  //
   198  //  Returns up to state.
   199  //  Chain sample KeyWithLegend, LegendChainSample
   200  //
   201  //  State will be used from creation.
   202  //
   203  // Example:
   204  //  - "{root}-{package}-{group}-{state}"
   205  //
   206  // Missing:
   207  //  - "{user}-{item}"
   208  //
   209  // Conditions apply:
   210  //  - if Option.IsSkipEmptyEntry then empty input wil be ignored.
   211  func (it *KeyWithLegend) GroupString(group string) string {
   212  	request := KeyLegendCompileRequest{
   213  		StateName: it.stateName,
   214  		GroupId:   group,
   215  	}
   216  
   217  	return it.CompileUsingRequest(request)
   218  }
   219  
   220  // UpToGroup
   221  //
   222  //  Returns up to group without states
   223  //  Chain sample KeyWithLegend, LegendChainSample
   224  //
   225  //  State will be used from creation.
   226  //
   227  // Example:
   228  //  - "{root}-{package}-{group}"
   229  //
   230  // Missing:
   231  //  - "{state}-{user}-{item}"
   232  //
   233  // Conditions apply:
   234  //  - if Option.IsSkipEmptyEntry then empty input wil be ignored.
   235  func (it *KeyWithLegend) UpToGroup(group interface{}) string {
   236  	request := KeyLegendCompileRequest{
   237  		GroupId: fmt.Sprintf(constants.SprintValueFormat, group),
   238  	}
   239  
   240  	return it.CompileUsingRequest(request)
   241  }
   242  
   243  // UpToGroupString
   244  //
   245  //  Returns up to group without states
   246  //  Chain sample KeyWithLegend, LegendChainSample
   247  //
   248  //  State will be used from creation.
   249  //
   250  // Example:
   251  //  - "{root}-{package}-{group}"
   252  //
   253  // Missing:
   254  //  - "{state}-{user}-{item}"
   255  //
   256  // Conditions apply:
   257  //  - if Option.IsSkipEmptyEntry then empty input wil be ignored.
   258  func (it *KeyWithLegend) UpToGroupString(group string) string {
   259  	request := KeyLegendCompileRequest{
   260  		GroupId: group,
   261  	}
   262  
   263  	return it.CompileUsingRequest(request)
   264  }
   265  
   266  // ItemWithoutUser
   267  //
   268  //  Returns up to item without user.
   269  //  Chain sample KeyWithLegend, LegendChainSample
   270  //
   271  //  State, Group will be used from creation.
   272  //
   273  // Example:
   274  //  - "{root}-{package}-{state}-{group}-{item}"
   275  //
   276  // Missing:
   277  //  - "{user}"
   278  //
   279  // Conditions apply:
   280  //  - if Option.IsSkipEmptyEntry then empty input wil be ignored.
   281  func (it *KeyWithLegend) ItemWithoutUser(item interface{}) string {
   282  	request := KeyLegendCompileRequest{
   283  		StateName: it.stateName,
   284  		GroupId:   it.groupName,
   285  		ItemId:    fmt.Sprintf(constants.SprintValueFormat, item),
   286  	}
   287  
   288  	return it.CompileUsingRequest(request)
   289  }
   290  
   291  // ItemWithoutUserGroup
   292  //
   293  //  Returns up to item without user, group.
   294  //  Chain sample KeyWithLegend, LegendChainSample
   295  //
   296  //  State will be used from creation.
   297  //
   298  // Example:
   299  //  - "{root}-{package}-{state}-{item}"
   300  //
   301  // Missing:
   302  //  - "{group}-{user}"
   303  //
   304  // Conditions apply:
   305  //  - if Option.IsSkipEmptyEntry then empty input wil be ignored.
   306  func (it *KeyWithLegend) ItemWithoutUserGroup(item interface{}) string {
   307  	request := KeyLegendCompileRequest{
   308  		StateName: it.stateName,
   309  		ItemId:    fmt.Sprintf(constants.SprintValueFormat, item),
   310  	}
   311  
   312  	return it.CompileUsingRequest(request)
   313  }
   314  
   315  // ItemWithoutUserStateGroup
   316  //
   317  //  Returns up to item without user, group, state.
   318  //  Chain sample KeyWithLegend, LegendChainSample
   319  //
   320  //  Nothing will be used from creation.
   321  //
   322  // Example:
   323  //  - "{root}-{package}-{item}"
   324  //
   325  // Missing:
   326  //  - "{group}-{state}-{user}"
   327  //
   328  // Conditions apply:
   329  //  - if Option.IsSkipEmptyEntry then empty input wil be ignored.
   330  func (it *KeyWithLegend) ItemWithoutUserStateGroup(item interface{}) string {
   331  	request := KeyLegendCompileRequest{
   332  		ItemId: fmt.Sprintf(constants.SprintValueFormat, item),
   333  	}
   334  
   335  	return it.CompileUsingRequest(request)
   336  }
   337  
   338  // ItemEnumByte
   339  //
   340  //  Returns up to item without user.
   341  //  Chain sample KeyWithLegend, LegendChainSample
   342  //
   343  //  Group, State will be used from creation.
   344  //
   345  // Example:
   346  //  - "{root}-{package}-{state}-{group}-{item}"
   347  //
   348  // Missing:
   349  //  - "{user}"
   350  //
   351  // Conditions apply:
   352  //  - if Option.IsSkipEmptyEntry then empty input wil be ignored.
   353  func (it *KeyWithLegend) ItemEnumByte(item enuminf.ByteEnumNamer) string {
   354  	request := KeyLegendCompileRequest{
   355  		StateName: it.stateName,
   356  		GroupId:   it.groupName,
   357  		ItemId: fmt.Sprintf(
   358  			constants.SprintValueFormat,
   359  			item),
   360  	}
   361  
   362  	return it.CompileUsingRequest(request)
   363  }
   364  
   365  // Item
   366  //
   367  //  Returns up to item without user.
   368  //  Chain sample KeyWithLegend, LegendChainSample
   369  //
   370  //  State, Group will be used from creation.
   371  //
   372  // Example:
   373  //  - "{root}-{package}-{state}-{group}-{item}"
   374  //
   375  // Missing:
   376  //  - "{user}"
   377  //
   378  // Conditions apply:
   379  //  - if Option.IsSkipEmptyEntry then empty input wil be ignored.
   380  func (it *KeyWithLegend) Item(item interface{}) string {
   381  	request := KeyLegendCompileRequest{
   382  		StateName: it.stateName,
   383  		GroupId:   it.groupName,
   384  		ItemId: fmt.Sprintf(
   385  			constants.SprintValueFormat,
   386  			item),
   387  	}
   388  
   389  	return it.CompileUsingRequest(request)
   390  }
   391  
   392  // ItemString
   393  //
   394  //  Returns up to item without user, group, state.
   395  //  Chain sample KeyWithLegend, LegendChainSample
   396  //
   397  //  State, Group will be used from creation.
   398  //
   399  // Example:
   400  //  - "{root}-{package}-{state}-{group}-{item}"
   401  //
   402  // Missing:
   403  //  - "{user}"
   404  //
   405  // Conditions apply:
   406  //  - if Option.IsSkipEmptyEntry then empty input wil be ignored.
   407  func (it *KeyWithLegend) ItemString(item string) string {
   408  	request := KeyLegendCompileRequest{
   409  		StateName: it.stateName,
   410  		GroupId:   it.groupName,
   411  		ItemId:    item,
   412  	}
   413  
   414  	return it.CompileUsingRequest(request)
   415  }
   416  
   417  // ItemInt
   418  //
   419  //  Returns up to item without user.
   420  //  Chain sample KeyWithLegend, LegendChainSample
   421  //
   422  //  State, Group will be used from creation.
   423  //
   424  // Example:
   425  //  - "{root}-{package}-{state}-{group}-{item}"
   426  //
   427  // Missing:
   428  //  - "{user}"
   429  //
   430  // Conditions apply:
   431  //  - if Option.IsSkipEmptyEntry then empty input wil be ignored.
   432  func (it *KeyWithLegend) ItemInt(itemId int) string {
   433  	return it.Item(itemId)
   434  }
   435  
   436  // ItemUInt
   437  //
   438  //  Returns up to item without user.
   439  //  Chain sample KeyWithLegend, LegendChainSample
   440  //
   441  //  State, Group will be used from creation.
   442  //
   443  // Example:
   444  //  - "{root}-{package}-{state}-{group}-{item}"
   445  //
   446  // Missing:
   447  //  - "{user}"
   448  //
   449  // Conditions apply:
   450  //  - if Option.IsSkipEmptyEntry then empty input wil be ignored.
   451  func (it *KeyWithLegend) ItemUInt(itemId uint) string {
   452  	return it.Item(itemId)
   453  }
   454  
   455  // GroupItemIntRange
   456  //
   457  //  Returns up to item without user.
   458  //  Chain sample KeyWithLegend, LegendChainSample
   459  //
   460  //  State, Group will be used from creation.
   461  //
   462  // Example:
   463  //  - "{root}-{package}-{state}-{group}-{item}"
   464  //
   465  // Missing:
   466  //  - "{user}"
   467  //
   468  // Conditions apply:
   469  //  - if Option.IsSkipEmptyEntry then empty input wil be ignored.
   470  func (it *KeyWithLegend) GroupItemIntRange(group string, startId, endId int) []string {
   471  	ids := make([]string, 0, (endId-startId)+constants.Capacity3)
   472  
   473  	for i := startId; i <= endId; i++ {
   474  		ids = append(ids, it.GroupItemString(group, strconv.Itoa(i)))
   475  	}
   476  
   477  	return ids
   478  }
   479  
   480  // UserStringWithoutState
   481  //
   482  //  Returns up to user without state.
   483  //  Chain sample KeyWithLegend, LegendChainSample
   484  //
   485  //  Group will be used from creation.
   486  //
   487  // Example:
   488  //  - "{root}-{package}-{group}--{user}"
   489  //
   490  // Missing:
   491  //  - "{state}-{item}"
   492  //
   493  // Conditions apply:
   494  //  - if Option.IsSkipEmptyEntry then empty input wil be ignored.
   495  func (it *KeyWithLegend) UserStringWithoutState(user string) string {
   496  	request := KeyLegendCompileRequest{
   497  		GroupId: it.groupName,
   498  		UserId:  user,
   499  	}
   500  
   501  	return it.CompileUsingRequest(request)
   502  }
   503  
   504  // UpToState
   505  //
   506  //  Returns up to state.
   507  //  Chain sample KeyWithLegend, LegendChainSample
   508  //
   509  //  State, Group will be used from creation.
   510  //
   511  // Example:
   512  //  - "{root}-{package}-{group}-{state}"
   513  //
   514  // Missing:
   515  //  - "{user}-{item}"
   516  //
   517  // Conditions apply:
   518  //  - if Option.IsSkipEmptyEntry then empty input wil be ignored.
   519  func (it *KeyWithLegend) UpToState(
   520  	user string,
   521  ) string {
   522  	request := KeyLegendCompileRequest{
   523  		StateName: it.stateName,
   524  		UserId:    user,
   525  		GroupId:   it.groupName,
   526  	}
   527  
   528  	return it.CompileUsingRequest(request)
   529  }
   530  
   531  func (it *KeyWithLegend) GroupIntRange(
   532  	startId, endId int,
   533  ) []string {
   534  	ids := make([]string, 0, (endId-startId)+constants.Capacity3)
   535  
   536  	for i := startId; i <= endId; i++ {
   537  		ids = append(ids, it.GroupString(strconv.Itoa(i)))
   538  	}
   539  
   540  	return ids
   541  }
   542  
   543  func (it *KeyWithLegend) GroupUIntRange(
   544  	startId, endId uint,
   545  ) []string {
   546  	ids := make([]string, 0, (endId-startId)+constants.Capacity3)
   547  
   548  	for i := startId; i <= endId; i++ {
   549  		ids = append(ids, it.Group(i))
   550  	}
   551  
   552  	return ids
   553  }
   554  
   555  func (it *KeyWithLegend) ItemIntRange(
   556  	startId, endId int,
   557  ) []string {
   558  	ids := make([]string, 0, (endId-startId)+constants.Capacity3)
   559  
   560  	for i := startId; i <= endId; i++ {
   561  		ids = append(ids, it.ItemInt(i))
   562  	}
   563  
   564  	return ids
   565  }
   566  
   567  func (it *KeyWithLegend) ItemUIntRange(
   568  	startId, endId uint,
   569  ) []string {
   570  	ids := make([]string, 0, (endId-startId)+constants.Capacity3)
   571  
   572  	for i := startId; i <= endId; i++ {
   573  		ids = append(ids, it.ItemInt(int(i)))
   574  	}
   575  
   576  	return ids
   577  }
   578  
   579  func (it *KeyWithLegend) GroupUserString(
   580  	group, user string,
   581  ) string {
   582  	request := KeyLegendCompileRequest{
   583  		StateName: it.stateName,
   584  		UserId:    user,
   585  		GroupId:   group,
   586  	}
   587  
   588  	return it.CompileUsingRequest(request)
   589  }
   590  
   591  func (it *KeyWithLegend) GroupUser(
   592  	group, user interface{},
   593  ) string {
   594  	request := KeyLegendCompileRequest{
   595  		StateName: it.stateName,
   596  		UserId:    fmt.Sprintf(constants.SprintValueFormat, user),
   597  		GroupId:   fmt.Sprintf(constants.SprintValueFormat, group),
   598  	}
   599  
   600  	return it.CompileUsingRequest(request)
   601  }
   602  
   603  func (it *KeyWithLegend) GroupUInt(
   604  	group uint,
   605  ) string {
   606  	request := KeyLegendCompileRequest{
   607  		GroupId: fmt.Sprintf(constants.SprintValueFormat, group),
   608  	}
   609  
   610  	return it.CompileUsingRequest(request)
   611  }
   612  
   613  func (it *KeyWithLegend) GroupByte(
   614  	group byte,
   615  ) string {
   616  	request := KeyLegendCompileRequest{
   617  		GroupId: fmt.Sprintf(constants.SprintValueFormat, group),
   618  	}
   619  
   620  	return it.CompileUsingRequest(request)
   621  }
   622  
   623  func (it *KeyWithLegend) GroupUserByte(
   624  	group, user byte,
   625  ) string {
   626  	request := KeyLegendCompileRequest{
   627  		StateName: it.stateName,
   628  		GroupId:   fmt.Sprintf(constants.SprintValueFormat, group),
   629  		UserId:    fmt.Sprintf(constants.SprintValueFormat, user),
   630  	}
   631  
   632  	return it.CompileUsingRequest(request)
   633  }
   634  
   635  // GroupUserItem
   636  //
   637  //  Returns up to item.
   638  //  Chain sample KeyWithLegend, LegendChainSample
   639  //
   640  //  State will be used from creation.
   641  //
   642  // Example:
   643  //  - "{root}-{package}-{group}-{state}-{user}-{item}"
   644  //
   645  // Missing:
   646  //  - Nothing
   647  //
   648  // Conditions apply:
   649  //  - if Option.IsSkipEmptyEntry then empty input wil be ignored.
   650  func (it *KeyWithLegend) GroupUserItem(
   651  	group, user, item interface{},
   652  ) string {
   653  	request := KeyLegendCompileRequest{
   654  		StateName: it.stateName,
   655  		UserId:    fmt.Sprintf(constants.SprintValueFormat, user),
   656  		GroupId:   fmt.Sprintf(constants.SprintValueFormat, group),
   657  		ItemId:    fmt.Sprintf(constants.SprintValueFormat, item),
   658  	}
   659  
   660  	return it.CompileUsingRequest(request)
   661  }
   662  
   663  func (it *KeyWithLegend) GroupStateUserItem(
   664  	group, state, user, item interface{},
   665  ) string {
   666  	request := KeyLegendCompileRequest{
   667  		StateName: fmt.Sprintf(constants.SprintValueFormat, state),
   668  		UserId:    fmt.Sprintf(constants.SprintValueFormat, user),
   669  		GroupId:   fmt.Sprintf(constants.SprintValueFormat, group),
   670  		ItemId:    fmt.Sprintf(constants.SprintValueFormat, item),
   671  	}
   672  
   673  	return it.CompileUsingRequest(request)
   674  }
   675  
   676  // StateUserItem
   677  //
   678  //  Returns up to item.
   679  //  Chain sample KeyWithLegend, LegendChainSample
   680  //
   681  //  Group will be used from creation.
   682  //
   683  // Example:
   684  //  - "{root}-{package}-{group}-{state}-{user}-{item}"
   685  //
   686  // Missing:
   687  //  - Nothing
   688  //
   689  // Conditions apply:
   690  //  - if Option.IsSkipEmptyEntry then empty input wil be ignored.
   691  func (it *KeyWithLegend) StateUserItem(
   692  	state, user, item interface{},
   693  ) string {
   694  	request := KeyLegendCompileRequest{
   695  		StateName: fmt.Sprintf(constants.SprintValueFormat, state),
   696  		UserId:    fmt.Sprintf(constants.SprintValueFormat, user),
   697  		GroupId:   it.groupName,
   698  		ItemId:    fmt.Sprintf(constants.SprintValueFormat, item),
   699  	}
   700  
   701  	return it.CompileUsingRequest(request)
   702  }
   703  
   704  // StateUser
   705  //
   706  //  Returns up to user.
   707  //  Chain sample KeyWithLegend, LegendChainSample
   708  //
   709  //  Group will be used from creation.
   710  //
   711  // Example:
   712  //  - "{root}-{package}-{group}-{state}-{user}"
   713  //
   714  // Missing:
   715  //  - "{item}"
   716  //
   717  // Conditions apply:
   718  //  - if Option.IsSkipEmptyEntry then empty input wil be ignored.
   719  func (it *KeyWithLegend) StateUser(
   720  	state, user interface{},
   721  ) string {
   722  	request := KeyLegendCompileRequest{
   723  		StateName: fmt.Sprintf(constants.SprintValueFormat, state),
   724  		UserId:    fmt.Sprintf(constants.SprintValueFormat, user),
   725  		GroupId:   it.groupName,
   726  	}
   727  
   728  	return it.CompileUsingRequest(request)
   729  }
   730  
   731  func (it *KeyWithLegend) GroupStateUserItemString(
   732  	group, state, user, item string,
   733  ) string {
   734  	request := KeyLegendCompileRequest{
   735  		UserId:    user,
   736  		GroupId:   group,
   737  		ItemId:    item,
   738  		StateName: state,
   739  	}
   740  
   741  	return it.CompileUsingRequest(request)
   742  }
   743  
   744  func (it *KeyWithLegend) GroupUserItemString(
   745  	group, user, item string,
   746  ) string {
   747  	request := KeyLegendCompileRequest{
   748  		UserId:    user,
   749  		GroupId:   group,
   750  		ItemId:    item,
   751  		StateName: it.stateName,
   752  	}
   753  
   754  	return it.CompileUsingRequest(request)
   755  }
   756  
   757  func (it *KeyWithLegend) GroupUserItemUint(
   758  	group, user, item uint,
   759  ) string {
   760  	return it.GroupUserItem(user, group, item)
   761  }
   762  
   763  func (it *KeyWithLegend) GroupUserItemInt(
   764  	group, user, item int,
   765  ) string {
   766  	return it.GroupUserItem(user, group, item)
   767  }
   768  
   769  func (it *KeyWithLegend) GroupItem(
   770  	group, item interface{},
   771  ) string {
   772  	request := KeyLegendCompileRequest{
   773  		StateName: it.stateName,
   774  		GroupId:   fmt.Sprintf(constants.SprintValueFormat, group),
   775  		ItemId:    fmt.Sprintf(constants.SprintValueFormat, item),
   776  	}
   777  
   778  	return it.CompileUsingRequest(request)
   779  }
   780  
   781  func (it *KeyWithLegend) StateItem(
   782  	stateName, item interface{},
   783  ) string {
   784  	request := KeyLegendCompileRequest{
   785  		StateName: fmt.Sprintf(constants.SprintValueFormat, stateName),
   786  		ItemId:    fmt.Sprintf(constants.SprintValueFormat, item),
   787  	}
   788  
   789  	return it.CompileUsingRequest(request)
   790  }
   791  
   792  // GroupItemString
   793  //
   794  //  Returns up to item without user.
   795  //  Chain sample KeyWithLegend, LegendChainSample
   796  //
   797  //  State, Group will be used from creation.
   798  //
   799  // Example:
   800  //  - "{root}-{package}-{state}-{group}-{item}"
   801  //
   802  // Missing:
   803  //  - "{user}"
   804  //
   805  // Conditions apply:
   806  //  - if Option.IsSkipEmptyEntry then empty input wil be ignored.
   807  func (it *KeyWithLegend) GroupItemString(
   808  	group, item string,
   809  ) string {
   810  	request := KeyLegendCompileRequest{
   811  		StateName: it.stateName,
   812  		GroupId:   group,
   813  		ItemId:    item,
   814  	}
   815  
   816  	return it.CompileUsingRequest(request)
   817  }
   818  
   819  func (it *KeyWithLegend) GroupStateItemString(
   820  	group, stateName, item string,
   821  ) string {
   822  	request := KeyLegendCompileRequest{
   823  		GroupId:   group,
   824  		ItemId:    item,
   825  		StateName: stateName,
   826  	}
   827  
   828  	return it.CompileUsingRequest(request)
   829  }
   830  
   831  func (it *KeyWithLegend) StateItemString(
   832  	stateName, item string,
   833  ) string {
   834  	request := KeyLegendCompileRequest{
   835  		GroupId:   it.groupName,
   836  		ItemId:    item,
   837  		StateName: stateName,
   838  	}
   839  
   840  	return it.CompileUsingRequest(request)
   841  }
   842  
   843  func (it *KeyWithLegend) Compile(
   844  	itemId string,
   845  ) string {
   846  	return it.ItemString(itemId)
   847  }
   848  
   849  // CompileDefault
   850  //
   851  //  Returns up to item without user, group, state.
   852  //  Chain sample KeyWithLegend, LegendChainSample
   853  //
   854  //  Group, State will be used from creation.
   855  //
   856  // Example:
   857  //  - "{root}-{package}-{state}-{group}"
   858  //
   859  // Missing:
   860  //  - "{user}-{item}"
   861  //
   862  // Conditions apply:
   863  //  - if Option.IsSkipEmptyEntry then empty input wil be ignored.
   864  func (it *KeyWithLegend) CompileDefault() string {
   865  	request := KeyLegendCompileRequest{
   866  		StateName: it.stateName,
   867  		GroupId:   it.groupName,
   868  	}
   869  
   870  	return it.CompileUsingRequest(request)
   871  }
   872  
   873  // CompileUsingJoiner
   874  //
   875  //  Returns up to item without user, group, state.
   876  //  Chain sample KeyWithLegend, LegendChainSample
   877  //
   878  //  State, Group will be used from creation.
   879  //
   880  // Example:
   881  //  - "{root}-{package}-{state}-{group}"
   882  //
   883  // Missing:
   884  //  - "{user}-{item}"
   885  //
   886  // Conditions apply:
   887  //  - if Option.IsSkipEmptyEntry then empty input wil be ignored.
   888  func (it *KeyWithLegend) CompileUsingJoiner(
   889  	joiner string,
   890  ) string {
   891  	request := KeyLegendCompileRequest{
   892  		StateName: it.stateName,
   893  		GroupId:   it.groupName,
   894  	}
   895  
   896  	finalItems := it.FinalStrings(request)
   897  
   898  	return strings.Join(finalItems, joiner)
   899  }
   900  
   901  // CompileStrings
   902  //
   903  //  Returns up to item without user, group, state.
   904  //  Chain sample KeyWithLegend, LegendChainSample
   905  //
   906  //  State, Group will be used from creation.
   907  //
   908  // Example:
   909  //  - "{root}-{package}-{state}-{group}"
   910  //
   911  // Missing:
   912  //  - "{user}-{item}"
   913  //
   914  // Conditions apply:
   915  //  - if Option.IsSkipEmptyEntry then empty input wil be ignored.
   916  func (it *KeyWithLegend) CompileStrings() []string {
   917  	request := KeyLegendCompileRequest{
   918  		StateName: it.stateName,
   919  		GroupId:   it.groupName,
   920  	}
   921  
   922  	return it.FinalStrings(request)
   923  }
   924  
   925  // Strings
   926  //
   927  //  Returns up to item without user, group, state.
   928  //  Chain sample KeyWithLegend, LegendChainSample
   929  //
   930  //  State, Group will be used from creation.
   931  //
   932  // Example:
   933  //  - "{root}-{package}-{state}-{group}"
   934  //
   935  // Missing:
   936  //  - "{user}-{item}"
   937  //
   938  // Conditions apply:
   939  //  - if Option.IsSkipEmptyEntry then empty input wil be ignored.
   940  func (it *KeyWithLegend) Strings() []string {
   941  	return it.CompileStrings()
   942  }
   943  
   944  // CompileItemUsingJoiner
   945  //
   946  //  Returns up to item without user, group, state.
   947  //  Chain sample KeyWithLegend, LegendChainSample
   948  //
   949  //  State, Group will be used from creation.
   950  //
   951  // Example:
   952  //  - "{root}-{package}-{state}-{group}"
   953  //
   954  // Missing:
   955  //  - "{user}-{item}"
   956  //
   957  // Conditions apply:
   958  //  - if Option.IsSkipEmptyEntry then empty input wil be ignored.
   959  func (it *KeyWithLegend) CompileItemUsingJoiner(
   960  	joiner, item string,
   961  ) string {
   962  	request := KeyLegendCompileRequest{
   963  		StateName: it.stateName,
   964  		GroupId:   it.groupName,
   965  		ItemId:    item,
   966  	}
   967  
   968  	finalItems := it.FinalStrings(request)
   969  
   970  	return strings.Join(finalItems, joiner)
   971  }
   972  
   973  // CompileUsingRequest
   974  //
   975  // Compiles using FinalStrings
   976  func (it *KeyWithLegend) CompileUsingRequest(
   977  	request KeyLegendCompileRequest,
   978  ) string {
   979  	finalItems := it.FinalStrings(request)
   980  
   981  	return strings.Join(finalItems, it.option.Joiner)
   982  }
   983  
   984  // FinalStrings
   985  //
   986  //  Returns compiled array from
   987  //  conditions using OutputItemsArray
   988  //
   989  // Conditions:
   990  //  - When request given
   991  func (it *KeyWithLegend) FinalStrings(
   992  	request KeyLegendCompileRequest,
   993  ) []string {
   994  	array := it.OutputItemsArray(request)
   995  
   996  	if it.option.IsUseBrackets {
   997  		return it.addBrackets(array)
   998  	}
   999  
  1000  	return array
  1001  }
  1002  
  1003  func (it *KeyWithLegend) addBrackets(inputItems []string) []string {
  1004  	for i, item := range inputItems {
  1005  		inputItems[i] = it.option.StartBracket + item + it.option.EndBracket
  1006  	}
  1007  
  1008  	return inputItems
  1009  }
  1010  
  1011  func (it *KeyWithLegend) OutputWithoutLegend(request KeyLegendCompileRequest) []string {
  1012  	slice := make([]string, 0, constants.Capacity6)
  1013  
  1014  	slice = append(slice, it.rootName)
  1015  	slice = append(slice, it.packageName)
  1016  
  1017  	isAddRegardless := it.
  1018  		option.
  1019  		IsAddEntryRegardlessOfEmptiness()
  1020  
  1021  	if isAddRegardless || request.GroupId != "" {
  1022  		slice = append(slice, request.GroupId)
  1023  	}
  1024  
  1025  	if isAddRegardless || request.StateName != "" {
  1026  		slice = append(slice, request.StateName)
  1027  	}
  1028  
  1029  	if isAddRegardless || request.UserId != "" {
  1030  		slice = append(slice, request.UserId)
  1031  	}
  1032  
  1033  	if isAddRegardless || request.ItemId != "" {
  1034  		slice = append(slice, request.ItemId)
  1035  	}
  1036  
  1037  	return slice
  1038  }
  1039  
  1040  func (it *KeyWithLegend) CloneUsing(groupName string) *KeyWithLegend {
  1041  	if it == nil {
  1042  		return nil
  1043  	}
  1044  
  1045  	return NewKeyWithLegend.All(
  1046  		it.option.ClonePtr(),
  1047  		it.LegendName,
  1048  		it.isAttachLegendNames,
  1049  		it.rootName,
  1050  		it.packageName,
  1051  		groupName,
  1052  		it.stateName)
  1053  }
  1054  
  1055  func (it *KeyWithLegend) Clone() *KeyWithLegend {
  1056  	return it.CloneUsing(it.groupName)
  1057  }