Class Checksummer<T>
java.lang.Object
com.atlassian.jira.functest.config.Checksummer<T>
- Type Parameters:
T- The type of object to be hashed.
Keeps the checksums of a group of objects of type T.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceHelps with the conversion of T into and from its different forms needed for the operation of the checksummer. -
Constructor Summary
ConstructorsConstructorDescriptionChecksummer(Checksummer.Helper<T> helper) Create a checksummer that uses the passed helper to covert T to and from a form that allows it to be serialized.Checksummer(Checksummer.Helper<T> helper, String defaultSum) Create a checksummer that uses the passed helper to convert T to and from a form that allows it to be serialized. -
Method Summary
Modifier and TypeMethodDescriptionstatic Checksummer<File>fileChecksummer(String hash) Static factory method that will create a checksum that storesFileobjects by hashing their contents.Return the hash algorithm used when adding new objects to the checkum.booleanhasChanged(T object) Tells the caller if the passed object has a hash the same as the one already stored in the checksum.booleanReturn true if the checksummer was modified sincewrite(org.dom4j.Element)was called, false otherwise.voidread(org.dom4j.Element element) Read the checksummer state as was previously saved usingwrite(org.dom4j.Element).booleanRemove the passed object and its hash from checksummer.voidsetDefaultSum(String defaultSum) Set the default hash algorithm used when adding new objects.booleanUpdate the current state of the passed object with its current hash.voidwrite(org.dom4j.Element checkElement) Write the current state of the checksummer to the passed element.
-
Constructor Details
-
Checksummer
Create a checksummer that uses the passed helper to covert T to and from a form that allows it to be serialized.- Parameters:
helper- the helper this checksum will use to process instances of T.
-
Checksummer
Create a checksummer that uses the passed helper to convert T to and from a form that allows it to be serialized. The checksum will use the passed hashing algorithm for any new objects added to the checksum.- Parameters:
helper- the helper this checksum will use to process instance of T.defaultSum- the checksum used to add any new objects.
-
-
Method Details
-
fileChecksummer
Static factory method that will create a checksum that storesFileobjects by hashing their contents. This can be used to find out quickly from a set of files which have changed.- Parameters:
hash- the checksum oused to add any new objects.- Returns:
- a checkum of the contents of
Fileobjects.
-
getDefaultSum
Return the hash algorithm used when adding new objects to the checkum.- Returns:
- the hash algorithm used when added new objects to the checksum.
-
setDefaultSum
Set the default hash algorithm used when adding new objects.- Parameters:
defaultSum- the default hash algorithm used when adding new objects.
-
hasChanged
Tells the caller if the passed object has a hash the same as the one already stored in the checksum. This gives a good indication whether the passed object has changed since it was added to the checksum.The method will return true if the passed object has not already been added to the checksum.
- Parameters:
object- the object to test.- Returns:
- if the object has the same hash as when it was added to the checksum.
-
isModified
public boolean isModified()Return true if the checksummer was modified sincewrite(org.dom4j.Element)was called, false otherwise.- Returns:
- true if the checksummer was modified since
write(org.dom4j.Element)was called, false otherwise.
-
update
Update the current state of the passed object with its current hash. This will add the passed object to the checksum if it has not already been added.- Parameters:
object- the object to update or add.- Returns:
- true if the object's hash was changed, false otherwise. Note that true will always be returned when adding new objects.
-
remove
Remove the passed object and its hash from checksummer.- Parameters:
object- the object to remove from the checksummer.- Returns:
- true if the object is removed, false otherwise
-
read
public void read(org.dom4j.Element element) Read the checksummer state as was previously saved usingwrite(org.dom4j.Element).- Parameters:
element- the element where the configuration is stored.
-
write
public void write(org.dom4j.Element checkElement) Write the current state of the checksummer to the passed element. The checksummer can later be reconstructed by callingread(org.dom4j.Element).- Parameters:
checkElement- the element to write the state to.
-