org.electrocodeogram.cpc.similarity.api.strategy
Interface ISimilarityStrategyTask


public interface ISimilarityStrategyTask

Parameter value for ISimilarityStrategy.calculateSimilarity(org.electrocodeogram.cpc.core.api.provider.store.IStoreProvider, ISimilarityStrategyTask).

Author:
vw

Field Summary
static int PROCESSING_STATUS_FILTERED
          Set once an ISimilarityStrategy has filtered out parts of the the processed contents.
static int PROCESSING_STATUS_NORMALISED_IDENTIFIERS
          Set once an ISimilarityStrategy has normalised identifiers of the processed contents.
static int PROCESSING_STATUS_NORMALISED_WHITESPACE
          Set once an ISimilarityStrategy has normalised white spaces of the processed contents.
 
Method Summary
 void addScore(double score, double weight)
          This method may be called only once per strategy.
 int getAverageScore()
          Retrieves the current average weighted score of all strategies which have been executed for this task.
 IClone getClone1()
          Retrieves the first clone for this comparison.
 IClone getClone2()
          Retrieves the second clone for this comparison.
 java.lang.String getLanguage()
          Retrieves the language for the given clone fragments.
 java.lang.String getProcessedContent1()
          Retrieves the processed/normalised content for clone1.
 java.lang.String getProcessedContent2()
          Retrieves the processed/normalised content for clone2.
 int getProcessingStatus()
          Retrieves the processing status of the two processed content strings.
 boolean isForceNonEqual()
          Whether the final similarity between the two clones needs to be capped at 99%.
 void markForceNonEqual()
          A strategy has to call this method if it detects any semantic difference between the two code fragments.
 void setProcessedContent1(java.lang.String processedContent1, int processingStatus)
          Updates the processed/normalised content for clone1.
 void setProcessedContent2(java.lang.String processedContent2, int processingStatus)
          Updates the processed/normalised content for clone2.
 

Field Detail

PROCESSING_STATUS_FILTERED

static final int PROCESSING_STATUS_FILTERED
Set once an ISimilarityStrategy has filtered out parts of the the processed contents. I.e. comments.

See Also:
Constant Field Values

PROCESSING_STATUS_NORMALISED_WHITESPACE

static final int PROCESSING_STATUS_NORMALISED_WHITESPACE
Set once an ISimilarityStrategy has normalised white spaces of the processed contents.

See Also:
Constant Field Values

PROCESSING_STATUS_NORMALISED_IDENTIFIERS

static final int PROCESSING_STATUS_NORMALISED_IDENTIFIERS
Set once an ISimilarityStrategy has normalised identifiers of the processed contents.

See Also:
Constant Field Values
Method Detail

addScore

void addScore(double score,
              double weight)
This method may be called only once per strategy.

Parameters:
score -
weight -

isForceNonEqual

boolean isForceNonEqual()
Whether the final similarity between the two clones needs to be capped at 99%.
This is required to adhere to the ISimilarityProvider API specification which states that a similarity of 100% must only be returned if the two code sections are guaranteed to be semantically equivalent.
If this value is true, some strategy detected a violation of that semantic equivalence.

Returns:
true if this task must never return 100, false otherwise.

markForceNonEqual

void markForceNonEqual()
A strategy has to call this method if it detects any semantic difference between the two code fragments.
Once set, this flag can't be unset.

See Also:
isForceNonEqual()

getAverageScore

int getAverageScore()
Retrieves the current average weighted score of all strategies which have been executed for this task.
Guaranteed to never return 100 if isForceNonEqual() is true.

Returns:
weighted, average score as integer between 0 and 100.

getLanguage

java.lang.String getLanguage()
Retrieves the language for the given clone fragments.

Returns:
the language for the given clone fragments, as specified by ISimilarityProvider, never null.

getClone1

IClone getClone1()
Retrieves the first clone for this comparison.
The returned clone object may not be modified in any way.

Returns:
first clone, never null.

getClone2

IClone getClone2()
Retrieves the second clone for this comparison.
The returned clone object may not be modified in any way.

Returns:
second clone, never null.

getProcessingStatus

int getProcessingStatus()
Retrieves the processing status of the two processed content strings.
The value is a bit mask, comprised of PROCESSING_STATUS_* values.

Returns:
current processing status bit mask for both content strings.
See Also:
setProcessedContent1(String, int)

getProcessedContent1

java.lang.String getProcessedContent1()
Retrieves the processed/normalised content for clone1.
This value may be updated by each strategy in turn.

Returns:
the current processed content for clone1, never null.

setProcessedContent1

void setProcessedContent1(java.lang.String processedContent1,
                          int processingStatus)
Updates the processed/normalised content for clone1.
Strategies may only update this value. The value of IClone.getContent() may not be modified.

Parameters:
processedContent1 - the new content for clone1, never null.
processingStatus - bit mask which indicates the kinds of modifications made to the content, data is additive. There is no need to pass through bits set earlier. Bits can't be unset. There is one bit mask for both contents.

getProcessedContent2

java.lang.String getProcessedContent2()
Retrieves the processed/normalised content for clone2.

See Also:
SimilarityStrategyTask.getProcessedContent1()

setProcessedContent2

void setProcessedContent2(java.lang.String processedContent2,
                          int processingStatus)
Updates the processed/normalised content for clone2.

See Also:
setProcessedContent1(String, int)