org.coweb.oe.ContextDifference Maven / Gradle / Ivy
package org.coweb.oe;
import java.util.Arrays;
import java.util.Vector;
public class ContextDifference {
public Vector sites;
public Vector seqs;
public ContextDifference() {
this.sites = new Vector();
this.seqs = new Vector();
}
/**
* Adds a range of operations to the difference.
*
* @param {Number} site Integer site ID
* @param {Number} start First integer operation sequence number, inclusive
* @param {Number} end Last integer operation sequence number, exclusive
*/
public void addRange(int site, int start, int end) {
for(int i=start; i < end; i++) {
this.addSiteSeq(site, i);
}
}
/**
* Adds a single operation to the difference.
*
* @param {Number} site Integer site ID
* @param {Number} seq Integer sequence number
*/
public void addSiteSeq(int site, int seq) {
this.sites.addElement(new Integer(site));
this.seqs.addElement(new Integer(seq));
}
/**
* Gets the histor buffer keys for all the operations represented in this
* context difference.
*
* @return {String[]} Array of keys for HistoryBuffer lookups
*/
public String[] getHistoryBufferKeys() {
Vector arr = new Vector();
int l = this.seqs.size();
for(int i=0; i < l; i++) {
String key = Operation.createHistoryKey(this.sites.elementAt(i),
this.seqs.elementAt(i));
arr.addElement(key);
}
String[] strArr = new String[arr.size()];
return arr.toArray(strArr);
}
/**
* Converts the contents of this context difference to a string.
*
* @return {String} All keys in the difference (for debug)
*/
public String toString() {
return Arrays.toString(this.getHistoryBufferKeys());
}
}