Example usage for java.lang String join

List of usage examples for java.lang String join

Introduction

In this page you can find the example usage for java.lang String join.

Prototype

public static String join(CharSequence delimiter, Iterable<? extends CharSequence> elements) 

Source Link

Document

Returns a new String composed of copies of the CharSequence elements joined together with a copy of the specified delimiter .

Usage

From source file:com.nestedbird.modules.facebookreader.FacebookReader.java

/**
 * Generates the URL to request the data from facebook with
 *
 * @param id     the identifier of the resource
 * @param fields what info are we requesting
 * @return the url/*from   ww w.j a  v a 2s .  c  om*/
 */
private String generateRequestUrl(final String id, final String[] fields) {
    return String.format("https://graph.facebook.com/%s/?fields=%s&access_token=%s&limit=60", id,
            String.join(",", fields), socialConfigSettings.getFbAccessToken());
}

From source file:org.mitre.ptmatchadapter.service.ServerAuthorizationService.java

/**
 * //  w  w w.j  ava2  s .  c  o m
 * @param reqHdrs
 * @param respHdrs
 */
public final void handleOptions(@Headers Map<String, Object> reqHdrs,
        @OutHeaders Map<String, Object> respHdrs) {

    final List<String> supportedHttpMethodsList = Arrays.asList("GET", "POST", "PUT", "DELETE", "OPTIONS");
    final String supportedHttpMethods = String.join(", ", supportedHttpMethodsList);

    respHdrs.put(Exchange.CONTENT_LENGTH, 0);
    respHdrs.put("Allow", supportedHttpMethods);

    // Write out message request headers
    if (LOG.isDebugEnabled()) {
        for (String key : reqHdrs.keySet()) {
            LOG.debug("handlOptions: req key: {} val: {}", key, reqHdrs.get(key));
        }
    }

    // request headers are considered case-insensitive, but camel has not normalized
    String origin = (String) reqHdrs.get("Origin");
    if (origin == null) {
        origin = (String) reqHdrs.get("origin");
    }
    LOG.debug("handleOptions: origin {}", origin);

    // Section 3.2 of RFC 7230 (https://tools.ietf.org/html/rfc7230#section-3.2)
    // says header fields are case-insensitive
    if (origin != null) {

        final String corsRequestMethod = (String) reqHdrs.get("Access-Control-Request-Method");
        LOG.info("handleOptions: corsRequestMethod {}", corsRequestMethod);

        // The W3C CORS Spec only seems to care, at a minimum, that a request
        // method header exists.  The response includes the supported methods,
        // regardless of the method in the request header (or so I read it).
        if (corsRequestMethod != null) {
            // Return a list of methods we allow
            respHdrs.put("Access-Control-Allow-Methods", supportedHttpMethods);
            respHdrs.put("Access-Control-Allow-Origin", origin);
            respHdrs.put("Access-Control-Allow-Credentials", "true");
            // Max Age - # of seconds the browser may cache this response
            respHdrs.put("Access-Control-Max-Age", 43200);
            final Object corsRequestHeaders = reqHdrs.get("Access-Control-Request-Headers");
            respHdrs.put("Access-Control-Allow-Headers", corsRequestHeaders);
        } else {
            // Origin header found, but no Request-Method, so invalid request
            respHdrs.put(Exchange.HTTP_RESPONSE_CODE, 400); // BAD REQUEST 
        }

        // Write out response headers
        if (LOG.isDebugEnabled()) {
            for (String key : respHdrs.keySet()) {
                LOG.debug("handleOptions: resp key: {} val: {}", key, respHdrs.get(key));
            }
        }

    } else {
        // A normal OPTIONS request wouldn't have any CORS headers, so treat as OK
    }
}

From source file:com.sisrni.managedbean.ProyectoReportMB.java

public String obtenerFacultades(List<Facultad> listFacultades) {
    List<String> nombreFacultad = new ArrayList<String>();
    for (Facultad facultad : listFacultades) {
        nombreFacultad.add(facultad.getNombreFacultad());
    }//w ww.jav  a  2s  .com
    return String.join(",", nombreFacultad);
}

From source file:org.ameba.aop.ServiceLayerAspect.java

/**
 * Called after an exception is thrown by classes of the service layer. <p> Set log level to ERROR to log the root cause. </p>
 *
 * @param ex The root exception that is thrown
 * @return Returns the exception to be thrown
 *///from ww w.j a v  a 2 s.c  o m
public Exception translateException(Exception ex) {
    if (ex instanceof BusinessRuntimeException) {
        BusinessRuntimeException bre = (BusinessRuntimeException) ex;
        MDC.put(LoggingCategories.MSGKEY, bre.getMsgKey());
        if (bre.getData() != null) {
            MDC.put(LoggingCategories.MSGDATA,
                    String.join(",", Stream.of(bre.getData()).map(Object::toString).toArray(String[]::new)));
        }
        // cleanup of context is done in SLF4JMappedDiagnosticContextFilter
        return bre;
    }

    Optional<Exception> handledException = doTranslateException(ex);
    if (handledException.isPresent()) {
        return handledException.get();
    }
    if (ex instanceof ServiceLayerException) {
        return ex;
    }
    return withRootCause ? new ServiceLayerException(ex.getMessage(), ex)
            : new ServiceLayerException(ex.getMessage());
}

From source file:fi.helsinki.opintoni.web.rest.publicapi.PublicCalendarFeedResourceTest.java

private String eventToString(String... args) {
    return String.join(CRLF, args);
}

From source file:ca.mcgill.cs.crown.data.WiktionaryReader.java

private static List<LexicalEntry> convertToEntries(List<JSONObject> rawEntries) {

    // Avoid the potential for duplicates in the entries
    Set<String> alreadyIncluded = new HashSet<String>();
    int excluded = 0;

    List<LexicalEntry> entries = new ArrayList<LexicalEntry>();
    for (JSONObject jo : rawEntries) {
        try {//  w w  w  . j ava  2 s .c o  m
            String posStr = jo.getString("pos").toUpperCase();
            String lemma = jo.getString("lemma");
            String id = jo.getString("id");
            // Check for duplicates
            if (alreadyIncluded.contains(lemma + "." + posStr + ":" + id)) {
                excluded++;
                continue;
            }
            alreadyIncluded.add(lemma + ":" + id);
            LexicalEntry e = new LexicalEntryImpl(lemma, id, POS.valueOf(posStr));
            Set<String> glosses = new LinkedHashSet<String>();
            Map<String, String> rawGlossToCleaned = new LinkedHashMap<String, String>();

            JSONArray glossArr = jo.getJSONArray("glosses");
            for (int i = 0; i < glossArr.length(); ++i) {
                String rawGloss = glossArr.getString(i);
                String cleaned = WiktionaryUtils.cleanGloss(rawGloss);
                glosses.add(cleaned);
                rawGlossToCleaned.put(rawGloss, cleaned);
            }

            String combinedGloss = String.join(" ", glosses);

            List<Relation> relations = new ArrayList<Relation>();
            JSONArray relationsArr = jo.getJSONArray("relations");
            for (int i = 0; i < relationsArr.length(); ++i) {
                JSONObject relObj = relationsArr.getJSONObject(i);
                Relation rel = new RelationImpl(relObj.getString("targetLemma"),
                        relObj.optString("targetSense"),
                        Relation.RelationType.valueOf(relObj.getString("type")));
                relations.add(rel);
            }

            CoreMap m = e.getAnnotations();
            m.set(CrownAnnotations.Gloss.class, combinedGloss);
            m.set(CrownAnnotations.Glosses.class, glosses);
            m.set(CrownAnnotations.RawGlosses.class, rawGlossToCleaned);
            m.set(CrownAnnotations.Relations.class, relations);

            entries.add(e);
        } catch (JSONException je) {
            throw new IOError(je);
        }
    }

    CrownLogger.verbose("Excluded %d duplicate entries", excluded);

    return entries;
}

From source file:uk.ac.ebi.eva.server.ws.GeneWSServer.java

@RequestMapping(value = "/{geneIds}/variants", method = RequestMethod.GET)
//    @ApiOperation(httpMethod = "GET", value = "Retrieves all the variants of a gene", response = QueryResponse.class)
public QueryResponse getVariantsByGene(@PathVariable("geneIds") List<String> geneIds,
        @RequestParam(name = "species") String species,
        @RequestParam(name = "studies", required = false) String studies,
        @RequestParam(name = "annot-ct", required = false) List<String> consequenceType,
        @RequestParam(name = "maf", defaultValue = "") String maf,
        @RequestParam(name = "polyphen", defaultValue = "") String polyphenScore,
        @RequestParam(name = "sift", defaultValue = "") String siftScore,
        @RequestParam(name = "ref", defaultValue = "") String reference,
        @RequestParam(name = "alt", defaultValue = "") String alternate,
        @RequestParam(name = "miss_alleles", defaultValue = "") String missingAlleles,
        @RequestParam(name = "miss_gts", defaultValue = "") String missingGenotypes)
        throws IllegalOpenCGACredentialsException, UnknownHostException, IOException {
    initializeQueryOptions();//from ww  w  . j ava2s .  c om

    VariantDBAdaptor variantMongoDbAdaptor = DBAdaptorConnector.getVariantDBAdaptor(species);

    if (studies != null && !studies.isEmpty()) {
        queryOptions.put(VariantDBAdaptor.STUDIES, studies);
    }

    if (consequenceType != null && !consequenceType.isEmpty()) {
        queryOptions.put(VariantDBAdaptor.ANNOT_CONSEQUENCE_TYPE, consequenceType);
    }

    if (!maf.isEmpty()) {
        queryOptions.put(VariantDBAdaptor.MAF, maf);
    }
    if (!polyphenScore.isEmpty()) {
        queryOptions.put(VariantDBAdaptor.POLYPHEN, polyphenScore);
    }
    if (!siftScore.isEmpty()) {
        queryOptions.put(VariantDBAdaptor.SIFT, siftScore);
    }

    if (!reference.isEmpty()) {
        queryOptions.put(VariantDBAdaptor.REFERENCE, reference);
    }
    if (!alternate.isEmpty()) {
        queryOptions.put(VariantDBAdaptor.ALTERNATE, alternate);
    }

    if (!missingAlleles.isEmpty()) {
        queryOptions.put(VariantDBAdaptor.MISSING_ALLELES, missingAlleles);
    }
    if (!missingGenotypes.isEmpty()) {
        queryOptions.put(VariantDBAdaptor.MISSING_GENOTYPES, missingGenotypes);
    }

    queryOptions.put(VariantDBAdaptor.SORT, new BasicDBObject("chr", 1).append("start", 1));
    queryOptions.put(VariantDBAdaptor.GENE, String.join(",", geneIds));

    return setQueryResponse(variantMongoDbAdaptor.getAllVariants(queryOptions));
}

From source file:io.sqp.proxy.customtypes.CustomTypeMapper.java

private String findMappingInRepo(SchemaMatcher matcher, List<String> keywords, TypeRepository repository,
        String repoName) throws TypeMappingNotPossibleException {
    ArrayList<String> keywordTypes = new ArrayList<>();
    ArrayList<String> otherTypes = new ArrayList<>();
    repository.getNativeTypes()/*from w  w  w .  jav  a2s  .c  o m*/
            .forEach(type -> (typeMatchesAnyKeyword(type, keywords) ? keywordTypes : otherTypes).add(type));

    String match;
    if (keywordTypes.size() > 0) {
        match = findMapping(matcher, repository, keywordTypes);
        if (match != null) {
            return match;
        } else {
            _logger.log(Level.INFO, "Didn't find a native type matching the schema with keywords: '"
                    + String.join(", ", keywords) + "' in " + repoName);
        }
    }
    match = findMapping(matcher, repository, otherTypes);
    if (match == null) {
        _logger.log(Level.INFO, "Didn't find any native type matching the schema in " + repoName);
    }
    return match;
}

From source file:PatternFinder.java

private List<String> getFileNames(String search, List<String> fileNames, Path dir) {
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) {
        for (Path path : stream) {
            if (path.toFile().isDirectory()) {
                getFileNames(search, fileNames, path);
            } else {

                String fileName = path.toAbsolutePath().getFileName().toString();
                String[] data = search.split("-");
                if (data[0] != null && (data[0].equals("atoms") || data[0].equals("molecules")
                        || data[0].equals("organisms")))
                    data = (String[]) ArrayUtils.remove(data, 0);

                String differentSearchTerm = String.join("-", data).toLowerCase();

                //Search for patternlab identifier in filesystem
                if (fileName.contains(differentSearchTerm) || fileName.contains(search)) {
                    fileNames.add(path.toAbsolutePath().toString());

                }/*from  w w  w.j a  v  a 2s. c o m*/

            }
        }
    } catch (IOException e) {
        //e.printStackTrace();
    }
    return fileNames;
}