|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.electrocodeogram.cpc.core.api.data.CloneDiff
public class CloneDiff
Clone diff objects represent modifications which were made to the content of a clone.
Their semantics are the same as those of DocumentEvent
s but all positions are
relative to the offset of the affected clone.
Due to performance considerations and its inherent simplicity this class is not hidden
behind any interface and its implementation is provided directly by the CPC Core and
not the ICloneFactoryProvider
.
NOTE: a CloneDiff
instance only describes the part of a DocumentEvent
which affected the corresponding clone. I.e. if a modification started before the start offset
of the clone than only the part of the modification which was attributed to the clone, should
be part of the CloneDiff
event. This may require some translation of offsets.
A relative CloneDiff
offset must never be negative.
The goal is that CloneDiff
events can be applied to a standalone copy of the corresponding
clone, without having to take any modifications outside of the clone into account.
IPositionUpdateStrategyProvider
,
CoreHistoryUtils
,
Serialized FormField Summary | |
---|---|
protected boolean |
automaticChange
|
protected java.util.Date |
creationDate
|
protected java.lang.String |
creator
|
protected int |
length
|
protected int |
offset
|
static java.lang.String |
PERSISTENCE_CLASS_IDENTIFIER
IStatefulObject persistence class identifier, value: "clone_diff" |
static java.lang.String |
PERSISTENCE_OBJECT_IDENTIFIER
IStatefulObject persistence object identifier, value: "creationDate"
getCreationDate() is guaranteed to be a unique value per clone. |
protected java.lang.String |
text
|
Constructor Summary | |
---|---|
CloneDiff()
This constructor may only be used while restoring CloneDiff objects. |
|
CloneDiff(java.lang.String creator,
java.util.Date creationDate,
boolean automaticChange,
int offset,
int length,
java.lang.String text)
Creates a new, immutable CloneDiff instance. |
Method Summary | |
---|---|
java.lang.Object |
clone()
CloneDiff objects are immutable. |
int |
compareTo(CloneDiff o)
|
boolean |
equals(java.lang.Object obj)
|
java.util.Date |
getCreationDate()
Retrieves the creation time of this diff. |
java.lang.String |
getCreator()
Retrieves the creator (username) of this diff. |
int |
getLength()
Retrieves the number of characters replaced by this modification. |
int |
getOffset()
Retrieves the offset of this modification. |
java.lang.String |
getPersistenceClassIdentifier()
Returns a string which uniquely identifies the object type. |
java.lang.String |
getPersistenceObjectIdentifier()
Returns a key which corresponds to an entry in the state Map returned by getState() which uniquely identifies an object instance. |
java.util.Map<java.lang.String,java.lang.Comparable<? extends java.lang.Object>> |
getState()
Returns a map which fully describes the internal state of this object. |
java.util.Map<java.lang.String,java.lang.Class<? extends java.lang.Object>> |
getStateTypes()
Returns a list of all keys which are needed to persist this objects internal state. |
java.lang.String |
getText()
Retrieves the text which was inserted by this modification. |
int |
getTextLength()
Retrieves the length of the text which was inserted by this modification. |
int |
hashCode()
|
boolean |
isAutomaticChange()
Checks whether this CloneDiff was created by some automated action, i.e. |
boolean |
isSealed()
Checks whether this ICloneDataElement instance has been sealed. |
void |
seal()
Seals this ICloneDataElement instance. |
void |
setState(java.util.Map<java.lang.String,java.lang.Comparable<? extends java.lang.Object>> state)
Restores the internal state of this object to the state which was extracted by means of getState() earlier. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String PERSISTENCE_CLASS_IDENTIFIER
IStatefulObject
persistence class identifier, value: "clone_diff"
public static final java.lang.String PERSISTENCE_OBJECT_IDENTIFIER
IStatefulObject
persistence object identifier, value: "creationDate"
getCreationDate()
is guaranteed to be a unique value per clone.
protected java.lang.String creator
protected java.util.Date creationDate
protected boolean automaticChange
protected int offset
protected int length
protected java.lang.String text
Constructor Detail |
---|
public CloneDiff()
CloneDiff
objects.
setState(Map)
.
public CloneDiff(java.lang.String creator, java.util.Date creationDate, boolean automaticChange, int offset, int length, java.lang.String text)
CloneDiff
instance.
NOTE: The creationDate needs to be a unique value for the corresponding clone.
As java Date
s offer only millisecond precision and many system clocks much less than
that, it would be possible for multiple CloneDiff
instances to be created with the same
date value.
This needs to be prevented. Any code which creates multiple CloneDiff
instances in quick
succession has to ensure that no two diffs are created with the same creationDate value.
One possible approach to this requirement would be to remember the time of the last CloneDiff
instance and to artificially increase the creationDate by one millisecond if it is equal to
the creationDate of the last event.
creator
- the creator (username) of this diff, NULL if unknown.creationDate
- the creation time of this diff, never null.
This value needs to be unique within one clone instance. See above.automaticChange
- true if it can be guaranteed that this change was not done directly by a human.
I.e. refactorings or source code reformats.offset
- the start offset of this diff, relative to the start offset of the clone, always >= 0.length
- the number of characters replaced by this modification.
0 if this modification only added text. Always >=0.text
- the text which was inserted by this modification, may be NULL.Method Detail |
---|
public int getOffset()
public int getLength()
public java.lang.String getText()
public int getTextLength()
getText()
or 0 if it is null. Always >=0.public java.lang.String getCreator()
public java.util.Date getCreationDate()
CloneDiff
object to ensure uniqueness of
creation times within the diff events of one clone object.
CloneDiff(String, Date, boolean, int, int, String)
public boolean isAutomaticChange()
CloneDiff
was created by some automated action, i.e.
a refactoring or a source code reformat.
public java.lang.String getPersistenceClassIdentifier()
IStatefulObject
For the default ICloneObject
sub interfaces the return values must equal
the PERSISTENCE_CLASS_IDENTIFIER constant defined in the interface.
3rd party clone objects can define their own persistence identifiers.
Allowed are only letters, numbers and the underscore. Furthermore
an identifier needs to contain at least one letter, may not begin with an underscore
and may not contain multiple consecutive underscores.
A typical store provider will use this method to derive directory/file or table names.
getPersistenceClassIdentifier
in interface IStatefulObject
public java.lang.String getPersistenceObjectIdentifier()
IStatefulObject
For the default ICloneObject
sub interfaces the return values must equal
the PERSISTENCE_OBJECT_IDENTIFIER constant defined in the ICloneObject
interface.
By default this is uuid.
3rd party clone objects can define their own persistence identifiers.
Allowed are only letters, numbers and the underscore. Furthermore
an identifier needs to contain at least one letter, may not begin with an underscore
and may not contain multiple consecutive underscores.
A typical store provider will use this method to derive file names, internal id structure names or table primary keys.
IMPORTANT: the corresponding value in IStatefulObject.getState()
must not be changed at any point.
The unique identifiers of all stateful objects must remain unchanged during their entire lifetime.
getPersistenceObjectIdentifier
in interface IStatefulObject
IStatefulObject.getState()
public java.util.Map<java.lang.String,java.lang.Comparable<? extends java.lang.Object>> getState()
IStatefulObject
IStoreProvider
and the setState() method is used to restore a persisted state.
In case of an ICloneObject
, the map does not include any data for
ICloneObjectExtension
which are stored under the object.
The values in the map are restricted to the following object types:
IStatefulObject.getPersistenceObjectIdentifier()
entry in this state map must always be defined
and its value may not change during the lifetime of a stateful object.
getState
in interface IStatefulObject
IStatefulObject.setState(Map)
public java.util.Map<java.lang.String,java.lang.Class<? extends java.lang.Object>> getStateTypes()
IStatefulObject
I.e. if getState() will return a Map which contains the key "uuid" with the value "jda83ds-..." then this Map contains the key "uuid" with the value String.class.
getStateTypes
in interface IStatefulObject
IStatefulObject.getState()
public void setState(java.util.Map<java.lang.String,java.lang.Comparable<? extends java.lang.Object>> state)
IStatefulObject
For a description of the internal structure of the map, see getState().
setState
in interface IStatefulObject
state
- a map describing the internal state of this object, never nullIStatefulObject.getState()
public boolean isSealed()
ICloneDataElement
ICloneDataElement
instance has been sealed.
isSealed
in interface ICloneDataElement
public void seal()
ICloneDataElement
ICloneDataElement
instance.
In order to "unseal" an ICloneDataElement
, it needs to be cloned. The seal state will not
be propagated to the cloned instance.
seal
in interface ICloneDataElement
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
CloneDiff
objects are immutable.
Object.clone()
contract,
cloneDiff.clone() == cloneDiff
will be true.
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int compareTo(CloneDiff o)
compareTo
in interface java.lang.Comparable<CloneDiff>
public java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |