Example usage for java.util LinkedList retainAll

List of usage examples for java.util LinkedList retainAll

Introduction

In this page you can find the example usage for java.util LinkedList retainAll.

Prototype

boolean retainAll(Collection<?> c);

Source Link

Document

Retains only the elements in this list that are contained in the specified collection (optional operation).

Usage

From source file:org.apache.cayenne.modeler.dialog.codegen.GeneratorController.java

/**
 * Creates a class generator for provided selections.
 *///from  w w  w. ja v a 2s  .  co m
public Collection<ClassGenerationAction> createGenerator() {

    File outputDir = getOutputDir();

    // no destination folder
    if (outputDir == null) {
        JOptionPane.showMessageDialog(this.getView(), "Select directory for source files.");
        return null;
    }

    // no such folder
    if (!outputDir.exists() && !outputDir.mkdirs()) {
        JOptionPane.showMessageDialog(this.getView(),
                "Can't create directory " + outputDir + ". Select a different one.");
        return null;
    }

    // not a directory
    if (!outputDir.isDirectory()) {
        JOptionPane.showMessageDialog(this.getView(), outputDir + " is not a valid directory.");
        return null;
    }

    // remove generic entities...
    Collection<ObjEntity> selectedEntities = new ArrayList<>(getParentController().getSelectedEntities());
    Iterator<ObjEntity> it = selectedEntities.iterator();
    while (it.hasNext()) {
        if (it.next().isGeneric()) {
            it.remove();
        }
    }

    Collection<ClassGenerationAction> generators = new ArrayList<>();
    Collection<StandardPanelComponent> dataMapLines = ((GeneratorControllerPanel) getView()).getDataMapLines();
    for (DataMap map : getParentController().getDataMaps()) {
        try {
            ClassGenerationAction generator = newGenerator();
            generator.setArtifactsGenerationMode(mode);
            generator.setDataMap(map);

            LinkedList<ObjEntity> objEntities = new LinkedList<>(map.getObjEntities());
            objEntities.retainAll(selectedEntities);
            generator.addEntities(objEntities);

            LinkedList<Embeddable> embeddables = new LinkedList<>(map.getEmbeddables());
            embeddables.retainAll(getParentController().getSelectedEmbeddables());
            generator.addEmbeddables(embeddables);

            generator.addQueries(map.getQueryDescriptors());

            Preferences preferences = application.getPreferencesNode(GeneralPreferences.class, "");

            if (preferences != null) {
                generator.setEncoding(preferences.get(GeneralPreferences.ENCODING_PREFERENCE, null));

            }

            generator.setDestDir(outputDir);
            generator.setMakePairs(true);

            for (StandardPanelComponent dataMapLine : dataMapLines) {
                if (dataMapLine.getDataMap() == map
                        && !Util.isEmptyString(dataMapLine.getSuperclassPackage().getText())) {
                    generator.setSuperPkg(dataMapLine.getSuperclassPackage().getText());
                    break;
                }
            }

            generators.add(generator);
        } catch (CayenneException exception) {
            JOptionPane.showMessageDialog(this.getView(), exception.getUnlabeledMessage());
            return null;
        }
    }

    return generators;
}