Search in sources :

Example 1 with DefaultIdentificationCacheDataPacket

use of me.retrodaredevil.solarthing.type.cache.packets.DefaultIdentificationCacheDataPacket in project solarthing by wildmountainfarms.

the class DefaultIdentificationCacheCreator method createFrom.

@Override
public IdentificationCacheDataPacket<T> createFrom(String sourceId, List<InstancePacketGroup> packetGroups, Instant periodStart, Duration periodDuration) {
    Class<U> acceptedType = identificationCacheNodeCreator.getAcceptedType();
    Map<String, Map<IdentifierFragment, List<TimestampedPacket<U>>>> mappedPackets = convertPackets(packetGroups, acceptedType);
    Map<IdentifierFragment, List<TimestampedPacket<U>>> identifierFragmentMap = mappedPackets.getOrDefault(sourceId, Collections.emptyMap());
    List<IdentificationCacheNode<T>> nodes = new ArrayList<>(identifierFragmentMap.size());
    for (Map.Entry<IdentifierFragment, List<TimestampedPacket<U>>> entry : identifierFragmentMap.entrySet()) {
        IdentifierFragment identifierFragment = entry.getKey();
        List<TimestampedPacket<U>> packets = entry.getValue();
        IdentificationCacheNode<T> node = identificationCacheNodeCreator.create(identifierFragment, packets, periodStart, periodDuration);
        nodes.add(node);
    }
    return new DefaultIdentificationCacheDataPacket<>(periodStart.toEpochMilli(), periodDuration.toMillis(), sourceId, identificationCacheNodeCreator.getCacheName(), nodes);
}
Also used : DefaultIdentificationCacheDataPacket(me.retrodaredevil.solarthing.type.cache.packets.DefaultIdentificationCacheDataPacket) IdentificationCacheNode(me.retrodaredevil.solarthing.type.cache.packets.IdentificationCacheNode) IdentifierFragment(me.retrodaredevil.solarthing.packets.identification.IdentifierFragment) TimestampedPacket(me.retrodaredevil.solarthing.packets.TimestampedPacket)

Aggregations

TimestampedPacket (me.retrodaredevil.solarthing.packets.TimestampedPacket)1 IdentifierFragment (me.retrodaredevil.solarthing.packets.identification.IdentifierFragment)1 DefaultIdentificationCacheDataPacket (me.retrodaredevil.solarthing.type.cache.packets.DefaultIdentificationCacheDataPacket)1 IdentificationCacheNode (me.retrodaredevil.solarthing.type.cache.packets.IdentificationCacheNode)1