001 /* 002 * Copyright 2010 The Apache Software Foundation. 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 */ 016 package org.vafer.jdependency; 017 018 import java.util.HashSet; 019 import java.util.Map; 020 import java.util.Set; 021 022 public final class ClazzpathUnit { 023 024 private final String id; 025 026 private final Map<String, Clazz> clazzes; 027 private final Map<String, Clazz> dependencies; 028 029 ClazzpathUnit( final String pId, final Map pClazzes, final Map pDependencies ) { 030 id = pId; 031 clazzes = pClazzes; 032 dependencies = pDependencies; 033 } 034 035 public Set getClazzes() { 036 final Set all = new HashSet(); 037 for (Clazz clazz : clazzes.values()) { 038 all.add(clazz); 039 } 040 return all; 041 } 042 043 public Clazz getClazz( final String pClazzName ) { 044 return (Clazz) clazzes.get(pClazzName); 045 } 046 047 public Set getDependencies() { 048 final Set all = new HashSet(); 049 for (Clazz clazz : dependencies.values()) { 050 all.add(clazz); 051 } 052 return all; 053 } 054 055 public Set getTransitiveDependencies() { 056 final Set all = new HashSet(); 057 for (Clazz clazz : clazzes.values()) { 058 clazz.findTransitiveDependencies(all); 059 } 060 return all; 061 } 062 063 public String toString() { 064 return id; 065 } 066 }