alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Groovy example source code file (SimpleGroovyPackageDoc.java)

This example Groovy source code file (SimpleGroovyPackageDoc.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Groovy tags/keywords

fs, groovyclassdoc, groovyclassdoc, list, list, map, simplegroovydoc, simplegroovypackagedoc, simplegroovypackagedoc, simplegroovyprogramelementdoc, string, string, stringbuffer, stringtokenizer, util

The Groovy SimpleGroovyPackageDoc.java source code

/*
 * Copyright 2003-2010 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.codehaus.groovy.tools.groovydoc;

import org.codehaus.groovy.groovydoc.GroovyClassDoc;
import org.codehaus.groovy.groovydoc.GroovyPackageDoc;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class SimpleGroovyPackageDoc extends SimpleGroovyDoc implements GroovyPackageDoc {
    private static final char FS = '/';
    final Map<String, GroovyClassDoc> classDocs;
    private String description = "";
    private String summary = "";

    public SimpleGroovyPackageDoc(String name) {
        super(name);
        classDocs = new TreeMap<String, GroovyClassDoc>();
    }

    public GroovyClassDoc[] allClasses() {
        return classDocs.values().toArray(new GroovyClassDoc[classDocs.values().size()]);
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public void setSummary(String summary) {
        this.summary = summary;
    }

    public void putAll(Map<String, GroovyClassDoc> classes) {
        // 2 way relationship for visible classes:
        // add reference to classes inside this package
        // add reference to this package inside classes
        for (Map.Entry<String, GroovyClassDoc> docEntry : classes.entrySet()) {
            final GroovyClassDoc classDoc = docEntry.getValue();
            classDocs.put(docEntry.getKey(), classDoc);
            SimpleGroovyProgramElementDoc programElement = (SimpleGroovyProgramElementDoc) classDoc;
            programElement.setContainingPackage(this);
        }
    }

    public String nameWithDots() {
        return name().replace(FS, '.');
    }

    public GroovyClassDoc[] allClasses(boolean arg0) {
        List<GroovyClassDoc> classDocValues = new ArrayList(classDocs.values());
        return classDocValues.toArray(new GroovyClassDoc[classDocValues.size()]);
    }

    public GroovyClassDoc[] enums() {
        List<GroovyClassDoc> result = new ArrayList(classDocs.values().size());
        for (GroovyClassDoc doc : classDocs.values()) {
            if (doc.isEnum()) {
                result.add(doc);
            }
        }
        return result.toArray(new GroovyClassDoc[result.size()]);
    }

    public GroovyClassDoc[] errors() {
        List<GroovyClassDoc> result = new ArrayList(classDocs.values().size());
        for (GroovyClassDoc doc : classDocs.values()) {
            if (doc.isError()) {
                result.add(doc);
            }
        }
        return result.toArray(new GroovyClassDoc[result.size()]);
    }

    public GroovyClassDoc[] exceptions() {
        List<GroovyClassDoc> result = new ArrayList(classDocs.values().size());
        for (GroovyClassDoc doc : classDocs.values()) {
            if (doc.isException()) {
                result.add(doc);
            }
        }
        return result.toArray(new GroovyClassDoc[result.size()]);
    }

    public GroovyClassDoc findClass(String arg0) {/*todo*/
        return null;
    }

    public GroovyClassDoc[] interfaces() {
        List<GroovyClassDoc> result = new ArrayList(classDocs.values().size());
        for (GroovyClassDoc doc : classDocs.values()) {
            if (doc.isInterface()) {
                result.add(doc);
            }
        }
        return result.toArray(new GroovyClassDoc[result.size()]);
    }

    public GroovyClassDoc[] ordinaryClasses() {
        List<GroovyClassDoc> result = new ArrayList(classDocs.values().size());
        for (GroovyClassDoc doc : classDocs.values()) {
            if (doc.isOrdinaryClass()) {
                result.add(doc);
            }
        }
        return result.toArray(new GroovyClassDoc[result.size()]);
    }

    public String description() {
        return description;
    }

    public String summary() {
        return summary;
    }

    public String getRelativeRootPath() {
        StringTokenizer tokenizer = new StringTokenizer(name(), "" + FS);
        StringBuffer sb = new StringBuffer();
        while (tokenizer.hasMoreTokens()) {
            tokenizer.nextToken();
            sb.append("../");
        }
        return sb.toString();
    }

}

Other Groovy examples (source code examples)

Here is a short list of links related to this Groovy SimpleGroovyPackageDoc.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.