class BlockManipulationServiceImpl implements IBlockManipulationService {

    @Override
    public String getNextBlockUuid(Metafile metafile)
            throws MetafileIsFolderException, BlockDoesNotExistException {
        if (metafile.getProperties().containsValue(FileType.DIR.toString())) {
            StringBuilder sb = new StringBuilder();
            sb.append(getMetafileInfoForLog(metafile, "getNextBlockUuid"));
            sb.append(", is folder.");
            throw new MetafileIsFolderException(sb.toString());
        } else {
            if (blockUuidList == null) {
                blockUuidList = new ArrayList<>(metafile.getBlockUuidList());
            }

            if (blockUuidList.isEmpty()) {
                StringBuilder sb = new StringBuilder();
                sb.append(getMetafileInfoForLog(metafile, "getNextBlockUuid"));
                sb.append(" does not have a block.");
                throw new BlockDoesNotExistException(sb.toString());
            }
        }

        return blockUuidList.remove(0);
    }

}