org.eclipse.wst.common.project.facet.core
Class DefaultVersionComparator
java.lang.Object
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
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
DefaultVersionComparator
public DefaultVersionComparator()
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 stringsegment
- the version segmentposition
- 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
Copyright (c) 2008 BEA Systems, Inc. and others. All rights reserved.