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

org.contextmapper.discovery.model.ContextMap Maven / Gradle / Ivy

Go to download

A reverse engineering library to generate Context Mapper DSL (CML) models from existing source code.

There is a newer version: 1.4.0
Show newest version
/*
 * Copyright 2019 The Context Mapper Project Team
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.contextmapper.discovery.model;

import java.util.HashSet;
import java.util.Set;

/**
 * Context Map with discovered Bounded Contexts and relationships
 *
 * @author Stefan Kapferer
 */
public class ContextMap {

    private Set boundedContexts = new HashSet<>();
    private Set relationships = new HashSet<>();

    /**
     * Adds a Bounded Context to the Context Map
     *
     * @param boundedContext the Bounded Context to be added to the Context Map
     */
    public void addBoundedContext(BoundedContext boundedContext) {
        this.boundedContexts.add(boundedContext);
    }

    /**
     * Adds all Bounded Contexts in the given set to the Context Map
     *
     * @param boundedContexts the set of Bounded Contexts to be added to the Context Map
     */
    public void addAllBoundedContexts(Set boundedContexts) {
        this.boundedContexts.addAll(boundedContexts);
    }

    /**
     * Adds a relationship to the Context Map
     *
     * @param relationship the relationship to be added to the Context Map
     */
    public void addRelationship(Relationship relationship) {
        if (!boundedContexts.contains(relationship.getUpstream()))
            throw new IllegalArgumentException("The upstream Bounded Context of this relationship is not part of the Context Map.");
        if (!boundedContexts.contains(relationship.getDownstream()))
            throw new IllegalArgumentException("The downstream Bounded Context of this relationship is not part of the Context Map.");
        this.relationships.add(relationship);
    }

    /**
     * Adds all relationships in the give set to the Context Map
     *
     * @param relationships the set of relationships to be added to the Context Map
     */
    public void addAllRelationships(Set relationships) {
        for (Relationship relationship : relationships) {
            addRelationship(relationship);
        }
    }

    /**
     * Gets the Bounded Contexts of the Context Map
     *
     * @return a set of Bounded Contexts
     */
    public Set getBoundedContexts() {
        return new HashSet<>(boundedContexts);
    }

    /**
     * Gets the relationships between Bounded Contexts of this Context Map
     *
     * @return a set of relationship between Bounded Contexts
     */
    public Set getRelationships() {
        return new HashSet<>(relationships);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy