net.sf.ext.helliker.id3
Class MP3Comparator

java.lang.Object
  extended bynet.sf.ext.helliker.id3.MP3Comparator
All Implemented Interfaces:
java.util.Comparator

public class MP3Comparator
extends java.lang.Object
implements java.util.Comparator

Description: This class is a comparator that is ideal for sorting mp3s. The MP3File class uses this object to implement its compareTo method. This works really well for playlists too because it has an order of precedence that attempts to sort the mp3s so that the tracks of the same artists and albums are together and that they are sorted by track number. If an error occurs while doing the comparison, the paths of the mp3s are compared.

Version History
1.3.1 - 2002.1023 by gruni
-Made Sourcecode compliant to the Sun CodingConventions
1.3 - 2002.0127 by helliker
-Title not a factor when sorting now.
1.2 - 2001.1019 by helliker
-All set for release.

Version:
1.3.1
Author:
Jonathan Hilliker

Constructor Summary
MP3Comparator()
           
 
Method Summary
 int compare(java.lang.Object o1, java.lang.Object o2)
          Compares the objects.
 boolean equals(java.lang.Object obj)
          Returns true if the specified object is an MP3Comparator
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MP3Comparator

public MP3Comparator()
Method Detail

equals

public boolean equals(java.lang.Object obj)
Returns true if the specified object is an MP3Comparator

Specified by:
equals in interface java.util.Comparator
Parameters:
obj - the object to test
Returns:
true if the object is an MP3Comparator

compare

public int compare(java.lang.Object o1,
                   java.lang.Object o2)
Compares the objects. Non-MP3File objects will always be less then an MP3File object and if neither objects are MP3Files then they are considered equal. A series of tests are conducted to determine the the outcome. First the artist is tested, then the album, then the track, then the title, then the path.

Specified by:
compare in interface java.util.Comparator
Parameters:
o1 - one object to compare
o2 - another object to compare
Returns:
a positive number if o1 > o2, zero if o1 = o2, and a negative number if o1 < o2