Example usage for java.io FileFilter FileFilter

List of usage examples for java.io FileFilter FileFilter

Introduction

In this page you can find the example usage for java.io FileFilter FileFilter.

Prototype

FileFilter

Source Link

Usage

From source file:ExtractorContentTest.java

@Test
public void testStatisticsBIG() throws Exception {

    final String OUTPUT_DIR = "/Users/macher1/Documents/RESEARCH/INPROGRESS/ICSE2014-KSynthesis/PCMs/";

    File dir = new File(OUTPUT_DIR);
    File[] fileFMs = dir.listFiles(new FileFilter() {

        @Override//from  ww w .  jav a  2 s. c  o  m
        public boolean accept(File pathname) {
            return pathname.getName().contains("fmlbdd");
        }
    });
    _shell.setVerbose(false);
    int i = 1;
    int totalAverage = 0;
    int totalNft = 0;
    int totalEdges = 0;
    for (File fileFM : fileFMs) {
        _shell.reset();
        FeatureModelVariable fmv1 = FMBuilder.parseFMLBDD(fileFM.getAbsolutePath(), _builder);
        assertNotNull(fmv1);

        /* new FeatureModelVariable("", FMBuilder.getInternalFM("FM (" +
        "WikiMatrix: General ; " +
        "General: (LicenseCostFee|Unicode)+ [Storage] [Language] License RSS ;" + 
        "LicenseCostFee: (DifferentLicences|US10|Community)? ;" +  
        "Language: (Java|Python|PHP|Perl) ; " + 
        "License: (Commercial|GPL|GPL2|Nolimit) ;" + 
        "Storage: (Files|Database|FileRCS) ;" +  
        "(Java -> Database);" + 
        "(Nolimit -> !Unicode);" +
        "(Nolimit -> LicenseCostFee); " +
        "(GPL2 -> Storage);" + 
        "(DifferentLicences -> GPL2);" + 
        "(GPL2 -> PHP);" + 
        "(DifferentLicences -> Database);" + 
        "(GPL -> Unicode);" + 
        "(Community -> GPL);" + 
        "(Storage <-> Unicode);" + 
        "(Python -> GPL);" + 
        "(Files -> !LicenseCostFee);" +
        "(Community <-> FileRCS);" +
        "(Commercial <-> US10);" + 
        "(Python -> Files);" + 
        "(FileRCS <-> Perl); " + 
        "(Unicode <-> Language);" +
        "(US10 <-> Java);"  + ")"));  */

        System.err.println("====== " + i++ + " ===========");

        int nFts = fmv1.features().size();
        System.err.println("#fts " + nFts);

        ImplicationGraph<String> big = fmv1.computeImplicationGraph();
        //TransitiveReduction.INSTANCE.reduce(big);

        System.err.println("#IG (edges) " + big.edges().size());
        Collection<String> vtxs = big.vertices();
        int t = 0;
        for (String ft : vtxs) {
            Collection<SimpleEdge> iedges = big.outgoingEdges(ft);
            int n = iedges.size();
            //System.err.println("ft=" + ft + " " + n);
            t += n;
        }

        int nAverage = t / nFts;
        System.err.println("(average) " + nAverage);
        //System.err.println("(rfm) " + fmv1);

        totalAverage += nAverage;

        _shell.reset();

        totalNft += nFts;
        totalEdges += t;

    }

    //System.err.println("" + (double) ((double)totalAverage / (double)i));
    System.err.println("" + (double) ((double) totalEdges / (double) totalNft));

}

From source file:org.testeditor.fixture.swt.SwtBotFixture.java

/**
 * FileFilter to find the SWTBotAgent Bundle.
 * //from  w  ww.j a v a  2s  .com
 * @return true if there is a an SWTBot bundle
 */
protected FileFilter getSWTBotAgentFilter() {
    return new FileFilter() {

        @Override
        public boolean accept(File pathname) {
            if (pathname.getName().startsWith("org.testeditor.agent.swtbot")) {
                return true;
            }
            return false;
        }
    };
}

From source file:edu.ku.brc.specify.tools.datamodelgenerator.DatamodelGenerator.java

/**
 * Reads in hbm files and generates datamodel tree.
 * @return List datamodel tree//from   w w w.  j a v  a 2  s .  co m
 */
@SuppressWarnings({ "unchecked", "cast" })
public List<Table> generateDatamodelTree(final List<Table> tableList, final String dataModelPath) {
    try {
        log.debug("Preparing to read in DataModel Classes files from  path: " + dataModelPath);

        srcCodeDir = new File(dataModelPath);

        String path = srcCodeDir.getAbsolutePath();
        log.info(path);
        //dir = new File(path.substring(0, path.lastIndexOf(File.separator)));

        // This filter only returns directories
        FileFilter fileFilter = new FileFilter() {
            public boolean accept(File file) {
                return file.toString().indexOf(".java") != -1;
            }
        };

        String PACKAGE = "package ";
        String CLASS = "public class ";

        File[] files = srcCodeDir.listFiles(fileFilter);
        int count = 0;
        for (File file : files) {
            if (showDebug)
                log.debug("Reading    " + file.getAbsolutePath());
            List<?> lines = FileUtils.readLines(file);
            count++;
            if (showDebug)
                log.debug("Processing " + count + " of " + files.length + "  " + file.getAbsolutePath());

            String className = null;

            for (Object lineObj : lines) {
                String line = ((String) lineObj).trim();
                //System.out.println(line);
                if (line.startsWith(PACKAGE)) {
                    packageName = line.substring(PACKAGE.length(), line.length() - 1);
                }
                if (StringUtils.contains(line, CLASS)) {
                    String str = line.substring(CLASS.length());
                    while (str.charAt(0) == ' ') {
                        str = str.substring(1);
                    }

                    int eInx = str.indexOf(' ');
                    if (eInx == -1) {
                        className = str;
                    } else {
                        className = str.substring(0, eInx);
                    }
                    break;
                }
            }

            if (className != null) {
                if (!StringUtils.contains(className, "SpUI")) {
                    processClass(className, tableList);
                }

                // These were used for correcting Cascading rules
                // Eventually these can be removed along with the methods.
                //processCascade(className, tableList);
                //processCascadeAddCascade(className, tableList);
            } else {
                String fileName = file.getName();
                if (!StringUtils.contains(fileName, "DataModelObjBase")
                        && !StringUtils.contains(fileName, "CollectionMember")
                        && !StringUtils.contains(fileName, "DisciplineMember")
                        && !StringUtils.contains(fileName, "UserGroupScope")
                        && !StringUtils.contains(fileName, "Treeable")
                        && !StringUtils.contains(fileName, "SpLocaleBase")
                        && !StringUtils.contains(fileName.toLowerCase(), "iface")
                        && !StringUtils.contains(fileName, "BaseTreeDef")
                        && !StringUtils.contains(fileName, "TreeDefItemStandardEntry")) {
                    throw new RuntimeException("Couldn't locate class name for " + file.getAbsolutePath());
                }
            }
        }
        System.out.println(missing);
        return tableList;

    } catch (Exception ex) {
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(DatamodelGenerator.class, ex);
        ex.printStackTrace();
        log.fatal(ex);
    }
    return null;
}

From source file:com.actuate.development.tool.task.InstallBRDPro.java

private File getPluginFile(final String pattern, File file) {
    File[] sdks = file.listFiles(new FileFilter() {

        public boolean accept(File file) {
            String fileName = file.getName();
            if (fileName.matches(pattern)) {
                return true;
            }// w w w. j  a va  2  s. c  om
            return false;
        }
    });
    if (sdks != null && sdks.length > 0) {
        FileSorter.sortFiles(sdks);
        return sdks[sdks.length - 1];
    }
    return null;
}

From source file:net.sf.zekr.common.config.ApplicationConfig.java

private void extractRevelOrderInfo() {
    String def = props.getString("revel.default");
    logger.info("Default revelation package is: " + def);

    File revelDir = new File(ApplicationPath.REVELATION_DIR);
    if (!revelDir.exists()) {
        logger.debug("No revelation data pack found.");
        return;/*from www.  j a v a 2s .  c  o m*/
    }

    logger.info("Loading revelation data packs from: " + revelDir);
    FileFilter filter = new FileFilter() { // accept zip files
        public boolean accept(File pathname) {
            if (pathname.getName().toLowerCase().endsWith(ApplicationPath.REVEL_PACK_SUFFIX)) {
                return true;
            }
            return false;
        }
    };
    File[] revelFiles = revelDir.listFiles(filter);

    RevelationData rd;
    for (int revelIndex = 0; revelIndex < revelFiles.length; revelIndex++) {
        ZipFile zipFile = null;
        try {
            rd = loadRevelationData(revelFiles[revelIndex]);
            if (rd == null) {
                continue;
            }
            revelation.add(rd);
            if (rd.id.equals(def)) {
                rd.load();
                logger.info("Default revelation data is: " + rd);
                revelation.setDefault(rd);
            }
        } catch (Exception e) {
            logger.warn("Can not load revelation data pack \"" + zipFile
                    + "\" properly because of the following exception:");
            logger.log(e);
        }
    }
}

From source file:com.mods.grx.settings.GrxSettingsActivity.java

/******************** RESTORE ****************************************************/

private void show_restore_dialog() {
    ListView lv = new ListView(this);
    File ficheros = new File(Common.BackupsDir + File.separator);
    FileFilter ff = new FileFilter() {
        @Override/*from  w w w .  java 2s.  c  o  m*/
        public boolean accept(File pathname) {
            String ruta;
            if (pathname.isFile()) {
                ruta = pathname.getAbsolutePath().toLowerCase();
                if (ruta.contains("." + getString(R.string.gs_backup_ext))) {
                    return true;
                }
            }
            return false;
        }
    };
    File fa[] = ficheros.listFiles(ff);
    if (fa.length == 0)
        show_snack_message(getString(R.string.gs_no_backups));
    else {

        AdapterBackups ab = new AdapterBackups();
        ab.AdapterBackups(this, fa);
        ListView lista = new ListView(this);
        lista.setAdapter(ab);
        lista.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                TextView tv = (TextView) view.findViewById(android.R.id.text1);
                String file_name = tv.getText().toString();
                mRestoreDialog.dismiss();
                mRestoreDialog = null;
                File f = new File(Common.BackupsDir + File.separator + file_name + "."
                        + getString(R.string.gs_backup_ext));
                if (f.exists())
                    show_restore_confirmation_dialog(file_name);
                else
                    show_snack_message(getString(R.string.gs_err_desconocido_restaurar));
            }
        });
        AlertDialog.Builder abd = new AlertDialog.Builder(this);
        abd.setTitle(R.string.gs_tit_restaurar);
        abd.setMessage(R.string.gs_mensaje_restaurar);
        abd.setView(lista);
        mRestoreDialog = abd.create();
        mRestoreDialog.show();
    }

}

From source file:org.apache.carbondata.sdk.file.CarbonReaderTest.java

@Ignore
public void testReadUserSchemaOfComplex() throws IOException {
    String path = "./testWriteFiles";
    FileUtils.deleteDirectory(new File(path));

    String mySchema = "{" + "  \"name\": \"address\", " + "   \"type\": \"record\", " + "    \"fields\": [  "
            + "  { \"name\": \"name\", \"type\": \"string\"}, " + "  { \"name\": \"age\", \"type\": \"int\"}, "
            + "  { " + "    \"name\": \"address\", " + "      \"type\": { " + "    \"type\" : \"record\", "
            + "        \"name\" : \"my_address\", " + "        \"fields\" : [ "
            + "    {\"name\": \"street\", \"type\": \"string\"}, "
            + "    {\"name\": \"city\", \"type\": \"string\"} " + "  ]} " + "  }, "
            + "  {\"name\" :\"doorNum\", " + "   \"type\" : { " + "   \"type\" :\"array\", " + "   \"items\":{ "
            + "   \"name\" :\"EachdoorNums\", " + "   \"type\" : \"int\", " + "   \"default\":-1} "
            + "              } " + "  }] " + "}";

    String json = "{\"name\":\"bob\", \"age\":10, \"address\" : {\"street\":\"abc\", \"city\":\"bang\"}, "
            + "   \"doorNum\" : [1,2,3,4]}";

    try {//w  w  w  .j a  v a2s  .co m
        WriteAvroComplexData(mySchema, json, path);
    } catch (InvalidLoadOptionException e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }

    File folder = new File(path);
    Assert.assertTrue(folder.exists());

    File[] dataFiles = folder.listFiles(new FileFilter() {
        @Override
        public boolean accept(File pathname) {
            return pathname.getName().endsWith(CarbonCommonConstants.FACT_FILE_EXT);
        }
    });
    Assert.assertNotNull(dataFiles);
    Assert.assertEquals(1, dataFiles.length);

    File[] dataFiles2 = new File(path).listFiles(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return name.endsWith("carbonindex");
        }
    });

    Schema schema = CarbonSchemaReader.readSchema(dataFiles2[0].getAbsolutePath()).asOriginOrder();

    for (int i = 0; i < schema.getFields().length; i++) {
        System.out.println(
                (schema.getFields())[i].getFieldName() + "\t" + schema.getFields()[i].getSchemaOrdinal());
    }
    FileUtils.deleteDirectory(new File(path));
}

From source file:com.actuate.development.tool.task.InstallBRDPro.java

private void handleSDK(Project p, ProjectHelper helper, File file, Module module, final String validateFile) {
    String fileName = "/templates/Source.xml";
    File templateFile = FileUtil.getTempFile(fileName);
    FileUtil.writeToBinarayFile(templateFile, this.getClass().getResourceAsStream(fileName), true);

    VelocityEngine velocityEngine = new VelocityEngine();
    velocityEngine.setProperty(VelocityEngine.FILE_RESOURCE_LOADER_PATH,
            templateFile.getAbsoluteFile().getParentFile().getAbsolutePath());
    velocityEngine.init();//from  ww w  . j  ava 2  s .c o m

    VelocityContext context = new VelocityContext();
    context.put("tempDir", data.getTempDir());
    context.put("brdproFile", data.getBrdproFile());
    context.put("installPath", data.getDirectory());
    context.put("source", module.getName());
    context.put("sourceFile", file.getAbsolutePath());
    context.put("runtime", FileSystem.getCurrentDirectory());

    Template template = velocityEngine.getTemplate(templateFile.getName());
    StringWriter sw = new StringWriter();
    template.merge(context, sw);

    File tempFile = FileUtil.getTempFile(fileName);
    FileUtil.writeToFile(tempFile, sw.toString().trim());

    helper.parse(p, tempFile);
    p.executeTarget(module.getName() + "_download");

    File sdkDir = new File(p.getProperty("build.temp") + "\\" + module.getName() + "_sdk\\" + ECLIPSE_FEATURES);
    if (sdkDir.exists()) {
        File[] children = sdkDir.listFiles(new FileFilter() {

            public boolean accept(File file) {
                if (file.getName().startsWith(validateFile))
                    return true;
                return false;
            }
        });
        if (children != null) {
            p.executeTarget(module.getName() + "_install");
        }
    }
}

From source file:net.sf.zekr.common.config.ApplicationConfig.java

private void extractPagingDataProps() {
    String def = props.getString("view.pagingMode");
    logger.info("Default paging mode is: " + def);

    File pagingDir = new File(ApplicationPath.PAGING_DIR);
    if (!pagingDir.exists()) {
        logger.debug("No paging data found.");
        return;// w  ww . j a  v a  2s  . c  om
    }

    logger.info("Loading paging data from: " + pagingDir);
    FileFilter filter = new FileFilter() {
        public boolean accept(File pathname) {
            if (pathname.getName().toLowerCase().endsWith(ApplicationPath.PAGING_PACK_SUFFIX)) {
                return true;
            }
            return false;
        }
    };
    File[] pagingFiles = pagingDir.listFiles(filter);

    // add built-in paging implementations
    quranPaging.add(new SuraPagingData());
    quranPaging.add(new FixedAyaPagingData(props.getInt("view.pagingMode.ayaPerPage", 20)));
    quranPaging.add(new HizbQuarterPagingData());
    quranPaging.add(new JuzPagingData());

    CustomPagingData cpd;
    for (int i = 0; i < pagingFiles.length; i++) {
        cpd = new CustomPagingData();
        String name = pagingFiles[i].getName();
        cpd.setId(name.substring(0, name.indexOf(ApplicationPath.PAGING_PACK_SUFFIX)));
        cpd.file = pagingFiles[i];
        quranPaging.add(cpd);
    }
    IPagingData ipd = (IPagingData) quranPaging.get(def);
    if (ipd != null) {
        try {
            logger.info("Default paging data is: " + ipd);
            ipd.load();
            logger.info("Default paging data loaded successfully: " + ipd);
            quranPaging.setDefault(ipd);
        } catch (Exception e) {
            logger.warn(
                    "Can not load paging data \"" + ipd + "\" properly because of the following exception:");
            logger.log(e);
            logger.debug("Set default paging data to: sura.");
            // set default paging model to sura, if nothing is set.
            quranPaging.setDefault(quranPaging.get(SuraPagingData.ID));
            props.setProperty("view.pagingMode", quranPaging.getDefault().getId());
        }
    }
    if (quranPaging.getDefault() == null) {
        logger.warn("No default paging data found. Will load Hizb Quarter paging data.");
        quranPaging.setDefault(quranPaging.get(HizbQuarterPagingData.ID));
    }
}

From source file:com.actuate.development.tool.task.InstallBRDPro.java

private File getSDKFile(String eclipseOutputDir, final String pattern) {
    File sdkDir = new File(eclipseOutputDir);
    if (sdkDir.exists()) {
        File[] sdks = sdkDir.listFiles(new FileFilter() {

            public boolean accept(File file) {
                String fileName = file.getName();
                if (fileName.matches(pattern)) {
                    return true;
                }/*from w  ww  .  j av a 2 s. c  o m*/
                return false;
            }
        });
        FileSorter.sortFiles(sdks);
        if (sdks != null && sdks.length > 0) {
            return sdks[sdks.length - 1];
        }
    }
    return null;
}