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

bibliothek.gui.dock.extension.css.doc.DocPackage Maven / Gradle / Ivy

The newest version!
/*
 * Bibliothek - DockingFrames
 * Library built on Java/Swing, allows the user to "drag and drop"
 * panels containing any Swing-Component the developer likes to add.
 * 
 * Copyright (C) 2013 Benjamin Sigg
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 * 
 * Benjamin Sigg
 * [email protected]
 * CH - Switzerland
 */
package bibliothek.gui.dock.extension.css.doc;

import java.text.Collator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * Represents a single package of classes (does not include sub packages).
 * @author Benjamin Sigg
 */
public class DocPackage implements Iterable{
	/** the root of the application */
	private DocRoot root;
	
	/** the fully qualified name of this package */
	private String name;

	/** all the classes in this package */
	private Map classes = new HashMap();
	
	/**
	 * Creates a new package.
	 * @param root the root element of the documentation
	 * @param name the fully qualified name of this package
	 */
	public DocPackage( DocRoot root, String name ){
		this.root = root;
		this.name = name;
	}
	
	/**
	 * Gets the root element of the documentation.
	 * @return the root element
	 */
	public DocRoot getRoot(){
		return root;
	}

	/**
	 * Gets the fully qualified name of this package.
	 * @return the name
	 */
	public String getName(){
		return name;
	}
	
	/**
	 * Adds clazz to the set of known {@link Class classes}. Does nothing if
	 * clazz is already known.
	 * @param clazz the new class
	 */
	public void add( Class clazz ){
		String name = clazz.getSimpleName();
		if( !classes.containsKey( name )){
			DocClass doc = new DocClass( this, clazz );
			classes.put( name, doc );
		}
	}
	
	/**
	 * Searches for the {@link DocClass} for clazz
	 * @param clazz the class to search for
	 * @return the representation of clazz or null if not found
	 */
	public DocClass get( Class clazz ){
		return classes.get( clazz.getSimpleName() );
	}
	
	@Override
	public Iterator iterator(){
		List copy = new ArrayList( classes.values() );
		Collections.sort( copy, new Comparator(){
			private Collator collator = Collator.getInstance();
			
			@Override
			public int compare( DocClass a, DocClass b ){
				return collator.compare( a.getName(), b.getName() );
			}
		} );
		return copy.iterator();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy