Search in sources :

Example 1 with PacketNode

use of me.retrodaredevil.solarthing.rest.graphql.packets.nodes.PacketNode in project solarthing by wildmountainfarms.

the class PacketUtil method convertPackets.

/**
 * @return A mutable list of packets of a certain type
 */
@SuppressWarnings("unchecked")
public static <T> List<PacketNode<T>> convertPackets(List<? extends FragmentedPacketGroup> packetGroups, Class<T> acceptClass, PacketFilter filter) {
    List<PacketNode<T>> r = new ArrayList<>();
    for (FragmentedPacketGroup packetGroup : packetGroups) {
        for (Packet packet : packetGroup.getPackets()) {
            if (!acceptClass.isInstance(packet)) {
                continue;
            }
            int fragmentId = packetGroup.getFragmentId(packet);
            String sourceId = packetGroup.getSourceId(packet);
            long dateMillis = packetGroup.getDateMillisOrKnown(packet);
            PacketNode<T> packetNode = new PacketNode<>((T) packet, dateMillis, sourceId, fragmentId);
            if (filter.keep(packetNode)) {
                r.add(packetNode);
            }
        }
    }
    return r;
}
Also used : FragmentedPacketGroup(me.retrodaredevil.solarthing.packets.collection.FragmentedPacketGroup) Packet(me.retrodaredevil.solarthing.packets.Packet) ArrayList(java.util.ArrayList) PacketNode(me.retrodaredevil.solarthing.rest.graphql.packets.nodes.PacketNode)

Aggregations

ArrayList (java.util.ArrayList)1 Packet (me.retrodaredevil.solarthing.packets.Packet)1 FragmentedPacketGroup (me.retrodaredevil.solarthing.packets.collection.FragmentedPacketGroup)1 PacketNode (me.retrodaredevil.solarthing.rest.graphql.packets.nodes.PacketNode)1