    001    /*****************************************************************************
    002     * Copyright (C) PicoContainer Organization. All rights reserved.            *
    003     * ------------------------------------------------------------------------- *
    004     * The software in this package is published under the terms of the BSD      *
    005     * style license a copy of which has been included with this distribution in *
    006     * the LICENSE.txt file.                                                     *
    007     *                                                                           *
    008     * Original code by                                                          *
    009     *****************************************************************************/
    010    package org.picocontainer.gems.monitors.prefuse;
    011
    012    import java.util.HashSet;
    013    import java.util.Set;
    014
    015    import org.picocontainer.gems.monitors.ComponentDependencyMonitor.Dependency;
    016
    017    /**
    018     * Understands non-duplicated dependencies.
    019     *
    020     * @author Peter Barry
    021     * @author Kent R. Spillner
    022     */
    023    public final class DependencySet implements ComponentDependencyListener {
    024
    025        private final Set uniqueDependencies = new HashSet();
    026
    027        private final ComponentDependencyListener listener;
    028
    029        public DependencySet(final ComponentDependencyListener listener) {
    030            this.listener = listener;
    031        }
    032
    033        public void addDependency(final Dependency dependency) {
    034            if (uniqueDependencies.add(dependency)) {
    035                listener.addDependency(dependency);
    036            }
    037        }
    038
    039        public Dependency[] getDependencies() {
    040            return (Dependency[]) uniqueDependencies.toArray(new Dependency[uniqueDependencies.size()]);
    041        }
    042    }