<commit_before>package de.fabiankeller.palladio.builder.util.impl;

import de.fabiankeller.palladio.builder.util.PalladioResourceRepository;
import org.palladiosimulator.pcm.core.entity.Entity;
import org.palladiosimulator.pcm.resourcetype.CommunicationLinkResourceType;
import org.palladiosimulator.pcm.resourcetype.ProcessingResourceType;
import org.palladiosimulator.pcm.resourcetype.ResourceRepository;
import org.palladiosimulator.pcm.resourcetype.ResourceType;

import java.util.HashMap;
import java.util.Map;

public class PalladioResourceRepositoryImpl implements PalladioResourceRepository {

    private final ResourceRepository repository;

    private static final String CPU = "CPU";
    private static final String LAN = "LAN";
    private static final String HDD = "HDD";
    private static final String DELAY = "DELAY";

    private final Map<String, Entity> resourceTypes = new HashMap<>();

    public PalladioResourceRepositoryImpl(final ResourceRepository repository) {
        this.repository = repository;
    }

    @Override
    public ProcessingResourceType cpu() {
        return (ProcessingResourceType) getResourceTypeByName(CPU);
    }

    @Override
    public ProcessingResourceType hdd() {
        return (ProcessingResourceType) getResourceTypeByName(HDD);
    }

    @Override
    public ProcessingResourceType delay() {
        return (ProcessingResourceType) getResourceTypeByName(DELAY);
    }

    @Override
    public CommunicationLinkResourceType lan() {
        return (CommunicationLinkResourceType) getResourceTypeByName(LAN);
    }

    private Entity getResourceTypeByName(final String entityName) {
        if (!this.resourceTypes.containsKey(entityName)) {
            for (final ResourceType type : this.repository.getAvailableResourceTypes_ResourceRepository()) {
                if (type.getEntityName().equals(entityName)) {
                    this.resourceTypes.put(entityName, type);
                    break;
                }
            }
            throw new RuntimeException(String.format("Could not find resource type '%s'", entityName));
        }
        return this.resourceTypes.get(entityName);
    }
}
<commit_msg>Fix: only throw exception if type not found in PalladioResourceRepository<commit_after>package de.fabiankeller.palladio.builder.util.impl;

import de.fabiankeller.palladio.builder.util.PalladioResourceRepository;
import org.palladiosimulator.pcm.core.entity.Entity;
import org.palladiosimulator.pcm.resourcetype.CommunicationLinkResourceType;
import org.palladiosimulator.pcm.resourcetype.ProcessingResourceType;
import org.palladiosimulator.pcm.resourcetype.ResourceRepository;
import org.palladiosimulator.pcm.resourcetype.ResourceType;

import java.util.HashMap;
import java.util.Map;

public class PalladioResourceRepositoryImpl implements PalladioResourceRepository {

    private final ResourceRepository repository;

    private static final String CPU = "CPU";
    private static final String LAN = "LAN";
    private static final String HDD = "HDD";
    private static final String DELAY = "DELAY";

    private final Map<String, Entity> resourceTypes = new HashMap<>();

    public PalladioResourceRepositoryImpl(final ResourceRepository repository) {
        this.repository = repository;
    }

    @Override
    public ProcessingResourceType cpu() {
        return (ProcessingResourceType) getResourceTypeByName(CPU);
    }

    @Override
    public ProcessingResourceType hdd() {
        return (ProcessingResourceType) getResourceTypeByName(HDD);
    }

    @Override
    public ProcessingResourceType delay() {
        return (ProcessingResourceType) getResourceTypeByName(DELAY);
    }

    @Override
    public CommunicationLinkResourceType lan() {
        return (CommunicationLinkResourceType) getResourceTypeByName(LAN);
    }

    private Entity getResourceTypeByName(final String entityName) {
        if (!this.resourceTypes.containsKey(entityName)) {
            for (final ResourceType type : this.repository.getAvailableResourceTypes_ResourceRepository()) {
                if (type.getEntityName().equals(entityName)) {
                    this.resourceTypes.put(entityName, type);
                    break;
                }
            }
            if (!this.resourceTypes.containsKey(entityName)) {
                throw new RuntimeException(String.format("Could not find resource type '%s'", entityName));
            }
        }
        return this.resourceTypes.get(entityName);
    }
}

{'fraction_non_alphanumeric': 0.08124306326304107, 'fraction_numerical': 0.0, 'mean_word_length': 3.6168032786885247, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '7396488', 'n_tokens_mistral': 1199, 'n_tokens_neox': 1171, 'n_words': 251}