/** * Searches the database for {@link ObjectId}s that match the given partial id. * * @param partialId the partial id to search for * @return a list of matching results * @see org.locationtech.geogig.storage.ObjectDatabase#lookUp(java.lang.String) */ @Override public List<ObjectId> lookUp(final String partialId) { checkNotNull(partialId, "argument partialId is null"); checkArgument(partialId.length() > 7, "partial id must be at least 8 characters long: ", partialId); checkState(isOpen(), "db is closed"); byte[] raw = ObjectId.toRaw(partialId); List<ObjectId> baseResults = lookUpInternal(raw); // If the length of the partial string is odd, then the last character wasn't considered in // the lookup, we need to filter the list further. if (partialId.length() % 2 != 0) { Iterator<ObjectId> listIterator = baseResults.iterator(); while (listIterator.hasNext()) { ObjectId lookupMatchCandidate = listIterator.next(); if (!lookupMatchCandidate.toString().startsWith(partialId)) { listIterator.remove(); } } } return baseResults; }
/** * Searches the database for {@link ObjectId}s that match the given partial id. * * @param partialId the partial id to search for * @return a list of matching results * @see org.locationtech.geogig.storage.ObjectDatabase#lookUp(java.lang.String) */ @Override public List<ObjectId> lookUp(final String partialId) { checkNotNull(partialId, "argument partialId is null"); checkArgument(partialId.length() > 7, "partial id must be at least 8 characters long: ", partialId); checkState(isOpen(), "db is closed"); byte[] raw = ObjectId.toRaw(partialId); List<ObjectId> baseResults = lookUpInternal(raw); // If the length of the partial string is odd, then the last character wasn't considered in // the lookup, we need to filter the list further. if (partialId.length() % 2 != 0) { Iterator<ObjectId> listIterator = baseResults.iterator(); while (listIterator.hasNext()) { ObjectId result = listIterator.next(); if (!result.toString().startsWith(partialId)) { listIterator.remove(); } } } return baseResults; }
config.checkRepositoryExists(); final int hash1 = PGId.intHash(ObjectId.toRaw(partialId)); final String sql = format( "SELECT ((id).h2), ((id).h3) FROM %s WHERE ((id).h1) = ? LIMIT 1000",
@Test public void testToRaw() { byte bytes[] = new byte[] { (byte) 0xff, (byte) 0x68, (byte) 0xb7, (byte) 0x47, (byte) 0x66, (byte) 0xe2, (byte) 0x0c, (byte) 0xca }; byte bytes2[] = ObjectId.toRaw("ff68b74766e20cca"); assertTrue(Arrays.equals(bytes, bytes2)); boolean caughtException = false; try { ObjectId.toRaw("r"); } catch (IllegalArgumentException e) { caughtException = true; } assertTrue(caughtException); }