Update:-
There is one issue with your suggestion -
Suppose if I am making keys like this, then it will throw IllegalArgumentException, right? Since uuid and deviceid are null or empty but with my above rules, if userId is set and it is set with proper value, then it should not throw IllegalArgumentException. Meaning if userId is set, then I will validate userId to see whether it is <= 0
or not.
DataKey keys = new DataKey.Builder(100).setUserId(1234L).setUuid("").setDeviceId(null).build();
There is always a priority, userId takes the priority first, then uuid takes the priority and then deviceId takes the priority.
If userId is set, then I will validate userId, but if userId is not set and uuid is set, then I will validate uuid but if userId and uuid is not set, then I will validate deviceId.