--- /dev/null
+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<Abort> abortsBefore = null;
+ List<Entry> parts = null;
+ Commit commit = null;
+ int currentSize = 0;
+ boolean didSendPart = false;
+ boolean didGenerateParts = false;
+
+ public ArbitrationRound(Commit _commit, Set<Abort> _abortsBefore) {
+
+ parts = new ArrayList<Entry>();
+
+ commit = _commit;
+ abortsBefore = _abortsBefore;
+
+
+ if (commit != null) {
+ commit.createCommitParts();
+ currentSize += commit.getNumberOfParts();
+ }
+
+ currentSize += abortsBefore.size();
+ }
+
+ public void generateParts() {
+ if (didGenerateParts) {
+ return;
+ }
+ parts = new ArrayList<Entry>(abortsBefore);
+ if (commit != null) {
+ parts.addAll(commit.getParts().values());
+ }
+ }
+
+
+ public List<Entry> getParts() {
+ return parts;
+ }
+
+ public void removeParts(List<Entry> 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<Abort> aborts) {
+ abortsBefore.addAll(aborts);
+ currentSize += aborts.size();
+ }
+
+
+ public Set<Abort> 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;
+ }
+}
\ No newline at end of file