<commit_before>package io.resourcepool.hvsz.service.impl;

import io.resourcepool.hvsz.persistance.dao.DaoMapDb;
import io.resourcepool.hvsz.persistance.models.Game;
import io.resourcepool.hvsz.persistance.models.GameStatus;
import io.resourcepool.hvsz.persistance.models.GenericBuilder;
import io.resourcepool.hvsz.persistance.models.Life;
import io.resourcepool.hvsz.persistance.models.SupplyZone;
import io.resourcepool.hvsz.service.HumanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

@Service
public class HumanServiceImpl implements HumanService {

    private static int incrementor = 0;

    @Autowired
    private DaoMapDb dao;


    @Override
    public Life newLife() {
        Game g = dao.get(1L);

        GameStatus status = g.getStatus();

        if (incrementor == 0) {
            setLastId(1L); // in case of reload of base, to avoid having incrementor reset
        }

        if (status.getNbLifeLeft() <= 0) {
            return null;
        } else {
            //Decrement nbLifeLeft in game status and increment nbHumanAlive
            status.setNbLifeLeft(status.getNbLifeLeft() - 1);
            status.setNbHumanAlive(status.getNbHumanAlive() + 1);
            //Create new Life
            Life life = GenericBuilder.of(Life::new)
                    .with(Life::setId, incrementor++)
                    .with(Life::setAlive, true)
                    .with(Life::setNbResources, 0)
                    .with(Life::setToken, UUID.randomUUID().toString()) // TODO smaller token, id + UUIDsubstring
                    .build();
            status.getLives().add(life);
            g.setStatus(status);
            dao.set(1L, g);
            return life;
        }
    }

    /**
     * get life by id.
     *
     * @param id .
     * @return life.
     */
    public Life getLife(Integer id) {
        Game g = dao.get(1L);<commit_msg>shortened life token generated<commit_after>package io.resourcepool.hvsz.service.impl;

import io.resourcepool.hvsz.persistance.dao.DaoMapDb;
import io.resourcepool.hvsz.persistance.models.Game;
import io.resourcepool.hvsz.persistance.models.GameStatus;
import io.resourcepool.hvsz.persistance.models.GenericBuilder;
import io.resourcepool.hvsz.persistance.models.Life;
import io.resourcepool.hvsz.persistance.models.SupplyZone;
import io.resourcepool.hvsz.service.HumanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

@Service
public class HumanServiceImpl implements HumanService {

    private static int incrementor = 0;

    @Autowired
    private DaoMapDb dao;


    @Override
    public Life newLife() {
        Game g = dao.get(1L);

        GameStatus status = g.getStatus();

        if (incrementor == 0) {
            setLastId(1L); // in case of reload of base, to avoid having incrementor reset
        }

        if (status.getNbLifeLeft() <= 0) {
            return null;
        } else {
            //Decrement nbLifeLeft in game status and increment nbHumanAlive
            status.setNbLifeLeft(status.getNbLifeLeft() - 1);
            status.setNbHumanAlive(status.getNbHumanAlive() + 1);
            //Create new Life
            Life life = GenericBuilder.of(Life::new)
                    .with(Life::setId, incrementor++)
                    .with(Life::setAlive, true)
                    .with(Life::setNbResources, 0)
                    .with(Life::setToken, (incrementor-1) + UUID.randomUUID().toString().substring(0,5))
                    .build();
            status.getLives().add(life);
            g.setStatus(status);
            dao.set(1L, g);
            return life;
        }
    }

    /**
     * get life by id.
     *
     * @param id .
     * @return life.
     */
    public Life getLife(Integer id) {
        Game g = dao.get(1L);
{'fraction_non_alphanumeric': 0.10868461147790756, 'fraction_numerical': 0.005840528186896902, 'mean_word_length': 2.3128679562657695, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6723098', 'n_tokens_mistral': 1219, 'n_tokens_neox': 1186, 'n_words': 240}