001/*
002 * Copyright 2010-2023 The jdependency developers.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.vafer.jdependency;
017
018import java.util.HashSet;
019import java.util.Map;
020import java.util.Set;
021import java.util.TreeMap;
022
023public final class ClazzpathUnit {
024
025    private final String id;
026
027    private final Map<String, Clazz> clazzes;
028    private final Map<String, Clazz> dependencies;
029
030    ClazzpathUnit( final String pId, final Map<String, Clazz> pClazzes, final Map<String, Clazz> pDependencies ) {
031        id = pId;
032        clazzes = pClazzes;
033        dependencies = pDependencies;
034    }
035
036    public Set<Clazz> getClazzes() {
037        return new HashSet<>(clazzes.values());
038    }
039
040    public Map<String, Clazz> getClazzesMap() {
041        return new TreeMap<>(clazzes);
042    }
043
044    public Clazz getClazz( final String pClazzName ) {
045        return clazzes.get(pClazzName);
046    }
047
048    public Set<Clazz> getDependencies() {
049        return new HashSet<>(dependencies.values());
050    }
051
052    public Set<Clazz> getTransitiveDependencies() {
053        final Set<Clazz> all = new HashSet<>();
054        for (Clazz clazz : clazzes.values()) {
055            clazz.findTransitiveDependencies(all);
056        }
057        return all;
058    }
059
060    public String toString() {
061        return id;
062    }
063}