Example usage for org.apache.commons.collections15 Closure execute

List of usage examples for org.apache.commons.collections15 Closure execute

Introduction

In this page you can find the example usage for org.apache.commons.collections15 Closure execute.

Prototype

public void execute(T input);

Source Link

Document

Performs an action on the specified input object.

Usage

From source file:com.diversityarrays.util.CombinationsAndPermutations.java

static private <T> void permutations(int nNames, T[] names, Closure<T[]> collector) {
    if (nNames == 1) {
        collector.execute(names);
    } else {//  w  w w . ja v a  2s .c o  m
        for (int i = 1; i <= nNames; ++i) {
            permutations(nNames - 1, names, collector);
            int jj = (1 == (nNames & 1)) ? 1 : i;

            int j = jj - 1;

            T tmp = names[j];
            names[j] = names[nNames - 1];
            names[nNames - 1] = tmp;
            //            collector.execute(names);
        }
    }
}

From source file:com.diversityarrays.util.CombinationsAndPermutations.java

static private <T> void combinations(T[] namesBeforeNameIndex, int fillIndex, T[] names, int nameIndex,
        Closure<T[]> collector) {
    if (fillIndex >= namesBeforeNameIndex.length) {
        collector.execute(namesBeforeNameIndex);
    } else {//w  w w  . ja v  a  2  s  . c o  m
        int nNames = names.length;
        for (int i = nameIndex; i < nNames; ++i) {
            namesBeforeNameIndex[fillIndex] = names[i];
            combinations(namesBeforeNameIndex, fillIndex + 1, names, i + 1, collector);
        }
        namesBeforeNameIndex[fillIndex] = null;
    }
}

From source file:com.diversityarrays.util.Either.java

public void execute(Closure<L> leftOption, Closure<R> rightOption) {
    if (right == null) {
        leftOption.execute(left);
    } else {/*from ww  w  . j  a  v  a 2  s .co  m*/
        rightOption.execute(right);
    }
}

From source file:facade.collections.CollectionInPlaceProxy.java

public CollectionProxy<T> apply(Closure<T> closure) {
    for (T t : collection) {
        closure.execute(t);
    }// www  .  j a  v a 2 s .c o  m
    return this;
}

From source file:com.diversityarrays.dal.db.bms.GenusStore.java

protected void report(Closure<String> progress) {
    progress.execute("Found " + genusById.size() + " Genus records");
    int total = 0;
    for (Genus g : counts.uniqueSet()) {
        int n = counts.getCount(g);
        total += n;//from w w  w  . j  av  a  2 s. com
        progress.execute("\t" + n + ": " + g.getGenusName());
    }
    progress.execute("Found total of " + total + " GIDs with Genus");
}

From source file:com.diversityarrays.dal.db.bms.GenusStore.java

private void createGenusTable(Connection conn, Closure<String> progress) throws SQLException {

    progress.execute("Creating Genus TEMPORARY table...");

    SqlUtil.executeUpdate(conn, CREATE_GENUS_TABLE);

    String insertGenusRecords = StringTemplate.buildString(INSERT_GENUS_RECORDS_TEMPLATE)
            .replace("fldno", fldNoForGenus).build();

    progress.execute("Populating Genus TEMPORARY table...");
    long startNanos = System.nanoTime();
    int statusCode = SqlUtil.executeUpdate(conn, insertGenusRecords);
    long elapsedNanos = System.nanoTime() - startNanos;
    progress.execute("Population of Genus table took " + (elapsedNanos / 1_000_000.0) + " millis, statusCode="
            + statusCode);//  ww  w  . j ava 2s . c om
}

From source file:com.diversityarrays.dal.db.bms.GenusStore.java

private void createGenusGenotypeTable(Connection conn, Closure<String> progress) throws SQLException {

    progress.execute("Creating Genus_Genotype TEMPORARY table...");

    SqlUtil.executeUpdate(conn, CREATE_GENUS_GENOTYPE_TABLE);

    String insertGGrecords = StringTemplate.buildSql(INSERT_GENUS_GENOTYPE_RECORDS_TEMPLATE)
            .replace("fldno", fldNoForGenus).build();
    progress.execute("Populating Genus_Genotype TEMPORARY table...");
    long startNanos = System.nanoTime();
    int statusCode = SqlUtil.executeUpdate(conn, insertGGrecords);
    long elapsedNanos = System.nanoTime() - startNanos;
    progress.execute("Population of Genus_Genotype table took " + (elapsedNanos / 1_000_000.0)
            + " millis, statusCode=" + statusCode);

}

From source file:com.diversityarrays.kdxplore.trials.MyTrialExportHelper.java

@Override
public void visitComments(Closure<Tag> commentVisitor) throws IOException {
    for (Tag tag : kdsmartDatabase.getAllTags()) {
        commentVisitor.execute(tag);
    }/*from   w  w  w  . jav a2  s .co m*/
}

From source file:com.diversityarrays.dal.db.bms.BmsConnectionInfo.java

protected void collectFldnoForGenus(Closure<String> progress) {
    if (genusFromSpecies) {
        progress.execute("Checking for Species Code FLDNO");
        fldNoForGenus = SqlUtil.getSingleInteger(centralConnection, GET_SPECIES_FLDNO);
        progress.execute("\tfound " + fldNoForGenus);
    } else {//from   w  ww.j ava2s.com
        progress.execute("Checking for Taxonomy FLDNO");
        fldNoForGenus = SqlUtil.getSingleInteger(centralConnection, GET_TAXONOMY_FLDNO);
        progress.execute("\tfound " + fldNoForGenus);
    }
}

From source file:com.diversityarrays.kdxplore.trialmgr.trait.repair.TraitsToRepair.java

public Map<Trait, String> repairTraits(Closure<Pair<Trait, Either<Exception, String>>> publishPartial) {
    Map<Trait, String> result = new LinkedHashMap<>();
    for (Trait trait : traitSamplesByTrait.keySet()) {
        TraitSamplesToRepair traitSamples = traitSamplesByTrait.get(trait);
        Either<Exception, String> either = traitSamples.applyRepair(kdxdb);
        if (either.isRight()) {
            result.put(trait, either.right());
        }/*from   w  ww . j av a 2  s  .  c  om*/
        publishPartial.execute(new Pair<>(trait, either));
    }
    return result;
}