org.japtproxy.packages
Class AbstractRepoPackageVersionComparator

java.lang.Object
  extended by org.japtproxy.packages.AbstractRepoPackageVersionComparator
All Implemented Interfaces:
java.util.Comparator<java.lang.String>
Direct Known Subclasses:
DebianPackageVersionComparator, RpmPackageVersionComparator

public abstract class AbstractRepoPackageVersionComparator
extends java.lang.Object
implements java.util.Comparator<java.lang.String>

The VersionComparator is responsible for comparing package versions. This is required for sorting a list of packages from the same program with different versions.

The algorithm used in this class was borrowed from vercmp.c in libdpkg which is written by Ian Jackson.

Version:
$LastChangedRevision: 116 $
Author:
Oliver J. Siegmar

Field Summary
protected static org.slf4j.Logger LOG
          The logger instance.
protected static int NON_ASCII_OFFSET
          Non ASCII offset constant.
 
Constructor Summary
AbstractRepoPackageVersionComparator()
           
 
Method Summary
 int compare(java.lang.String f1, java.lang.String f2)
          Compares two packages based on the version and revision field.
protected abstract  int order(char[] ca, int pos)
          Returns the order for a single character.
 void setRepoPackageFactory(IRepoPackageFactory repoPackageFactory)
           
protected  int strCompare(java.lang.String s1, java.lang.String s2)
          Compares two version strings and returns and int that specifies the order.
 
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

LOG

protected static final org.slf4j.Logger LOG
The logger instance.


NON_ASCII_OFFSET

protected static final int NON_ASCII_OFFSET
Non ASCII offset constant.

See Also:
Constant Field Values
Constructor Detail

AbstractRepoPackageVersionComparator

public AbstractRepoPackageVersionComparator()
Method Detail

setRepoPackageFactory

public void setRepoPackageFactory(IRepoPackageFactory repoPackageFactory)

order

protected abstract int order(char[] ca,
                             int pos)
Returns the order for a single character.

Parameters:
ca - the character array
pos - the position in the character array
Returns:
the order for the given character

strCompare

protected int strCompare(java.lang.String s1,
                         java.lang.String s2)
Compares two version strings and returns and int that specifies the order.

Parameters:
s1 - version string 1
s2 - version string 2
Returns:
the order

compare

public int compare(java.lang.String f1,
                   java.lang.String f2)
Compares two packages based on the version and revision field.

Specified by:
compare in interface java.util.Comparator<java.lang.String>
Parameters:
f1 - file1
f2 - file2
Returns:
0 if both packages have the same version (should not happen), 1 if f1 is more recent than f2, otherwise -1


Copyright © 2006-2008. All Rights Reserved.