@SafeVarargs public static List<Pair<SizeUnit, Double>> getMathOperationSafeOperands(Pair<SizeUnit, Double>... operands) { List<Pair<SizeUnit, Double>> operationReadyOperands = new ArrayList<>(); List<Pair<SizeUnit, Double>> convertedOperands = new ArrayList<>(); for (Pair<SizeUnit, Double> operand : operands) { convertedOperands.add(autoConvert(operand.getSecond().longValue(), operand.getFirst())); } SizeUnit finalUnit = leastUnitInList(convertedOperands); for (Pair<SizeUnit, Double> operand : convertedOperands) { if(operand.getFirst() != finalUnit) { operationReadyOperands.add(new Pair<>(finalUnit, convert(operand.getSecond().longValue(), operand.getFirst(), finalUnit).doubleValue())); } else { operationReadyOperands.add(operand); } } return operationReadyOperands; } }
private String formatDataRead(UIMessages messages, long totalBytesRead, long bytesReadInCurrentInterval) { Pair<SizeUnit, Double> dataReadInCurrentInterval = SizeConverter.autoConvert(bytesReadInCurrentInterval, SizeUnit.BYTES); Pair<SizeUnit, Double> dataRead = SizeConverter.autoConvert(totalBytesRead, SizeUnit.BYTES); return messages.bytesReadInCurrentProfileInterval(formatSize(dataReadInCurrentInterval.getSecond()), dataReadInCurrentInterval.getFirst().name(), formatSize(dataRead.getSecond()), dataRead.getFirst().toString()); }
private String formatDataWritten(UIMessages messages, long totalBytesWritten, long bytesWrittenInCurrentInterval) { Pair<SizeUnit, Double> dataWrittenInCurrentInterval = SizeConverter.autoConvert(bytesWrittenInCurrentInterval, SizeUnit.BYTES); Pair<SizeUnit, Double> dataWritten = SizeConverter.autoConvert(totalBytesWritten, SizeUnit.BYTES); return messages.bytesWrittenInCurrentProfileInterval(formatSize(dataWrittenInCurrentInterval.getSecond()), dataWrittenInCurrentInterval.getFirst().toString(), formatSize(dataWritten.getSecond()), dataWritten.getFirst().toString()); }
private void updateBrickSize() { long totalSize = 0; // Calculate and show the total size of all selected device so that user can get an idea of what will be his // brick // capacity. if (getStorageDevices().getSelectedItems() != null) { for (StorageDevice storageDevice : getStorageDevices().getSelectedItems()) { totalSize += storageDevice.getSize(); } } Pair<SizeUnit, Double> convertedSize = SizeConverter.autoConvert(totalSize, SizeUnit.MiB); setBrickSize(convertedSize); }