Update CharBag, Add remote methods in Document
This commit is contained in:
parent
fb18863ed2
commit
0960890d0d
@ -12,6 +12,7 @@ public class ArrayCharBag implements CharBag {
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
// TODO: use binary search
|
// TODO: use binary search
|
||||||
while(i < chars.size() && Util.comparePositions(chars.get(i).position(), character.position()) < 0) i++;
|
while(i < chars.size() && Util.comparePositions(chars.get(i).position(), character.position()) < 0) i++;
|
||||||
|
if(i < chars.size() && Util.comparePositions(chars.get(i).position(), character.position()) == 0) return -1;
|
||||||
chars.add(i, character);
|
chars.add(i, character);
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,8 @@ package me.mrletsplay.shareclientcore.document;
|
|||||||
|
|
||||||
public interface CharBag {
|
public interface CharBag {
|
||||||
|
|
||||||
// public Character find(PositionIdentifier position);
|
|
||||||
// public Character findBefore(PositionIdentifier position);
|
|
||||||
// public Character findAfter(PositionIdentifier position);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a character to the bag and returns the index it was inserted at
|
* Adds a character to the bag and returns the index it was inserted at, or -1 if it was not inserted because it already exists
|
||||||
* @param character The character to add
|
* @param character The character to add
|
||||||
* @return The index it was inserted at
|
* @return The index it was inserted at
|
||||||
*/
|
*/
|
||||||
|
@ -48,6 +48,26 @@ public class Document {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inserts a remote change into the document and updates internal parameters accordingly
|
||||||
|
* @param c The character to insert
|
||||||
|
* @return The index of the inserted character, or -1 if it was not inserted because it already exists
|
||||||
|
*/
|
||||||
|
public int remoteInsert(Char c) {
|
||||||
|
lamport = Math.max(c.lamport(), lamport) + 1;
|
||||||
|
return charBag.add(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a character from the document and updates internal parameters accordingly
|
||||||
|
* @param c The character to delete
|
||||||
|
* @return The index the character was located at, or -1 if it was not contained in the document
|
||||||
|
*/
|
||||||
|
public int remoteDelete(Char c) {
|
||||||
|
lamport = Math.max(c.lamport(), lamport) + 1;
|
||||||
|
return charBag.remove(c);
|
||||||
|
}
|
||||||
|
|
||||||
public CharBag getCharBag() {
|
public CharBag getCharBag() {
|
||||||
return charBag;
|
return charBag;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user