org.unitils.dbmaintainer.version
Class Version

java.lang.Object
  extended by org.unitils.dbmaintainer.version.Version
All Implemented Interfaces:
Comparable<Version>

public class Version
extends Object
implements Comparable<Version>

Class representing the version of a database or the version of a script.

A version is represented by a modification timestamp and a list of version indexes. The indexes should be defined as follows:

01_folder/01_subfolder/1_script ==> 1,1,1
01_folder/02_subfolder/1_script ==> 1,2,1
01_folder/02_subfolder/script ==> 1,2,null
folder/subfolder/2_script ==> null,null,2
script ==> null

The last index should always be the index of the script.

Author:
Filip Neven, Tim Ducheyne

Constructor Summary
Version(List<Long> indexes)
          Creates a new version.
Version(String indexString)
          Creates a new version.
 
Method Summary
 int compareTo(Version otherVersion)
          Compares the given version to this version using the index values.
 boolean equals(Object obj)
           
protected  List<Long> extractIndexes(String indexString)
          Extracts the indexes out of the given string as followes: 1.x.2.x => 1, null, 2, null
 List<Long> getIndexes()
          An empty list if no version is defined.
 String getIndexesString()
          Gets a string representation of the indexes as followes: 1, null, 2, null => 1.x.2.x
 Long getScriptIndex()
          Gets the last index in the list.
 int hashCode()
           
 void setIndexes(List<Long> indexes)
          Sets the indexes.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Version

public Version(List<Long> indexes)
Creates a new version.

Parameters:
indexes - The script indexes, not null
timeStamp - The script timestamp

Version

public Version(String indexString)
Creates a new version.

Parameters:
indexString - The indexes as a string
Method Detail

getIndexes

public List<Long> getIndexes()
An empty list if no version is defined.

Returns:
The script index, not null

getScriptIndex

public Long getScriptIndex()
Gets the last index in the list.

Returns:
The last index, null if there is no last index

setIndexes

public void setIndexes(List<Long> indexes)
Sets the indexes. Use an empty list if no version is defined.

Parameters:
indexes - The script indexes, not null

getIndexesString

public String getIndexesString()
Gets a string representation of the indexes as followes: 1, null, 2, null => 1.x.2.x

Returns:
The string, not null

extractIndexes

protected List<Long> extractIndexes(String indexString)
Extracts the indexes out of the given string as followes: 1.x.2.x => 1, null, 2, null

Parameters:
indexString - The string
Returns:
The list of longs or nulls in case of 'x'

toString

public String toString()
Overrides:
toString in class Object
Returns:
The string representation of the version.

compareTo

public int compareTo(Version otherVersion)
Compares the given version to this version using the index values.

If both scripts have an index, the index is used. If one of the scripts has an index, it is considerer lower than the script that does not have an index.

Specified by:
compareTo in interface Comparable<Version>
Parameters:
otherVersion - The other version, not null
Returns:
-1 when this version is smaller, 0 if equal, 1 when larger

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object


Copyright © 2011. All Rights Reserved.