org.sonar.duplications.detector
Class ContainsInComparator

java.lang.Object
  extended by org.sonar.duplications.detector.ContainsInComparator
All Implemented Interfaces:
Comparator<ClonePart>

public final class ContainsInComparator
extends Object
implements Comparator<ClonePart>

Allows to determine if ClonePart includes another ClonePart. Inclusion is the partial order, so in fact this class violates contracts of Comparator, however it allows to use SortedListsUtils for efficient filtering.


Field Summary
static Comparator<ClonePart> CLONEPART_COMPARATOR
          Defines order by resourceId and by unitStart.
static Comparator<ClonePart> RESOURCE_ID_COMPARATOR
          Defines order by resourceId.
 
Constructor Summary
ContainsInComparator(int l1, int l2)
          Constructs new comparator for two parts with lengths l1 and l2 respectively.
 
Method Summary
 int compare(ClonePart part1, ClonePart part2)
          Compares two parts on inclusion.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Comparator
equals
 

Field Detail

RESOURCE_ID_COMPARATOR

public static final Comparator<ClonePart> RESOURCE_ID_COMPARATOR
Defines order by resourceId.


CLONEPART_COMPARATOR

public static final Comparator<ClonePart> CLONEPART_COMPARATOR
Defines order by resourceId and by unitStart.

Constructor Detail

ContainsInComparator

public ContainsInComparator(int l1,
                            int l2)
Constructs new comparator for two parts with lengths l1 and l2 respectively.

Method Detail

compare

public int compare(ClonePart part1,
                   ClonePart part2)
Compares two parts on inclusion. part1 includes part2 if (part1.resourceId == part2.resourceId) && (part1.unitStart <= part2.unitStart) && (part2.unitEnd <= part1.unitEnd).

Specified by:
compare in interface Comparator<ClonePart>
Returns:
0 if part1 includes part2, 1 if resourceId of part1 is greater than resourceId of part2 or if unitStart of part1 is greater than unitStart of part2, -1 in all other cases


Copyright © 2009-2012 SonarSource. All Rights Reserved.