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. The IResourceVariantComparator is used to decide which comparison type to use.

For two-way comparisons, a SyncInfo node has a change type. This will be one of IN-SYNC, ADDITION, DELETION or CHANGE 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 or CONFLICTING. 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.
Again, the comparison of resources is done using the variant comparator provided when the sync info was created.
Since:
3.0
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Sync constant (value 1) indicating that one side was added.
    static final int
    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 final int
    Sync constant (value 3) indicating that one side was changed.
    static final int
    Bit mask for extracting the change type.
    static final int
    Sync constant (value 12) indicating a change to both the remote and local resources.
    static final int
    Sync constant (value 2) indicating that one side was deleted.
    static final int
    Bit mask for extracting the synchronization direction.
    static final int
    Sync constant (value 0) indicating element is in sync.
    static final int
    Sync constant (value 8) indicating a change to the remote resource.
    static final int
    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 final int
    Sync constant (value 4) indicating a change to the local resource.
    static final int
    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
    Construct a sync info object.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected int
    Method that is invoked from the init() method to calculate the sync kind for this instance of SyncInfo.
    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.
    Returns the remote resource handle for the base resource, or null if the base resource does not exist.
    static int
    getChange(int kind)
    Helper method to return the change portion of the given kind.
    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
    Returns the kind of synchronization for this node.
    Returns the state of the local resource.
    Returns the author of the revision corresponding to the local resource or null if it doesn't have one.
    Returns the content identifier for the local resource or null if it doesn't have one.
    Returns the handle for the remote resource, or null if the remote resource does not exist.
    int
     
    final void
    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.
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • IN_SYNC

      public static final int IN_SYNC
      Sync constant (value 0) indicating element is in sync.
      See Also:
    • ADDITION

      public static final int ADDITION
      Sync constant (value 1) indicating that one side was added.
      See Also:
    • DELETION

      public static final int DELETION
      Sync constant (value 2) indicating that one side was deleted.
      See Also:
    • CHANGE

      public static final int CHANGE
      Sync constant (value 3) indicating that one side was changed.
      See Also:
    • CHANGE_MASK

      public static final int CHANGE_MASK
      Bit mask for extracting the change type.
      See Also:
    • OUTGOING

      public static final int OUTGOING
      Sync constant (value 4) indicating a change to the local resource.
      See Also:
    • INCOMING

      public static final int INCOMING
      Sync constant (value 8) indicating a change to the remote resource.
      See Also:
    • CONFLICTING

      public static final int CONFLICTING
      Sync constant (value 12) indicating a change to both the remote and local resources.
      See Also:
    • DIRECTION_MASK

      public static final int DIRECTION_MASK
      Bit mask for extracting the synchronization direction.
      See Also:
    • 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:
    • 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:
    • 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:
  • Constructor Details

    • 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 or null
      remote - the remote resource variant or null
      comparator - the comparator used to determine if resources differ
  • Method Details

    • 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 or null 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 or null 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, or null 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, or null 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 a SyncInfo
      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 a SyncInfo
      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 a SyncInfo
      Returns:
      the change portion of the kind
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • 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. Returns null 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 interface IAdaptable
      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
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • 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 a SyncInfo
      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 the SyncInfo 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 the init() method to calculate the sync kind for this instance of SyncInfo. The result is assigned to an instance variable and is available using getKind(). 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.