I need to implement a structure in Java that is a key-value list (of types Integer-String) and I want to shuffle it.
Basically, I would like to do something like that.>
You can use enum
to achieve this, example
package device.packet.data;
public enum TLVList {
SpeedingAlarm(0x1001, 3, Short.class),
LowVoltageAlarm(0x1002, 3, Short.class),
OBDCommunicationError(0x1015, 3, Short.class),
IgnitionOn(0x1016, 3, Short.class),
IgnitionOff(0x1017, 3, Short.class),
MILAlarm(0x1018, 3, Short.class),
UnlockAlarm(0x1019, 3, Short.class),
NoCardPresented(0x101A, 3, Short.class),
HiddenCommand(0x101B, 3, Short.class),
Vibration(0x101C, 3, Short.class),
DoorOpened(0x101D, 3, Short.class);
private int tagFlagHex;
private int length;
private Class aClass;
public int gettagFlagHex() {
return tagFlagHex;
}
public int getLength() {
return length;
}
public Class getClassType() {
return aClass;
}
TLVList(int tagFlagHex, int length, Class aClass) {
this.tagFlagHex = tagFlagHex;
this.length = length;
this.aClass = aClass;
}
public static TLVList of(Integer tagFlagHex) {
for (TLVList tagFlag : TLVList.values()) {
if(tagFlag.tagFlagHex == tagFlagHex) return tagFlag;
}
return null;
}
}
I hope it helps.