public BucketId getBucketIdForType(ClientParameters.SelectionType type, String id) throws BucketStatsException {
        switch (type) {
            case DOCUMENT:
                return bucketIdFactory.getBucketId(new DocumentId(id));
            case BUCKET:
                // The internal parser of BucketID is used since the Java Long.decode cannot handle unsigned longs.
                return new BucketId(String.format("BucketId(%s)", id));
            case GID:
                return convertGidToBucketId(id);
            case USER:
            case GROUP:
                try {
                    BucketSet bucketList = selector.getBucketList(createDocumentSelection(type, id));
                    if (bucketList.size() != 1) {
                        String message = String.format("Document selection must map to only one location. " +
                                "Specified selection matches %d locations.", bucketList.size());
                        throw new BucketStatsException(message);
                    }
                    return bucketList.iterator().next();
                } catch (ParseException e) {
                    throw new BucketStatsException(String.format("Invalid id: %s (%s).", id, e.getMessage()), e);
                }
            default:
                throw new RuntimeException("Unreachable code");
        }
    }
@Test
    void testGetBucketId() throws BucketStatsException {
        BucketStatsRetriever retriever = createRetriever();

        assertEquals("BucketId(0x80000000000004d2)",
                retriever.getBucketIdForType(ClientParameters.SelectionType.USER, "1234").toString());
        assertEquals("BucketId(0x800000003a7455d7)",
                retriever.getBucketIdForType(ClientParameters.SelectionType.GROUP, "mygroup").toString());
        assertEquals("BucketId(0x800000003a7455d7)",
                retriever.getBucketIdForType(ClientParameters.SelectionType.BUCKET, "0x800000003a7455d7").toString());
        assertEquals("BucketId(0xeb018ac5e5732db3)",
                retriever.getBucketIdForType(ClientParameters.SelectionType.DOCUMENT, "id:ns:type::another").toString());
        assertEquals("BucketId(0xeadd5fe811a2012c)",
                retriever.getBucketIdForType(ClientParameters.SelectionType.GID, "0x2c01a21163cb7d0ce85fddd6").toString());
    }