Skip to main content
summaryrefslogtreecommitdiffstats
blob: 601b210246480078ae8143c696530f5e4fce0703 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package org.eclipse.ecf.docshare.cola;

import org.eclipse.ecf.docshare.messages.*;

public class ColaUpdateMessage extends UpdateMessage {

	private static final long serialVersionUID = 2038025022180647210L;

	// TODO encapsulate in a new ColaOpOriginationState and re-implement equals,
	// hashCode, i.e. make comparable
	final double localOperationsCount;
	final double remoteOperationsCount;
	final TransformationStrategy trafoStrat;

	public ColaUpdateMessage(UpdateMessage msg, double localOperationsCount,
			double remoteOperationsCount) {
		super(msg.getOffset(), msg.getLength(), msg.getText());
		this.localOperationsCount = localOperationsCount;
		this.remoteOperationsCount = remoteOperationsCount;
		if (super.getLength() == 0) {
			// this is neither a replacement, nor a deletion
			trafoStrat = new ColaInsertion();
		} else {
			if (super.getText().length() == 0) {
				// something has been replaced, nothing inserted, must be a
				// deletion
				trafoStrat = new ColaDeletion();
			} else {
				// something has been replaced with some new input, has to be a
				// replacement op
				trafoStrat = new ColaReplacement();
			}
		}
	}

	public double getLocalOperationsCount() {
		return this.localOperationsCount;
	}

	public double getRemoteOperationsCount() {
		return this.remoteOperationsCount;
	}

	/**
	 * The receiver of this message transforms it for local application.
	 * 
	 * The transformation assumes that this operation is to be transformed
	 * against queued document owner operations which have a higher modification
	 * priority. that is when in direct index conflict are applied to lower
	 * index positions. This <code>ColaUpdateMessage</code> is transformed to
	 * be applied to the next appropriate higher document index position.
	 * 
	 * @param msg
	 *            queued up operation of local editing site
	 * @return message suitable to be transformed against next queued up
	 *         operation
	 */
	public ColaUpdateMessage transformForApplicationAtOwnerAgainst(ColaUpdateMessage msg) {
		// case this is the operation of lesser insertion priority
		ColaUpdateMessage transformedMsg = trafoStrat.getForOwner(this, msg);
		return transformedMsg;
	}

	public ColaUpdateMessage transformForApplicationAtParticipantAgainst(ColaUpdateMessage msg) {
		// case this is the operation of higher insertion priority
		ColaUpdateMessage transformedMsg = trafoStrat.getForParticipant(this, msg);
		return transformedMsg;
	}

	@Override
	public String toString() {
		return super.toString() + "\n originationCount: local: " + this.localOperationsCount
				+ " remote: " + this.remoteOperationsCount;
	}

}

Back to the top