From: <ga...@us...> - 2009-02-09 15:42:48
|
Revision: 5014 http://jnode.svn.sourceforge.net/jnode/?rev=5014&view=rev Author: galatnm Date: 2009-02-09 15:42:45 +0000 (Mon, 09 Feb 2009) Log Message: ----------- Simplify compare method. Modified Paths: -------------- trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogKey.java Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogKey.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogKey.java 2009-02-09 15:41:40 UTC (rev 5013) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogKey.java 2009-02-09 15:42:45 UTC (rev 5014) @@ -53,9 +53,11 @@ } /** + * Create catalog key based on parent CNID and the name of the file or folder. * - * @param parentID - * @param name + * @param parentID Parent catalog node identifier. + * @param name Name of the file or folder. + * */ public CatalogKey(final CatalogNodeId parentID, final HFSUnicodeString name) { this.parentID = parentID; @@ -75,22 +77,30 @@ return nodeName; } - public final int compareTo(final Key o) { - if (o instanceof CatalogKey) { - CatalogKey ck = (CatalogKey) o; - if (getParentId().getId() == ck.getParentId().getId()) { - return nodeName.getUnicodeString().compareTo( + /** + * Compare two catalog keys. These keys are compared by parent id and next + * by node name. + * + * @param key + * + */ + public final int compareTo(final Key key) { + int res = -1; + if (key instanceof CatalogKey) { + CatalogKey ck = (CatalogKey) key; + res = this.getParentId().compareTo(ck.getParentId()); + if (res == 0) { + res = this.getNodeName().getUnicodeString().compareTo( ck.getNodeName().getUnicodeString()); - } else if (getParentId().getId() < ck.getParentId().getId()) { - return -1; - } else { - return 1; } - } else { - return -1; } + return res; } + /* + * (non-Javadoc) + * @see org.jnode.fs.hfsplus.tree.AbstractKey#getBytes() + */ public byte[] getBytes() { byte[] data = new byte[this.getKeyLength()]; BigEndian.setInt16(data, 0, this.getKeyLength()); @@ -99,6 +109,10 @@ return data; } + /* + * (non-Javadoc) + * @see java.lang.Object#toString() + */ public final String toString() { StringBuffer s = new StringBuffer(); s.append("[length, Parent ID, Node name]:").append(getKeyLength()).append(",").append(getParentId().getId()) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |