package iotcloud; import java.util.Set; import java.util.HashSet; import java.util.List; import java.util.ArrayList; class ArbitrationRound { public static final int MAX_PARTS = 10; Set abortsBefore = null; List parts = null; Commit commit = null; int currentSize = 0; boolean didSendPart = false; boolean didGenerateParts = false; public ArbitrationRound(Commit _commit, Set _abortsBefore) { parts = new ArrayList(); commit = _commit; abortsBefore = _abortsBefore; if (commit != null) { commit.createCommitParts(); currentSize += commit.getNumberOfParts(); } currentSize += abortsBefore.size(); } public void generateParts() { if (didGenerateParts) { return; } parts = new ArrayList(abortsBefore); if (commit != null) { parts.addAll(commit.getParts().values()); } } public List getParts() { return parts; } public void removeParts(List removeParts) { parts.removeAll(removeParts); didSendPart = true; } public boolean isDoneSending() { if ((commit == null) && abortsBefore.isEmpty()) { return true; } return parts.isEmpty(); } public Commit getCommit() { return commit; } public void setCommit(Commit _commit) { if (commit != null) { currentSize -= commit.getNumberOfParts(); } commit = _commit; if (commit != null) { currentSize += commit.getNumberOfParts(); } } public void addAbort(Abort abort) { abortsBefore.add(abort); currentSize++; } public void addAborts(Set aborts) { abortsBefore.addAll(aborts); currentSize += aborts.size(); } public Set getAborts() { return abortsBefore; } public int getAbortsCount() { return abortsBefore.size(); } public int getCurrentSize() { return currentSize; } public boolean isFull() { return currentSize >= MAX_PARTS; } public boolean didSendPart() { return didSendPart; } }