@Override public CountersSnapshotDTO clone() { final CountersSnapshotDTO other = new CountersSnapshotDTO(); other.setGenerated(getGenerated()); final List<CounterDTO> clonedCounters = new ArrayList<>(getCounters().size()); for (final CounterDTO counterDto : getCounters()) { clonedCounters.add(counterDto.clone()); } other.setCounters(clonedCounters); return other; } }
/** * Creates CounterDTOs for each Counter specified. * * @param counterDtos dtos * @return dto */ public CountersSnapshotDTO createCountersDto(final Collection<CounterDTO> counterDtos) { final CountersSnapshotDTO dto = new CountersSnapshotDTO(); dto.setCounters(counterDtos); dto.setGenerated(new Date()); return dto; }
public static void merge(final CountersSnapshotDTO target, final CountersSnapshotDTO toMerge) { final Map<String, CounterDTO> counters = new HashMap<>(); for (final CounterDTO counter : target.getCounters()) { counters.put(counter.getId(), counter); } for (final CounterDTO counter : toMerge.getCounters()) { final CounterDTO existing = counters.get(counter.getId()); if (existing == null) { counters.put(counter.getId(), counter); } else { merge(existing, counter); } } target.setCounters(counters.values()); }
@Override protected void mergeResponses(CountersDTO clientDto, Map<NodeIdentifier, CountersDTO> dtoMap, NodeIdentifier selectedNodeId) { final CountersDTO mergedCounters = clientDto; mergedCounters.setNodeSnapshots(new ArrayList<NodeCountersSnapshotDTO>()); final NodeCountersSnapshotDTO selectedNodeSnapshot = new NodeCountersSnapshotDTO(); selectedNodeSnapshot.setSnapshot(clientDto.getAggregateSnapshot().clone()); selectedNodeSnapshot.setAddress(selectedNodeId.getApiAddress()); selectedNodeSnapshot.setApiPort(selectedNodeId.getApiPort()); selectedNodeSnapshot.setNodeId(selectedNodeId.getId()); mergedCounters.getNodeSnapshots().add(selectedNodeSnapshot); for (final Map.Entry<NodeIdentifier, CountersDTO> entry : dtoMap.entrySet()) { final NodeIdentifier nodeId = entry.getKey(); final CountersDTO toMerge = entry.getValue(); if (toMerge == clientDto) { continue; } StatusMerger.merge(mergedCounters, toMerge, nodeId.getId(), nodeId.getApiAddress(), nodeId.getApiPort()); } }
@Override public NodeCountersSnapshotDTO clone() { final NodeCountersSnapshotDTO other = new NodeCountersSnapshotDTO(); other.setNodeId(getNodeId()); other.setAddress(getAddress()); other.setApiPort(getApiPort()); other.setSnapshot(getSnapshot().clone()); return other; }