Webiyo

This page was generated using Webiyo. See its source code and unit tests.

org/webiyo/examples/viewjava/SourceIndex.java

package org.webiyo.examples.viewjava;

import java.util.*;

public class SourceIndex implements Iterable<SourceFile> {

    private final Map<String, SourceFile> sourceFilesByClass;

    public SourceIndex(SourceDir... dirs) {
        this(findSourceFiles(Arrays.asList(dirs)));
    }

    public SourceIndex(SourceFile... files) {
        this(Arrays.asList(files));
    }

    public SourceIndex(List<SourceFile> sourceFiles) {
        this.sourceFilesByClass = new LinkedHashMap<String, SourceFile>();
        for (SourceFile file : sourceFiles) {
            this.sourceFilesByClass.put(file.getClassName(), file);
        }
    }

    public Iterator<SourceFile> iterator() {
        return sourceFilesByClass.values().iterator();
    }

    public SourceFile getSourceFile(String className) {
        return sourceFilesByClass.get(className);
    }

    public List<SourceFile> getFilesInPackage(String packageName) {
        List<SourceFile> result = new ArrayList<SourceFile>();
        for (SourceFile file : this) {
            if (file.getPackage().equals(packageName)) {
                result.add(file);
            }
        }
        return result;
    }

    private static List<SourceFile> findSourceFiles(List<SourceDir> sourceDirs) {
        List<SourceFile> result = new ArrayList<SourceFile>();
        for (SourceDir dir : sourceDirs) {
            result.addAll(dir.findSourceFiles());
        }
        return result;
    }
}
SourceForge