@Test public void testKeyFromBytesArray() { CatalogKey key = new CatalogKey(KEY_AS_BYTES_ARRAY, 0); assertEquals(NODE_NAME_AS_STRING, key.getNodeName().getUnicodeString()); assertEquals(26, key.getKeyLength()); assertEquals(7, key.getParentId().getId()); }
@Test public void testConstructFromCNIDAndEmptyString() { CatalogNodeId id = CatalogNodeId.HFSPLUS_START_CNID; HfsUnicodeString string = new HfsUnicodeString(""); CatalogKey key = new CatalogKey(id, string); assertEquals("", key.getNodeName().getUnicodeString()); assertEquals(8, key.getKeyLength()); assertEquals(7, key.getParentId().getId()); }
@Test public void testConstructFromCNIDAndString() { CatalogNodeId id = CatalogNodeId.HFSPLUS_START_CNID; HfsUnicodeString string = new HfsUnicodeString(NODE_NAME_AS_STRING); CatalogKey key = new CatalogKey(id, string); assertEquals(NODE_NAME_AS_STRING, key.getNodeName().getUnicodeString()); assertEquals(24, key.getKeyLength()); assertEquals(7, key.getParentId().getId()); }
/** * 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) { // Note: this is unlikely to be correct. See TN1150 section "Unicode Subtleties" for details // For reading in data is should be safe since the B-Tree will be pre-sorted, but for adding // new entries // it will cause the order to be wrong. res = this.getNodeName().getUnicodeString().compareTo(ck.getNodeName().getUnicodeString()); } } return res; }