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

com.speedment.common.injector.dependency.DependencyGraph Maven / Gradle / Ivy

Go to download

A Speedment bundle that shades all dependencies into one jar. This is useful when deploying an application on a server.

The newest version!
/*
 *
 * Copyright (c) 2006-2019, Speedment, Inc. All Rights Reserved.
 *
 * 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 com.speedment.common.injector.dependency;

import com.speedment.common.injector.exception.CyclicReferenceException;
import com.speedment.common.injector.internal.dependency.DependencyGraphImpl;

import java.util.Optional;
import java.util.stream.Stream;

/**
 * Represents the graph of dependencies in the injector.
 * 
 * @author  Emil Forslund
 * @since   1.2.0
 */
public interface DependencyGraph {
    
    /**
     * Returns the {@link DependencyNode} representing the specified type in the 
     * graph. This method might throw a {@link CyclicReferenceException} if the
     * class is in a cyclic dependency chain.
     * 

* If the specified class does not exist in the graph, an * {@code IllegalArgumentException} is thrown. * * @param clazz the class to look for in the graph * @return the node found * * @throws CyclicReferenceException if the class is in a cyclic dependency * @throws IllegalArgumentException the specified class is not in graph */ DependencyNode get(Class clazz); /** * Returns the {@link DependencyNode} representing the specified type in the * graph if one exists, else creates it and returns it. * * @param clazz the class to look for in the graph * @return the node found or created */ DependencyNode getOrCreate(Class clazz); /** * Returns the {@link DependencyNode} representing the specified type in the * graph if one exists, else returns an empty {@code Optional}. * * @param clazz the class to look for in the graph * @return the node found or empty */ Optional getIfPresent(Class clazz); /** * Inject all dependency injected fields in the graph, throwing an * {@link CyclicReferenceException} if any cyclic references was detected. * * @return a reference to this graph * * @throws CyclicReferenceException if cyclic reference was detected */ DependencyGraph inject(); /** * Streams over all the nodes in the graph. * * @return stream of nodes */ Stream nodes(); /** * Creates and returns a new DependencyGraph. * @param injectables to use * @return a new DependencyGraph * @throws CyclicReferenceException if there is a cyclic dependency */ static DependencyGraph create(Stream> injectables) { final DependencyGraph graph = new DependencyGraphImpl(); injectables.forEachOrdered(graph::getOrCreate); graph.inject(); return graph; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy