All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hadii.clarpse.sourcemodel.OOPSourceCodeModel Maven / Gradle / Ivy

There is a newer version: 7.1.1
Show newest version
package com.hadii.clarpse.sourcemodel;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Stream;

/**
 * A language independent representation of a codebase that reveals its
 * structural buildup.
 */
public class OOPSourceCodeModel implements Serializable {

    private static final long serialVersionUID = 1L;
    private static final Logger LOGGER = LogManager.getLogger(OOPSourceCodeModel.class);

    public OOPSourceCodeModel() {
    }

    private final Map components = new HashMap<>();

    private Map getComponents() {
        return components;
    }

    public void merge(final OOPSourceCodeModel sourceModel) {
        insertComponents(sourceModel.getComponents());
    }

    public int size() {
        return components.size();
    }

    public void insertComponent(final Component component) {
        LOGGER.debug("Inserted component " + component + ".");
        components.put(component.uniqueName(), component);
    }

    public boolean containsComponent(final String componentName) {
        return getComponents().containsKey(componentName);
    }

    public Optional getComponent(final String componentName) {
        return Optional.ofNullable(this.getComponents().get(componentName));
    }

    public void insertComponents(final Map newCmps) {
        for (final Map.Entry entry : newCmps.entrySet()) {
            insertComponent(entry.getValue());
        }
    }

    public void removeComponent(String cmpUniqueName) {
        this.components.remove(cmpUniqueName);
        LOGGER.debug("Removed component " + cmpUniqueName + ".");
    }

    public Stream components() {
        return components.values().stream();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy