001 /* 002 * The contents of this file are subject to the Mozilla Public 003 * License Version 1.1 (the "License"); you may not use this file 004 * except in compliance with the License. You may obtain a copy of 005 * the License at http://www.mozilla.org/MPL/ 006 * 007 * Software distributed under the License is distributed on an "AS 008 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 009 * implied. See the License for the specific language governing 010 * rights and limitations under the License. 011 * 012 * The Original Code is Knowtator. 013 * 014 * The Initial Developer of the Original Code is University of Colorado. 015 * Copyright (C) 2005 - 2008. All Rights Reserved. 016 * 017 * Knowtator was developed by the Center for Computational Pharmacology 018 * (http://compbio.uchcs.edu) at the University of Colorado Health 019 * Sciences Center School of Medicine with support from the National 020 * Library of Medicine. 021 * 022 * Current information about Knowtator can be obtained at 023 * http://knowtator.sourceforge.net/ 024 * 025 * Contributor(s): 026 * Philip V. Ogren <philip@ogren.info> (Original Author) 027 */ 028 package edu.uchsc.ccp.iaa.matcher; 029 030 import java.util.HashSet; 031 import java.util.Map; 032 import java.util.Set; 033 034 public class ClassHierarchyImpl implements ClassHierarchy { 035 036 Map<String, Set<String>> subclassMap; 037 038 public ClassHierarchyImpl(Map<String, Set<String>> subclassMap) { 039 this.subclassMap = subclassMap; 040 } 041 042 public Set<String> getSubclasses(String className) { 043 Set<String> returnValues = new HashSet<String>(); 044 returnValues.add(className); 045 collectSubclasses(className, returnValues); 046 return returnValues; 047 } 048 049 private void collectSubclasses(String className, Set<String> subclassNames) { 050 Set<String> subNames = subclassMap.get(className); 051 if (subNames != null) { 052 for (String subName : subNames) { 053 if (!subclassNames.contains(subName)) { 054 subclassNames.add(subName); 055 collectSubclasses(subName, subclassNames); 056 } 057 } 058 } 059 } 060 061 }