Example usage for org.apache.commons.lang3 StringUtils join

List of usage examples for org.apache.commons.lang3 StringUtils join

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils join.

Prototype

public static String join(final Iterable<?> iterable, final String separator) 

Source Link

Document

Joins the elements of the provided Iterable into a single String containing the provided elements.

No delimiter is added before or after the list.

Usage

From source file:com.rantop.web.util.reflection.ConvertUtils.java

/**
 * ????(getter), ??./*from   ww w. ja v a 2s. c om*/
 * 
 * @param collection ???.
 * @param propertyName ??????.
 * @param separator .
 */
@SuppressWarnings("unchecked")
public static String convertElementPropertyToString(final Collection collection, final String propertyName,
        final String separator) {
    List list = convertElementPropertyToList(collection, propertyName);
    return StringUtils.join(list, separator);
}

From source file:com.act.lcms.db.analysis.IonSearchAnalysis.java

public static void main(String[] args) throws Exception {
    Options opts = new Options();
    for (Option.Builder b : OPTION_BUILDERS) {
        opts.addOption(b.build());/*from  w w w.  j av a  2s  . c  o  m*/
    }

    CommandLine cl = null;
    try {
        CommandLineParser parser = new DefaultParser();
        cl = parser.parse(opts, args);
    } catch (ParseException e) {
        System.err.format("Argument parsing failed: %s\n", e.getMessage());
        HELP_FORMATTER.printHelp(LoadPlateCompositionIntoDB.class.getCanonicalName(), HELP_MESSAGE, opts, null,
                true);
        System.exit(1);
    }

    if (cl.hasOption("help")) {
        HELP_FORMATTER.printHelp(LoadPlateCompositionIntoDB.class.getCanonicalName(), HELP_MESSAGE, opts, null,
                true);
        return;
    }

    File lcmsDir = new File(cl.getOptionValue(OPTION_DIRECTORY));
    if (!lcmsDir.isDirectory()) {
        System.err.format("File at %s is not a directory\n", lcmsDir.getAbsolutePath());
        HELP_FORMATTER.printHelp(LoadPlateCompositionIntoDB.class.getCanonicalName(), HELP_MESSAGE, opts, null,
                true);
        System.exit(1);
    }

    Double fontScale = null;
    if (cl.hasOption("font-scale")) {
        try {
            fontScale = Double.parseDouble(cl.getOptionValue("font-scale"));
        } catch (IllegalArgumentException e) {
            System.err.format("Argument for font-scale must be a floating point number.\n");
            System.exit(1);
        }
    }

    try (DB db = DB.openDBFromCLI(cl)) {
        Set<String> includeIons = null;
        if (cl.hasOption("include-ions")) {
            String[] ionNames = cl.getOptionValues("include-ions");
            includeIons = new HashSet<>(Arrays.asList(ionNames));
            System.out.format("Including ions in search: %s\n", StringUtils.join(includeIons, ", "));
        }
        Set<String> excludeIons = null;
        if (cl.hasOption("exclude-ions")) {
            String[] ionNames = cl.getOptionValues("exclude-ions");
            excludeIons = new HashSet<>(Arrays.asList(ionNames));
            System.out.format("Excluding ions from search: %s\n", StringUtils.join(excludeIons, ", "));
        }

        Set<Integer> takeSamplesFromPlateIds = null;
        if (cl.hasOption(OPTION_FILTER_BY_PLATE_BARCODE)) {
            String[] plateBarcodes = cl.getOptionValues(OPTION_FILTER_BY_PLATE_BARCODE);
            System.out.format("Considering only sample wells in plates: %s\n",
                    StringUtils.join(plateBarcodes, ", "));
            takeSamplesFromPlateIds = new HashSet<>(plateBarcodes.length);
            for (String plateBarcode : plateBarcodes) {
                Plate p = Plate.getPlateByBarcode(db, plateBarcode);
                if (p == null) {
                    System.err.format("WARNING: unable to find plate in DB with barcode %s\n", plateBarcode);
                } else {
                    takeSamplesFromPlateIds.add(p.getId());
                }
            }
            // Allow filtering on barcode even if we couldn't find any in the DB.
        }

        System.out.format("Loading/updating LCMS scan files into DB\n");
        ScanFile.insertOrUpdateScanFilesInDirectory(db, lcmsDir);

        System.out.format("Processing LCMS scans\n");
        Pair<List<LCMSWell>, Set<Integer>> positiveWellsAndPlateIds = Utils.extractWellsAndPlateIds(db,
                cl.getOptionValues(OPTION_STRAINS), cl.getOptionValues(OPTION_CONSTRUCTS),
                takeSamplesFromPlateIds, false);
        List<LCMSWell> positiveWells = positiveWellsAndPlateIds.getLeft();
        if (positiveWells.size() == 0) {
            throw new RuntimeException("Found no LCMS wells for specified strains/constructs");
        }
        // Only take negative samples from the plates where we found the positive samples.
        Pair<List<LCMSWell>, Set<Integer>> negativeWellsAndPlateIds = Utils.extractWellsAndPlateIds(db,
                cl.getOptionValues(OPTION_NEGATIVE_STRAINS), cl.getOptionValues(OPTION_NEGATIVE_CONSTRUCTS),
                positiveWellsAndPlateIds.getRight(), true);
        List<LCMSWell> negativeWells = negativeWellsAndPlateIds.getLeft();
        if (negativeWells == null || negativeWells.size() == 0) {
            System.err.format("WARNING: no valid negative samples found in same plates as positive samples\n");
        }

        // Extract the reference MZ that will be used in the LCMS trace processing.
        List<Pair<String, Double>> searchMZs = null;
        Set<CuratedChemical> standardChemicals = null;
        List<ChemicalAssociatedWithPathway> pathwayChems = null;
        if (cl.hasOption(OPTION_SEARCH_MZ)) {
            // Assume mz can be an FP number of a chemical name.
            String massStr = cl.getOptionValue(OPTION_SEARCH_MZ);
            Pair<String, Double> searchMZ = Utils.extractMassFromString(db, massStr);
            if (searchMZ != null) {
                searchMZs = Collections.singletonList(searchMZ);
            }
            standardChemicals = Utils.extractTargetsForWells(db, positiveWells);
        } else {
            CuratedChemical targetChemical = Utils.requireOneTarget(db, positiveWells);
            if (targetChemical == null) {
                throw new RuntimeException(
                        "Unable to find a curated chemical entry for specified strains'/constructs' targets.  "
                                + "Please specify a chemical name or m/z explicitly or update the curated chemicals list in the DB.");
            }
            System.out.format("Using reference M/Z for positive target %s (%f)\n", targetChemical.getName(),
                    targetChemical.getMass());
            searchMZs = Collections.singletonList(Pair.of(targetChemical.getName(), targetChemical.getMass()));
            standardChemicals = Collections.singleton(targetChemical);
        }

        // Look up the standard by name, or use the target if none is specified.
        List<StandardWell> standardWells = null;
        if (cl.hasOption(OPTION_NO_STANDARD)) {
            System.err.format("WARNING: skipping standard comparison (no-standard option specified)\n");
            standardWells = new ArrayList<>(0);
        } else if (cl.hasOption(OPTION_STANDARD_WELLS)) {
            String[] standardCoordinates = cl.getOptionValues(OPTION_STANDARD_WELLS);
            standardWells = new ArrayList<>(standardCoordinates.length);
            Plate standardPlate = Plate.getPlateByBarcode(db, cl.getOptionValue(OPTION_STANDARD_PLATE_BARCODE));
            List<String> foundCoordinates = new ArrayList<>(standardCoordinates.length);
            for (String stringCoords : standardCoordinates) {
                Pair<Integer, Integer> coords = Utils.parsePlateCoordinates(stringCoords);
                StandardWell well = StandardWell.getInstance().getStandardWellsByPlateIdAndCoordinates(db,
                        standardPlate.getId(), coords.getLeft(), coords.getRight());
                if (well == null) {
                    System.err.format("Unable to find standard well at %s [%s]\n", standardPlate.getBarcode(),
                            stringCoords);
                    continue;
                }
                standardWells.add(well);
                foundCoordinates.add(stringCoords);
            }
            System.out.format("Using explicitly specified standard wells %s [%s]\n", standardPlate.getBarcode(),
                    StringUtils.join(foundCoordinates, ", "));
        } else if (cl.hasOption(OPTION_STANDARD_NAME)) {
            String standardName = cl.getOptionValue(OPTION_STANDARD_NAME);
            System.out.format("Using explicitly specified standard %s\n", standardName);
            standardWells = Collections.singletonList(Utils.extractStandardWellFromPlate(db,
                    cl.getOptionValue(OPTION_STANDARD_PLATE_BARCODE), standardName));
        } else if (standardChemicals != null && standardChemicals.size() > 0) {
            // Default to using the target chemical(s) as a standard if none is specified.
            standardWells = new ArrayList<>(standardChemicals.size());
            for (CuratedChemical c : standardChemicals) {
                String standardName = c.getName();
                System.out.format("Searching for well containing standard %s\n", standardName);
                standardWells.add(Utils.extractStandardWellFromPlate(db,
                        cl.getOptionValue(OPTION_STANDARD_PLATE_BARCODE), standardName));
            }
        }

        boolean useFineGrainedMZ = cl.hasOption("fine-grained-mz");
        boolean useSNR = cl.hasOption(OPTION_USE_SNR);

        /* Process the standard, positive, and negative wells, producing ScanData containers that will allow them to be
         * iterated over for graph writing. */
        HashMap<Integer, Plate> plateCache = new HashMap<>();
        Pair<List<ScanData<StandardWell>>, Double> allStandardScans = AnalysisHelper.processScans(db, lcmsDir,
                searchMZs, ScanData.KIND.STANDARD, plateCache, standardWells, useFineGrainedMZ, includeIons,
                excludeIons, useSNR);
        Pair<List<ScanData<LCMSWell>>, Double> allPositiveScans = AnalysisHelper.processScans(db, lcmsDir,
                searchMZs, ScanData.KIND.POS_SAMPLE, plateCache, positiveWells, useFineGrainedMZ, includeIons,
                excludeIons, useSNR);
        Pair<List<ScanData<LCMSWell>>, Double> allNegativeScans = AnalysisHelper.processScans(db, lcmsDir,
                searchMZs, ScanData.KIND.NEG_CONTROL, plateCache, negativeWells, useFineGrainedMZ, includeIons,
                excludeIons, useSNR);

        String fmt = "pdf";
        String outImg = cl.getOptionValue(OPTION_OUTPUT_PREFIX) + "." + fmt;
        String outData = cl.getOptionValue(OPTION_OUTPUT_PREFIX) + ".data";
        System.err.format("Writing combined scan data to %s and graphs to %s\n", outData, outImg);

        produceLCMSSearchPlots(lcmsDir, outData, outImg, allStandardScans, allPositiveScans, allNegativeScans,
                fontScale, useFineGrainedMZ, cl.hasOption(OPTION_USE_HEATMAP), useSNR);
    }
}

From source file:com.epam.dlab.Help.java

/** Print help to console.
 * @param resourceName the name of resource.
 * @param substitute - map for substitution in help content.
 * @throws InitializationException//w w w.j a  v  a 2  s .  c om
 */
private static void printHelp(String resourceName, Map<String, String> substitute)
        throws InitializationException {
    List<String> list = BillingUtils
            .getResourceAsList("/" + Help.class.getName() + "." + resourceName + ".txt");
    String help = StringUtils.join(list, System.lineSeparator());

    if (substitute == null) {
        substitute = new HashMap<>();
    }
    substitute.put("classname", BillingScheduler.class.getName());

    for (String key : substitute.keySet()) {
        help = StringUtils.replace(help, "${" + key.toUpperCase() + "}", substitute.get(key));
    }
    System.out.println(help);
}

From source file:dsd.dao.RawDataDAO.java

public static int InsertRawData(List<RawData> listOfData) {
    try {//from   w w w  .j av  a  2s.c o  m
        Connection con = DAOProvider.getDataSource().getConnection();
        int counter = 0;
        try {
            counter += DAOProvider.InsertRowsSecure(tableName, StringUtils.join(fields, ','), con,
                    PrepareMultipleValuesForInsert(listOfData));
        } catch (Exception exc) {
            exc.printStackTrace();
        }
        con.close();
        return counter;
    } catch (Exception exc) {
        exc.printStackTrace();
    }
    return 0;
}

From source file:com.lyncode.jtwig.exception.UnknownExpressionException.java

public UnknownExpressionException() {
    super("Known expressions: " + StringUtils.join(new String[] { JtwigKeyword.FOR.toString(),
            JtwigKeyword.IF.toString(), JtwigKeyword.BLOCK.toString(), JtwigKeyword.INCLUDE.toString(),
            JtwigKeyword.SET.toString() }, ", "));
}

From source file:com.moscona.dataSpace.debug.ByteBufferTest.java

public static void print(String label, ByteBuffer buf) {
    System.out.println(label + ":");
    ArrayList<String> l = new ArrayList<String>();
    for (byte b : buf.array()) {
        l.add(Byte.toString(b));// ww  w  .  j a v  a  2 s .c  o m
    }
    System.out.println("  " + StringUtils.join(l, ", "));
}

From source file:io.wcm.caravan.pipeline.extensions.hal.filter.ReportHalResourceFilters.java

/**
 * Executes all delegated filters and creates a report with error messages for each failed filter. If there are
 * negative predicate results, all further predicates still get executed.
 *//*from  w  ww.jav  a 2s  .  c  o  m*/
public static HalResourcePredicate all(HalResource report, HalResourcePredicate... delegates) {

    return new HalResourcePredicate() {

        @Override
        public String getId() {
            List<String> ids = Stream.of(delegates).map(matcher -> matcher.getId())
                    .collect(java.util.stream.Collectors.toList());
            return "ALL(" + StringUtils.join(ids, '+') + ")";
        }

        @Override
        public boolean apply(HalPath halPath, HalResource hal) {

            List<String> errors = Stream.of(delegates).filter(delegate -> !delegate.apply(halPath, hal))
                    .map(delegate -> delegate.getId()).collect(java.util.stream.Collectors.toList());

            if (!errors.isEmpty()) {
                report.addEmbedded("item", createReport(halPath, hal, errors));
            }
            return errors.isEmpty();

        }

    };

}

From source file:graph.core.CyclicErrorEdge.java

@Override
public String getError() {
    return "Asserting (" + StringUtils.join(cyclicAssertion_, " ") + ") would create a cycle.";
}

From source file:com.microsoft.applicationinsights.web.internal.cookies.Cookie.java

/**
 * Formats the given values to a session cookie value.
 * @param values The values to format./*from   www .j a  va2s .  co m*/
 * @return Formatted session cookie.
 */
public static String formatCookie(String[] values) {
    return StringUtils.join(values, RAW_COOKIE_DELIMITER);
}

From source file:dsd.dao.ParsedInputFilesDAO.java

public static int InsertParsedInputFile(List<ParsedInputFile> listOfParsedInputFile) {
    try {/*w w w . j a va2s .c  om*/
        Connection con = DAOProvider.getDataSource().getConnection();
        int counter = 0;
        for (ParsedInputFile parsedInputFile : listOfParsedInputFile) {
            try {
                counter += DAOProvider.InsertRowSecure(tableName, StringUtils.join(tableFields, ','), con,
                        PrepareValuesForInsert(parsedInputFile));
            } catch (Exception exc) {
                exc.printStackTrace();
            }
        }
        con.close();
        return counter;
    } catch (Exception exc) {
        exc.printStackTrace();
    }
    return 0;
}