Hi kotliners, I’m going to model permission rules. Nothing difficult per-se but since the “source of truth” is a spreadheet with rows “object status” and columns “user role” and cells “grant/deny” I was wondering if I should build a representation close to this so it is easier to visually compare with that spreadsheet source of truth.
Anything better suited in kotlin than having and array of arrays for this? It is all static and only a 5x8 table.
m
Michael de Kaste
05/08/2020, 9:40 AM
depends on how readable you'd want it.
What does permissionRules[1][2] say? (That's access to one cell)
What are the different object statusses? What are the different User Roles?
b
Big Chungus
05/08/2020, 9:44 AM
Represent a row as object and store it as
List<RowClass>
. Or if you want header colomn
Map<String, RowClassForNonHeaderColumns>
Big Chungus
05/08/2020, 9:44 AM
This way you can use type safe representations of your columns. e.g.
String
,
Int
,
Enum
f
frogger
05/08/2020, 10:27 AM
(sorry for the delay. work..)
depends on how readable you’d want it.
What does permissionRules[1][2] say? (That’s access to one cell)
It would say granted true/false
frogger
05/08/2020, 10:28 AM
Ok, I see some kind of array of array or array of list is the best to try. the type-safe builder look like more suitable for tree models.
j
Jakub Pi
05/08/2020, 2:35 PM
Use data classes so that you have typesafe immutable representations with significant names for the underlying data, and then design your interface based on your lookup needs. For such a small table, you can get away with a List and just do a linear search. If it gets any bigger, put it into a Map with your search criteria as the key. Do not model it as a table, create a domain model and override toString() to spit out a table representation