Package com._1c.g5.v8.dt.compare.core
Class ComparisonUtils
- java.lang.Object
-
- com._1c.g5.v8.dt.compare.core.ComparisonUtils
-
public class ComparisonUtils extends Object
Utility methods used for comparison and merge.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ComparisonUtils.Sequence<U>
The sequence of elements.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
adoptImportedObjectSymlink(IComparisonSession session, String symlink)
Converts, if possible, the imported object symlink into a new one supported by the main side.static ComparisonFlags
compareStreams(InputStream main, InputStream other, InputStream ancestor, boolean isThreeWay)
Compares the given triple of streams.static ComparisonFlags
compareStreamsContent(InputStream main, InputStream other, InputStream ancestor)
Compares streams content byte by byte.static ComparisonContext
createComparisonContext(IComparisonSession session)
Creates a comparison context with read-only transactional access to the data sources.static ComparisonContext
createComparisonContext(IComparisonSession session, boolean comparisonModelWriteEnabled)
Creates a comparison context with read-only transactional access to the data sources and to the comparison model.static ComparisonContext
createComparisonContext(IComparisonSession session, IBmTransaction mainDataSourceMergeTransaction)
Creates a comparison context with transactional access to the data sources.static ComparisonFlags
createComparisonFlagsForObjects(IComparedObjects<?> comparingObjects, boolean threeWay)
Creates and returns a comparison flags for the triple of compared objects and fills them with information about object presence on each comparison side.static <U> List<U>
getLongestCommonSubsequence(List<U> sequence1, List<U> sequence2)
Returns the longest common subsequence of the two specified sequences.static <U> List<U>
getLongestCommonSubsequence(List<U> sequence1, List<U> sequence2, List<U> sequence3)
Returns the longest common subsequence of the three specified sequences.static <U> List<U>
getLongestCommonSubsequenceMemoryOptimized(ComparisonUtils.Sequence<U> sequence1, ComparisonUtils.Sequence<U> sequence2, ComparisonUtils.Sequence<U> sequence3, BiFunction<U,U,Boolean> equalityFunction)
Returns the longest common subsequence of the three specified sequences.static String
getNameFromSymlink(String symlink)
Obtains object's name from the given object's symlink.static org.eclipse.xtext.scoping.IScopeProvider
getScopeProviderForExtension(String extension)
static boolean
hasConflictOrderChangesInCollection(Set<? extends IComparedObjects<?>> collectionElementsWithChangedOrderInAncestorMain, Set<? extends IComparedObjects<?>> collectionElementsWithChangedOrderInAncestorOther)
Detects conflict order changes in a collection in three-way comparison mode.static boolean
hasDeletionConflict(IComparedObjects<?> comparingObjects, ComparisonFlags flags)
Checks case when element was deleted on one side and modified on the other.static boolean
isComparisonModelEditable(ComparisonProcessStatus status)
Tell whether the comparison model is editable for the comparison handle with the given comparison process status.static boolean
isSubsymlinkOf(String originalSymlink, String testedSymlink)
Checks whether the tested symlink is subsymlink of the original symlink.static RestoredMergeSettings
readMergeSettings(String mergeSettingsFileName, IMergeSettingsSerializerService mergeSettingsSerializerService)
Reads merge settings from a file.static void
threeWayCheckDoubleChanges(ComparisonFlags flags)
Detects double changes according to the given comparison flags and updates them.static boolean
unequalAndNotNull(Object first, Object second)
Determines whether two objects are unequal and both non-null.
-
-
-
Method Detail
-
compareStreams
public static ComparisonFlags compareStreams(InputStream main, InputStream other, InputStream ancestor, boolean isThreeWay) throws IOException
Compares the given triple of streams. Checks whether any stream isnull
and compares streams byte by byte. Does not close streams at the end.- Parameters:
main
- the main stream, may benull
other
- the other stream, may benull
ancestor
- the ancestor stream, may benull
isThreeWay
-true
if the data source comparison is three-way andfalse
if it is two-way- Returns:
- the comparison result, never
null
- Throws:
IOException
- if some other I/O error occurs while reading the streams
-
compareStreamsContent
public static ComparisonFlags compareStreamsContent(InputStream main, InputStream other, InputStream ancestor) throws IOException
Compares streams content byte by byte.- Parameters:
main
- the main stream, can benull
.other
- the other stream, can benull
.ancestor
- the ancestor stream, can benull
.- Returns:
- the resulting comparison flags, never
null
- Throws:
IOException
- if some other I/O error occurs while reading the streams
-
getScopeProviderForExtension
public static org.eclipse.xtext.scoping.IScopeProvider getScopeProviderForExtension(String extension)
-
getLongestCommonSubsequence
public static <U> List<U> getLongestCommonSubsequence(List<U> sequence1, List<U> sequence2)
Returns the longest common subsequence of the two specified sequences.- Type Parameters:
U
- the type of elements in the sequences- Parameters:
sequence1
- the first sequence, notnull
sequence2
- the second sequence, notnull
- Returns:
- the longest common subsequence, not
null
-
getLongestCommonSubsequence
public static <U> List<U> getLongestCommonSubsequence(List<U> sequence1, List<U> sequence2, List<U> sequence3)
Returns the longest common subsequence of the three specified sequences.- Type Parameters:
U
- the type of elements in the sequences- Parameters:
sequence1
- the first sequence, cannot benull
sequence2
- the second sequence, cannot benull
sequence3
- the third sequence, cannot benull
- Returns:
- the longest common subsequence of the three sequences, never
null
-
getLongestCommonSubsequenceMemoryOptimized
public static <U> List<U> getLongestCommonSubsequenceMemoryOptimized(ComparisonUtils.Sequence<U> sequence1, ComparisonUtils.Sequence<U> sequence2, ComparisonUtils.Sequence<U> sequence3, BiFunction<U,U,Boolean> equalityFunction)
Returns the longest common subsequence of the three specified sequences. Uses the memory optimized Hirschberg algorithm.- Type Parameters:
U
- the type of elements in the sequences- Parameters:
sequence1
- the first sequence, cannot benull
sequence2
- the second sequence, cannot benull
sequence3
- the third sequence, cannot benull
equalityFunction
- the function of equality of elements, may benull
- Returns:
- the longest common subsequence of the three sequences, never
null
-
isSubsymlinkOf
public static boolean isSubsymlinkOf(String originalSymlink, String testedSymlink)
Checks whether the tested symlink is subsymlink of the original symlink.- Parameters:
originalSymlink
- the original symlink, can not benull
testedSymlink
- the symlink to test, can not benull
- Returns:
true
if the tested symlink is subsymlink of the original symlink andfalse
otherwise
-
getNameFromSymlink
public static String getNameFromSymlink(String symlink)
Obtains object's name from the given object's symlink.- Parameters:
symlink
- the symlink to get name from, cannot benull
- Returns:
- the object's name, never
null
-
threeWayCheckDoubleChanges
public static void threeWayCheckDoubleChanges(ComparisonFlags flags)
Detects double changes according to the given comparison flags and updates them. Should be run only in threeway comparison mode. It is generally INCORRECT to call this method for combined comparison flags of parent nodes, because they contain flags from different children, while this method expects flags calculated just for one single node.- Parameters:
flags
- the comparison flags to check, cannot benull
-
adoptImportedObjectSymlink
public static String adoptImportedObjectSymlink(IComparisonSession session, String symlink)
Converts, if possible, the imported object symlink into a new one supported by the main side.- Parameters:
session
- the comparison session, cannot benull
symlink
- the imported object symlink to convert, cannot benull
- Returns:
- the converted symlink, never
null
-
unequalAndNotNull
public static boolean unequalAndNotNull(Object first, Object second)
Determines whether two objects are unequal and both non-null.- Parameters:
first
- the first object to check, may benull
second
- the second object to check, may benull
- Returns:
true
if both non-null and they are not equal according toObject.equals(Object)
, otherwise returnfalse
-
createComparisonFlagsForObjects
public static ComparisonFlags createComparisonFlagsForObjects(IComparedObjects<?> comparingObjects, boolean threeWay)
Creates and returns a comparison flags for the triple of compared objects and fills them with information about object presence on each comparison side.- Parameters:
comparingObjects
- the comparing objects to check comparison direction change for, cannot benull
threeWay
- tells whether the comparison is three-way or two-way- Returns:
- the comparison flags with information about object presence on each comparison side, never
null
-
createComparisonContext
public static ComparisonContext createComparisonContext(IComparisonSession session)
Creates a comparison context with read-only transactional access to the data sources. The transaction to the comparison model is not opened. Note that the caller is responsible to close the context after its usage.- Parameters:
session
- the comparison session to open the context for, cannot benull
- Returns:
- the comparison context instance, never
null
-
createComparisonContext
public static ComparisonContext createComparisonContext(IComparisonSession session, IBmTransaction mainDataSourceMergeTransaction)
Creates a comparison context with transactional access to the data sources. If the merge transaction is given, the context can be used on a merge phase to modify MAIN data source. The transaction to the comparison model is not opened. Note that the caller is responsible to close the context after its usage.- Parameters:
session
- the comparison session to open the context for, cannot benull
mainDataSourceMergeTransaction
- the active merge transaction to MAIN data source, can benull
- Returns:
- the comparison context instance, never
null
-
createComparisonContext
public static ComparisonContext createComparisonContext(IComparisonSession session, boolean comparisonModelWriteEnabled)
Creates a comparison context with read-only transactional access to the data sources and to the comparison model. Note that the caller is responsible to close the context after its usage.- Parameters:
session
- the comparison session to open the context for, cannot benull
comparisonModelWriteEnabled
- the flag indicating possibility to modify the comparison model- Returns:
- the comparison context instance, never
null
-
hasConflictOrderChangesInCollection
public static boolean hasConflictOrderChangesInCollection(Set<? extends IComparedObjects<?>> collectionElementsWithChangedOrderInAncestorMain, Set<? extends IComparedObjects<?>> collectionElementsWithChangedOrderInAncestorOther)
Detects conflict order changes in a collection in three-way comparison mode.- Parameters:
collectionElementsWithChangedOrderInAncestorMain
- the set of compared objects with order changes between ancestor and main sides, cannot benull
collectionElementsWithChangedOrderInAncestorOther
- the set of compared objects with order changes between ancestor and other sides, cannot benull
- Returns:
true
if the collection has conflict order changes,false
otherwise
-
hasDeletionConflict
public static boolean hasDeletionConflict(IComparedObjects<?> comparingObjects, ComparisonFlags flags)
Checks case when element was deleted on one side and modified on the other.- Parameters:
comparingObjects
- the comparing objects, cannot benull
flags
- the comparison flags calculated for the comparing objects, cannot benull
- Returns:
true
if the deletion conflict has been detected,false
otherwise
-
readMergeSettings
public static RestoredMergeSettings readMergeSettings(String mergeSettingsFileName, IMergeSettingsSerializerService mergeSettingsSerializerService) throws FileNotFoundException, IOException, InvalidPreferencesFormatException
Reads merge settings from a file.- Parameters:
mergeSettingsFileName
- merge settings file name, may benull
mergeSettingsSerializerService
- merge settings serializer service, cannot benull
- Returns:
- restored merge settings, can be
null
- Throws:
FileNotFoundException
- if the file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened forreadingIOException
- if an input/output operation was failed or interaptedInvalidPreferencesFormatException
- unsupported version of input file serialization format
-
isComparisonModelEditable
public static boolean isComparisonModelEditable(ComparisonProcessStatus status)
Tell whether the comparison model is editable for the comparison handle with the given comparison process status.- Parameters:
status
- the comparison process status, cannot benull
- Returns:
true
if the comparison model is editable,false
otherwise
-
-