org.egothor.duplicity.file
Class SimilarUnitPairsFileProducer

java.lang.Object
  extended by org.egothor.duplicity.file.SimilarUnitPairsFileProducer

public class SimilarUnitPairsFileProducer
extends java.lang.Object

Represents the "similar unit pairs" file used in duplicity checking algorithm, before if was written to the filesystem. Allows producing new instances of SimilarUnitPairsFile and SimilarUnitPairsTempFile classes. The file contains instances of UnitPair class. That means it contains pairs {first, second}, where first, second are identificators of units on which we check duplicity (can be document, paragraph or sentence). The class should be used as follows.

  1. The class must be constructed by its constructor.
  2. Unit pairs can be added by a call to add(org.egothor.duplicity.datastructure.TextUnitID, org.egothor.duplicity.datastructure.TextUnitID).
  3. Committing barrels by a call to commit(java.lang.String) (or commitTemp(java.lang.String)) sorts and writes data to filesystem and returns instance of SimilarUnitPairsFile (or SimilarUnitPairsTempFile) class.

Author:
Kate�ina Dufkov�

Constructor Summary
SimilarUnitPairsFileProducer(long permID)
          Initializes the object.
 
Method Summary
 void add(TextUnitID first, TextUnitID second)
          Adds new UnitPair to the file.
 SimilarUnitPairsFile commit(java.lang.String location)
          Commit the changes in the buffer to filesystem file.
 SimilarUnitPairsTempFile commitTemp(java.lang.String location)
          Commit the changes in the buffer to temporary filesystem file.
 java.util.List<UnitPair> getBuffer()
           
 long getPermID()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SimilarUnitPairsFileProducer

public SimilarUnitPairsFileProducer(long permID)
Initializes the object.

Parameters:
permID - permutation assigned to this file
Method Detail

getBuffer

public java.util.List<UnitPair> getBuffer()

getPermID

public long getPermID()

add

public void add(TextUnitID first,
                TextUnitID second)
Adds new UnitPair to the file. Asserts that only pairs {first, second} where first < second are inserted. For a pair that does not satisfy the condition method switches its parameters and adds {second, first} pair instead. It does NOT need to create an own copy of arguments because the arguments are immutable.

Parameters:
first - first unit id for the UnitPair object to be added
second - second unit id for the UnitPair object to be added

commit

public SimilarUnitPairsFile commit(java.lang.String location)
Commit the changes in the buffer to filesystem file.

Parameters:
location - location to which the file should be written
Returns:
instance of regular SimilarUnitPairsFile representing the file

commitTemp

public SimilarUnitPairsTempFile commitTemp(java.lang.String location)
Commit the changes in the buffer to temporary filesystem file.

Parameters:
location - location to which the file should be written
Returns:
instance of temporary SimilarUnitPairsTempFile representing the file

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object