Class SyncInfo
- java.lang.Object
-
- org.eclipse.team.core.synchronize.SyncInfo
-
- All Implemented Interfaces:
IAdaptable
public class SyncInfo extends Object implements IAdaptable
Describes the synchronization of a local resource relative to a remote resource variant. There are two types of comparison: two-way and three-way. TheIResourceVariantComparator
is used to decide which comparison type to use.For two-way comparisons, a
SyncInfo
node has a change type. This will be one ofIN-SYNC
,ADDITION
,DELETION
orCHANGE
determined in the following manner.- A resource is considered an
ADDITION
if it exists locally and there is no remote. - A resource is considered an
DELETION
if it does not exists locally and there is remote. - A resource is considered a
CHANGE
if both the local and remote exist but the comparator indicates that they differ. The comparator may be comparing contents or timestamps or some other resource state. - A resource is considered
IN_SYNC
in all other cases.
For three-way comparisons, the sync info node has a direction as well as a change type. The direction is one of
INCOMING
,OUTGOING
orCONFLICTING
. The comparison of the local and remote resources with a base resource is used to determine the direction of the change.- Differences between the base and local resources are classified as outgoing changes; if there is a difference, the local resource is considered the outgoing resource.
- Differences between the base and remote resources are classified as incoming changes; if there is a difference, the remote resource is considered the incoming resource.
- If there are both incoming and outgoing changes, the resource is considered a conflicting change.
- Since:
- 3.0
-
-
Field Summary
Fields Modifier and Type Field Description static int
ADDITION
Sync constant (value 1) indicating that one side was added.static int
AUTOMERGE_CONFLICT
Sync constant (value 32) indicating that both the local and remote resources have changed relative to the base but their content changes do not conflict (e.g. source file changes on different lines).static int
CHANGE
Sync constant (value 3) indicating that one side was changed.static int
CHANGE_MASK
Bit mask for extracting the change type.static int
CONFLICTING
Sync constant (value 12) indicating a change to both the remote and local resources.static int
DELETION
Sync constant (value 2) indicating that one side was deleted.static int
DIRECTION_MASK
Bit mask for extracting the synchronization direction.static int
IN_SYNC
Sync constant (value 0) indicating element is in sync.static int
INCOMING
Sync constant (value 8) indicating a change to the remote resource.static int
MANUAL_CONFLICT
Sync constant (value 64) indicating that both the local and remote resources have changed relative to the base and their content changes conflict (e.g. local and remote resource have changes on same lines).static int
OUTGOING
Sync constant (value 4) indicating a change to the local resource.static int
PSEUDO_CONFLICT
Sync constant (value 16) indication that both the local and remote resources have changed relative to the base but their contents are the same.
-
Constructor Summary
Constructors Constructor Description SyncInfo(IResource local, IResourceVariant base, IResourceVariant remote, IResourceVariantComparator comparator)
Construct a sync info object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected int
calculateKind()
Method that is invoked from theinit()
method to calculate the sync kind for this instance ofSyncInfo
.boolean
equals(Object other)
<T> T
getAdapter(Class<T> adapter)
Returns an object which is an instance of the given class associated with this object.IResourceVariant
getBase()
Returns the remote resource handle for the base resource, ornull
if the base resource does not exist.static int
getChange(int kind)
Helper method to return the change portion of the given kind.IResourceVariantComparator
getComparator()
Returns the comparator that is used to determine the kind of this sync node.static int
getDirection(int kind)
Helper method to return the direction portion of the given kind.int
getKind()
Returns the kind of synchronization for this node.IResource
getLocal()
Returns the state of the local resource.String
getLocalAuthor(IProgressMonitor monitor)
Returns the author of the revision corresponding to the local resource ornull
if it doesn't have one.String
getLocalContentIdentifier()
Returns the content identifier for the local resource ornull
if it doesn't have one.IResourceVariant
getRemote()
Returns the handle for the remote resource, ornull
if the remote resource does not exist.int
hashCode()
void
init()
Method that is invoked after instance creation to initialize the sync kind.static boolean
isInSync(int kind)
Helper method that returns whether the given kind represents an in-sync resource.static String
kindToString(int kind)
A helper method that returns a displayable (i.e. externalized) string describing the provided sync kind.String
toString()
-
-
-
Field Detail
-
IN_SYNC
public static final int IN_SYNC
Sync constant (value 0) indicating element is in sync.- See Also:
- Constant Field Values
-
ADDITION
public static final int ADDITION
Sync constant (value 1) indicating that one side was added.- See Also:
- Constant Field Values
-
DELETION
public static final int DELETION
Sync constant (value 2) indicating that one side was deleted.- See Also:
- Constant Field Values
-
CHANGE
public static final int CHANGE
Sync constant (value 3) indicating that one side was changed.- See Also:
- Constant Field Values
-
CHANGE_MASK
public static final int CHANGE_MASK
Bit mask for extracting the change type.- See Also:
- Constant Field Values
-
OUTGOING
public static final int OUTGOING
Sync constant (value 4) indicating a change to the local resource.- See Also:
- Constant Field Values
-
INCOMING
public static final int INCOMING
Sync constant (value 8) indicating a change to the remote resource.- See Also:
- Constant Field Values
-
CONFLICTING
public static final int CONFLICTING
Sync constant (value 12) indicating a change to both the remote and local resources.- See Also:
- Constant Field Values
-
DIRECTION_MASK
public static final int DIRECTION_MASK
Bit mask for extracting the synchronization direction.- See Also:
- Constant Field Values
-
PSEUDO_CONFLICT
public static final int PSEUDO_CONFLICT
Sync constant (value 16) indication that both the local and remote resources have changed relative to the base but their contents are the same.- See Also:
- Constant Field Values
-
AUTOMERGE_CONFLICT
public static final int AUTOMERGE_CONFLICT
Sync constant (value 32) indicating that both the local and remote resources have changed relative to the base but their content changes do not conflict (e.g. source file changes on different lines). These conflicts could be merged automatically.- See Also:
- Constant Field Values
-
MANUAL_CONFLICT
public static final int MANUAL_CONFLICT
Sync constant (value 64) indicating that both the local and remote resources have changed relative to the base and their content changes conflict (e.g. local and remote resource have changes on same lines). These conflicts can only be correctly resolved by the user.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SyncInfo
public SyncInfo(IResource local, IResourceVariant base, IResourceVariant remote, IResourceVariantComparator comparator)
Construct a sync info object.- Parameters:
local
- the local resource. Must be non-null but may not exist.base
- the base resource variant ornull
remote
- the remote resource variant ornull
comparator
- the comparator used to determine if resources differ
-
-
Method Detail
-
getLocal
public IResource getLocal()
Returns the state of the local resource. Note that the resource may or may not exist.- Returns:
- a resource
-
getLocalContentIdentifier
public String getLocalContentIdentifier()
Returns the content identifier for the local resource ornull
if it doesn't have one. For example, in CVS this would be the revision number.- Returns:
- String that could be displayed to the user to identify this resource.
-
getLocalAuthor
public String getLocalAuthor(IProgressMonitor monitor)
Returns the author of the revision corresponding to the local resource ornull
if it doesn't have one. For example if the local file is shared in CVS this would be the revision author.- Parameters:
monitor
- the progress monitor- Returns:
- the author of the revision associated with the local file or
null
- Since:
- 3.6
-
getBase
public IResourceVariant getBase()
Returns the remote resource handle for the base resource, ornull
if the base resource does not exist.[Note: The type of the common resource may be different from the types of the local and remote resources. ]
- Returns:
- a remote base resource handle, or
null
-
getRemote
public IResourceVariant getRemote()
Returns the handle for the remote resource, ornull
if the remote resource does not exist.[Note: The type of the remote resource may be different from the types of the local and common resources. ]
- Returns:
- a remote resource handle, or
null
-
getComparator
public IResourceVariantComparator getComparator()
Returns the comparator that is used to determine the kind of this sync node.- Returns:
- the comparator that is used to determine the kind of this sync node.
-
getKind
public int getKind()
Returns the kind of synchronization for this node.- Returns:
- the kind of synchronization for this node.
-
isInSync
public static boolean isInSync(int kind)
Helper method that returns whether the given kind represents an in-sync resource.- Parameters:
kind
- the kind of aSyncInfo
- Returns:
- whether the kind is
IN_SYNC
.
-
getDirection
public static int getDirection(int kind)
Helper method to return the direction portion of the given kind. The resulting value can be compared directly with the direction constants.- Parameters:
kind
- the kind of aSyncInfo
- Returns:
- the direction portion of the kind
-
getChange
public static int getChange(int kind)
Helper method to return the change portion of the given kind. The resulting value can be compared directly with the change type constants.- Parameters:
kind
- the kind of aSyncInfo
- Returns:
- the change portion of the kind
-
getAdapter
public <T> T getAdapter(Class<T> adapter)
Description copied from interface:IAdaptable
Returns an object which is an instance of the given class associated with this object. Returnsnull
if no such object can be found.Clients may implement this method but should generally call
Adapters.adapt(Object, Class, boolean)
rather than invoking it directly.- Specified by:
getAdapter
in interfaceIAdaptable
- Type Parameters:
T
- the class type- Parameters:
adapter
- the adapter class to look up- Returns:
- a object of the given class,
or
null
if this object does not have an adapter for the given class
-
kindToString
public static String kindToString(int kind)
A helper method that returns a displayable (i.e. externalized) string describing the provided sync kind.- Parameters:
kind
- the sync kind obtained from aSyncInfo
- Returns:
- a displayable string that describes the kind
-
init
public final void init() throws TeamException
Method that is invoked after instance creation to initialize the sync kind. This method should only be invoked by the creator of theSyncInfo
instance. It is not done from the constructor in order to allow subclasses to calculate the sync kind from any additional state variables they may have.- Throws:
TeamException
- if there were problems calculating the sync state.
-
calculateKind
protected int calculateKind() throws TeamException
Method that is invoked from theinit()
method to calculate the sync kind for this instance ofSyncInfo
. The result is assigned to an instance variable and is available usinggetKind()
. Subclasses should not invoke this method but may override it in order to customize the sync kind calculation algorithm.- Returns:
- the sync kind of this
SyncInfo
- Throws:
TeamException
- if there were problems calculating the sync state.
-
-