use of me.retrodaredevil.solarthing.packets.instance.InstancePacket in project solarthing by wildmountainfarms.
the class PacketGroups method parseToTargetPacketGroup.
public static TargetPacketGroup parseToTargetPacketGroup(PacketGroup packetGroup) {
if (packetGroup instanceof TargetPacketGroup) {
return (TargetPacketGroup) packetGroup;
}
List<Packet> packets = new ArrayList<>();
InstanceSourcePacket sourcePacket = null;
InstanceTargetPacket targetPacket = null;
for (Packet packet : packetGroup.getPackets()) {
if (packet instanceof InstancePacket) {
InstancePacket instancePacket = (InstancePacket) packet;
switch(instancePacket.getPacketType()) {
case SOURCE:
sourcePacket = (InstanceSourcePacket) packet;
break;
case TARGET:
targetPacket = (InstanceTargetPacket) packet;
break;
}
} else {
packets.add(packet);
}
}
return createTargetPacketGroup(packets, packetGroup.getDateMillis(), sourcePacket == null ? InstanceSourcePacket.UNUSED_SOURCE_ID : sourcePacket.getSourceId(), targetPacket == null ? Collections.emptyList() : targetPacket.getTargetFragmentIds());
}
use of me.retrodaredevil.solarthing.packets.instance.InstancePacket in project solarthing by wildmountainfarms.
the class PacketGroups method parseToInstancePacketGroup.
public static InstancePacketGroup parseToInstancePacketGroup(PacketGroup group, DefaultInstanceOptions defaultInstanceOptions) {
if (group instanceof InstancePacketGroup) {
return (InstancePacketGroup) group;
}
List<Packet> packets = new ArrayList<>();
String sourceId = defaultInstanceOptions.getDefaultSourceId();
int fragmentId = defaultInstanceOptions.getDefaultFragmentId();
for (Packet packet : group.getPackets()) {
if (packet instanceof InstancePacket) {
InstancePacket instancePacket = (InstancePacket) packet;
switch(instancePacket.getPacketType()) {
case SOURCE:
sourceId = ((InstanceSourcePacket) instancePacket).getSourceId();
break;
case FRAGMENT_INDICATOR:
fragmentId = ((InstanceFragmentIndicatorPacket) instancePacket).getFragmentId();
break;
default:
break;
}
} else {
packets.add(packet);
}
}
return createInstancePacketGroup(packets, group.getDateMillis(), sourceId, fragmentId);
}
Aggregations