Faceted Project Framework
Version 1.3

org.eclipse.wst.common.project.facet.core
Class DefaultVersionComparator

java.lang.Object
  extended by org.eclipse.wst.common.project.facet.core.DefaultVersionComparator
All Implemented Interfaces:
Comparator<String>

public class DefaultVersionComparator
extends Object
implements Comparator<String>

The default version comparator that will be used when one is not explicitly specified. The default version comparator can handle version strings using the standard decimal notation. It can also be subclassed to modify the separators that are used or to provide custom parsing for a version segment.

Author:
Konstantin Komissarchik

Constructor Summary
DefaultVersionComparator()
           
 
Method Summary
 int compare(String obj1, String obj2)
           
protected  String getSeparators()
          Returns the string containing the separator characters that should be used when breaking the version string into segments.
protected  Comparable<? extends Object> parse(String version, String segment, int position)
          Parses a segment of the version string.
 
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
 

Constructor Detail

DefaultVersionComparator

public DefaultVersionComparator()
Method Detail

compare

public final int compare(String obj1,
                         String obj2)
                  throws VersionFormatException
Specified by:
compare in interface Comparator<String>
Throws:
VersionFormatException

getSeparators

protected String getSeparators()
Returns the string containing the separator characters that should be used when breaking the version string into segments. The default implementation returns ".". Subclasses can override this method.

Returns:
the separator characters

parse

protected Comparable<? extends Object> parse(String version,
                                             String segment,
                                             int position)
                                      throws VersionFormatException
Parses a segment of the version string. The default implementation parses the first segment as an integer (leading zeroes are ignored) and the rest of the segments as decimals (leading zeroes are kept). Subclasses can override this method to provide custom parsing for any number of segments.

Parameters:
version - the full version string
segment - the version segment
position - the position of the segment in the version string
Returns:
the parsed representation of the segment as a Comparable
Throws:
VersionFormatException - if encountered an error while parsing

Faceted Project Framework
Version 1.3

Copyright (c) 2008 BEA Systems, Inc. and others. All rights reserved.