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:se.inera.intyg.intygstjanst.web.integration.RegisterCertificateResponderImpl.java

@Override
public RegisterCertificateResponseType registerCertificate(String logicalAddress,
        RegisterCertificateType registerCertificate) {
    try {/* w  w  w  .j a v  a  2  s  . c  o m*/
        String intygsTyp = getIntygsTyp(registerCertificate);
        ModuleApi api = moduleRegistry.getModuleApi(intygsTyp);
        String xml = xmlToString(registerCertificate);
        ValidateXmlResponse validationResponse = api.validateXml(xml);

        if (!validationResponse.hasErrorMessages()) {
            return storeIntyg(registerCertificate, intygsTyp, api, xml);
        } else {
            String validationErrors = String.join(";", validationResponse.getValidationErrors());
            return makeValidationErrorResult(validationErrors);
        }
    } catch (CertificateAlreadyExistsException e) {
        return makeCertificateAlreadyExistsResult(registerCertificate);
    } catch (InvalidCertificateException e) {
        return makeInvalidCertificateResult(registerCertificate);
    } catch (ConverterException e) {
        return makeValidationErrorResult(e.getMessage());
    } catch (JAXBException e) {
        LOGGER.error("JAXB error in Webservice: ", e);
        Throwables.propagate(e);
    } catch (NotImplementedException e) {
        LOGGER.error("This webservice is not valid for the current certificate type {}",
                registerCertificate.getIntyg());
        Throwables.propagate(e);
    } catch (Exception e) {
        LOGGER.error("Error in Webservice: ", e);
        Throwables.propagate(e);
    }
    throw new RuntimeException("Unrecoverable exception in registerCertificate");
}

From source file:org.wallride.web.controller.admin.article.ArticlePreviewController.java

@RequestMapping
public void preview(@PathVariable String language, @Valid @ModelAttribute("form") ArticlePreviewForm form,
        BindingResult result, AuthorizedUser authorizedUser, Model model, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    Article article = new Article();
    article.setLanguage(language);/*  w w  w  .j a v a  2s .  c om*/
    article.setCover(form.getCoverId() != null ? mediaService.getMedia(form.getCoverId()) : null);
    article.setTitle(form.getTitle());
    article.setBody(form.getBody());
    article.setDate(form.getDate() != null ? form.getDate() : LocalDateTime.now());

    List<CustomFieldValue> fieldValues = new ArrayList<>();
    for (CustomFieldValueEditForm valueForm : form.getCustomFieldValues()) {
        CustomFieldValue value = new CustomFieldValue();
        value.setCustomField(customFieldService.getCustomFieldById(valueForm.getCustomFieldId(), language));
        if (valueForm.getFieldType().equals(CustomField.FieldType.CHECKBOX)
                && !ArrayUtils.isEmpty(valueForm.getTextValues())) {
            value.setTextValue(String.join(",", valueForm.getTextValues()));
        } else {
            value.setTextValue(valueForm.getTextValue());
        }
        value.setStringValue(valueForm.getStringValue());
        value.setNumberValue(valueForm.getNumberValue());
        value.setDateValue(valueForm.getDateValue());
        value.setDatetimeValue(valueForm.getDatetimeValue());
        fieldValues.add(value);
    }
    article.setCustomFieldValues(new TreeSet<>(fieldValues));
    article.setAuthor(authorizedUser);

    WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext,
            "org.springframework.web.servlet.FrameworkServlet.CONTEXT.guestServlet");
    if (context == null) {
        throw new ServiceException("GuestServlet is not ready yet");
    }

    Blog blog = blogService.getBlogById(Blog.DEFAULT_ID);
    BlogLanguage blogLanguage = blog.getLanguage(language);
    request.setAttribute(BlogLanguageMethodArgumentResolver.BLOG_LANGUAGE_ATTRIBUTE, blogLanguage);

    DefaultModelAttributeInterceptor interceptor = context.getBean(DefaultModelAttributeInterceptor.class);
    ModelAndView mv = new ModelAndView("dummy");
    interceptor.postHandle(request, response, this, mv);

    final WebContext ctx = new WebContext(request, response, servletContext, LocaleContextHolder.getLocale(),
            mv.getModelMap());
    ctx.setVariable("article", article);

    ThymeleafEvaluationContext evaluationContext = new ThymeleafEvaluationContext(context, null);
    ctx.setVariable(ThymeleafEvaluationContext.THYMELEAF_EVALUATION_CONTEXT_CONTEXT_VARIABLE_NAME,
            evaluationContext);

    SpringTemplateEngine templateEngine = context.getBean("templateEngine", SpringTemplateEngine.class);
    String html = templateEngine.process("article/describe", ctx);

    response.setContentType("text/html;charset=UTF-8");
    response.setContentLength(html.getBytes("UTF-8").length);
    response.getWriter().write(html);
}

From source file:org.wallride.web.controller.admin.page.PagePreviewController.java

@RequestMapping
public void preview(@PathVariable String language, @Valid @ModelAttribute("form") PagePreviewForm form,
        BindingResult result, AuthorizedUser authorizedUser, Model model, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    Page page = new Page();
    page.setLanguage(language);//from  ww  w . ja va 2  s  . c om
    page.setCover(form.getCoverId() != null ? mediaService.getMedia(form.getCoverId()) : null);
    page.setTitle(form.getTitle());
    page.setBody(form.getBody());
    page.setDate(form.getDate() != null ? form.getDate() : LocalDateTime.now());
    List<CustomFieldValue> fieldValues = new ArrayList<>();
    for (CustomFieldValueEditForm valueForm : form.getCustomFieldValues()) {
        CustomFieldValue value = new CustomFieldValue();
        value.setCustomField(customFieldService.getCustomFieldById(valueForm.getCustomFieldId(), language));
        if (valueForm.getFieldType().equals(CustomField.FieldType.CHECKBOX)
                && !ArrayUtils.isEmpty(valueForm.getTextValues())) {
            value.setTextValue(String.join(",", valueForm.getTextValues()));
        } else {
            value.setTextValue(valueForm.getTextValue());
        }
        value.setStringValue(valueForm.getStringValue());
        value.setNumberValue(valueForm.getNumberValue());
        value.setDateValue(valueForm.getDateValue());
        value.setDatetimeValue(valueForm.getDatetimeValue());
        fieldValues.add(value);
    }
    page.setCustomFieldValues(new TreeSet<>(fieldValues));
    page.setAuthor(authorizedUser);

    WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext,
            "org.springframework.web.servlet.FrameworkServlet.CONTEXT.guestServlet");
    if (context == null) {
        throw new ServiceException("GuestServlet is not ready yet");
    }

    Blog blog = blogService.getBlogById(Blog.DEFAULT_ID);
    BlogLanguage blogLanguage = blog.getLanguage(language);
    request.setAttribute(BlogLanguageMethodArgumentResolver.BLOG_LANGUAGE_ATTRIBUTE, blogLanguage);

    DefaultModelAttributeInterceptor interceptor = context.getBean(DefaultModelAttributeInterceptor.class);
    ModelAndView mv = new ModelAndView("dummy");
    interceptor.postHandle(request, response, this, mv);

    final WebContext ctx = new WebContext(request, response, servletContext, LocaleContextHolder.getLocale(),
            mv.getModelMap());
    ctx.setVariable("page", page);

    ThymeleafEvaluationContext evaluationContext = new ThymeleafEvaluationContext(context, null);
    ctx.setVariable(ThymeleafEvaluationContext.THYMELEAF_EVALUATION_CONTEXT_CONTEXT_VARIABLE_NAME,
            evaluationContext);

    SpringTemplateEngine templateEngine = context.getBean("templateEngine", SpringTemplateEngine.class);
    String html = templateEngine.process("page/describe", ctx);

    response.setContentType("text/html;charset=UTF-8");
    response.setContentLength(html.getBytes("UTF-8").length);
    response.getWriter().write(html);
}

From source file:com.netflix.spinnaker.clouddriver.kubernetes.v2.op.manifest.AbstractKubernetesEnableDisableManifestOperation.java

public List<String> determineLoadBalancers(KubernetesManifest target) {
    getTask().updateStatus(OP_NAME, "Getting load balancer list to " + getVerbName() + "...");
    List<String> result = description.getLoadBalancers();
    if (result != null && !result.isEmpty()) {
        getTask().updateStatus(OP_NAME, "Using supplied list [" + String.join(", ", result) + "]");
    } else {//www.  ja  v  a 2 s  .  c  o m
        KubernetesManifestTraffic traffic = KubernetesManifestAnnotater.getTraffic(target);
        result = traffic.getLoadBalancers();
        getTask().updateStatus(OP_NAME, "Using annotated list [" + String.join(", ", result) + "]");
    }

    return result;
}

From source file:com.kalessil.phpStorm.phpInspectionsEA.inspectors.phpDoc.UnknownInspectionInspector.java

@Override
@NotNull/* w w  w  .  j av a2 s  . c  o m*/
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
    return new BasePhpElementVisitor() {
        public void visitPhpDocTag(@NotNull PhpDocTag tag) {
            if (!tag.getName().equals("@noinspection")) {
                return;
            }

            /* cleanup the tag and ensure we have anything to check */
            final String tagValue = tag.getTagValue().replaceAll("[^\\p{L}\\p{Nd}]+", " ").trim();
            final String[] suppressed = tagValue.split("\\s+");
            if (0 == suppressed.length || 0 == tagValue.length()) {
                return;
            }

            /* check if all suppressed inspections are known */
            final List<String> reported = new ArrayList<>();
            for (String suppression : suppressed) {
                if (suppression.length() >= minInspectionNameLength
                        && !inspectionsNames.contains(suppression)) {
                    reported.add(suppression);
                }
            }

            /* report unknown inspections; if inspections provided by not loaded plugin they are reported */
            if (reported.size() > 0) {
                final PsiElement target = tag.getFirstChild();
                if (null != target) {
                    holder.registerProblem(target, message.replace("%i%", String.join(", ", reported)),
                            ProblemHighlightType.WEAK_WARNING);
                }

                reported.clear();
            }
        }
    };
}

From source file:ch.icclab.cyclops.persistence.orm.InstanceORM.java

/**
 * Parse List and return it as serialised string
 * @param list to be serialised// w ww . jav  a2  s .  com
 * @return string
 */
private String getListAsString(Set list) {
    return String.join(",", list);
}

From source file:com.kalessil.phpStorm.yii2inspections.inspectors.MissingPropertyAnnotationsInspector.java

@Override
@NotNull//from  ww  w . ja v  a  2  s. c  o  m
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
    return new PhpElementVisitor() {
        @Override
        public void visitPhpClass(PhpClass clazz) {
            /* check only regular named classes */
            final PsiElement nameNode = NamedElementUtil.getNameIdentifier(clazz);
            if (null == nameNode) {
                return;
            }

            /* check if the class inherited from yii\base\Object */
            boolean supportsPropertyFeature = false;
            final Set<PhpClass> parents = InheritanceChainExtractUtil.collect(clazz);
            if (!parents.isEmpty()) {
                for (final PhpClass parent : parents) {
                    if (baseObjectClasses.contains(parent.getFQN())) {
                        supportsPropertyFeature = true;
                        break;
                    }
                }

                parents.clear();
            }
            if (!supportsPropertyFeature) {
                return;
            }

            /* iterate get methods, find matching set methods */
            final Map<String, String> props = this.findPropertyCandidates(clazz);
            if (props.size() > 0) {
                List<String> names = new ArrayList<>(props.keySet());
                Collections.sort(names);
                final String message = messagePattern.replace("%p%", String.join("', '", names));
                holder.registerProblem(nameNode, message, ProblemHighlightType.WEAK_WARNING,
                        new TheLocalFix(props));
            }
        }

        @NotNull
        private Map<String, String> findPropertyCandidates(@NotNull PhpClass clazz) {
            final Map<String, String> properties = new HashMap<>();

            /* extract methods and operate on name-methods relations */
            final Method[] methods = clazz.getOwnMethods();
            if (null == methods || 0 == methods.length) {
                return properties;
            }
            final Map<String, Method> mappedMethods = new HashMap<>();
            for (Method method : methods) {
                mappedMethods.put(method.getName(), method);
            }

            /* process extracted methods*/
            for (String candidate : mappedMethods.keySet()) {
                Method getterMethod = null;
                Method setterMethod = null;

                /* extract methods: get (looks up and extracts set), set (looks up get and skipped if found) */
                if (candidate.startsWith("get")) {
                    getterMethod = mappedMethods.get(candidate);
                    if (getterMethod.isStatic() || 0 != getterMethod.getParameters().length) {
                        getterMethod = null;
                    }

                    final String complimentarySetter = candidate.replaceAll("^get", "set");
                    if (mappedMethods.containsKey(complimentarySetter)) {
                        setterMethod = mappedMethods.get(complimentarySetter);
                        if (setterMethod.isStatic() || 0 == setterMethod.getParameters().length) {
                            setterMethod = null;
                        }

                    }
                }
                if (candidate.startsWith("set")) {
                    setterMethod = mappedMethods.get(candidate);
                    if (setterMethod.isStatic() || setterMethod.getParameters().length != 1) {
                        setterMethod = null;
                    }

                    final String complimentaryGetter = candidate.replaceAll("^set", "get");
                    if (mappedMethods.containsKey(complimentaryGetter)) {
                        continue;
                    }
                }

                /* ensure that strategies are reachable */
                if ((null == getterMethod && null == setterMethod)
                        || (REQUIRE_BOTH_GETTER_SETTER && (null == getterMethod || null == setterMethod))) {
                    continue;
                }

                /* store property and it's types */
                final Set<String> propertyTypesFqns = new HashSet<>();

                if (null != getterMethod) {
                    propertyTypesFqns.addAll(getterMethod.getType().filterUnknown().getTypes());
                }
                if (null != setterMethod) {
                    final Parameter[] setterParams = setterMethod.getParameters();
                    if (setterParams.length > 0) {
                        propertyTypesFqns.addAll(setterParams[0].getType().filterUnknown().getTypes());
                    }
                }

                /* drop preceding \ in core types */
                final Set<String> propertyTypes = new HashSet<>();
                for (String type : propertyTypesFqns) {
                    if (type.length() > 0) {
                        if ('\\' == type.charAt(0) && 1 == StringUtils.countMatches(type, "\\")) {
                            type = type.replace("\\", "");
                        }
                        propertyTypes.add(type);
                    }
                }
                propertyTypesFqns.clear();

                final String typesAsString = propertyTypes.isEmpty() ? "mixed"
                        : String.join("|", propertyTypes);
                properties.put(StringUtils.uncapitalize(candidate.replaceAll("^(get|set)", "")), typesAsString);
            }

            /* exclude annotated properties: lazy bulk operation */
            if (properties.size() > 0) {
                final Collection<Field> fields = clazz.getFields();
                for (Field candidate : fields) {
                    /* do not process constants and static fields */
                    if (candidate.isConstant() || candidate.getModifier().isStatic()) {
                        continue;
                    }

                    properties.remove(candidate.getName());
                }
                fields.clear();
            }

            return properties;
        }
    };
}

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

@RequestMapping(value = "/{variantId}/info", method = RequestMethod.GET)
//    @ApiOperation(httpMethod = "GET", value = "Retrieves the information about a variant", response = QueryResponse.class)
public QueryResponse getVariantById(@PathVariable("variantId") String variantId,
        @RequestParam(name = "studies", required = false) List<String> studies,
        @RequestParam("species") String species, HttpServletResponse response)
        throws IllegalOpenCGACredentialsException, UnknownHostException, IOException {
    initializeQueryOptions();//from   w ww  . j av a  2  s  . c  om

    VariantDBAdaptor variantMongoDbAdaptor = DBAdaptorConnector.getVariantDBAdaptor(species);

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

    if (!variantId.contains(":")) { // Query by accession id
        return setQueryResponse(variantMongoDbAdaptor.getVariantById(variantId, queryOptions));
    } else { // Query by chr:pos:ref:alt
        String parts[] = variantId.split(":", -1);
        if (parts.length < 3) {
            response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
            return setQueryResponse(
                    "Invalid position and alleles combination, please use chr:pos:ref or chr:pos:ref:alt");
        }

        Region region = new Region(parts[0], Integer.parseInt(parts[1]), Integer.parseInt(parts[1]));
        queryOptions.put("reference", parts[2]);
        if (parts.length > 3) {
            queryOptions.put("alternate", String.join(":", Arrays.copyOfRange(parts, 3, parts.length)));
        }

        return setQueryResponse(variantMongoDbAdaptor.getAllVariantsByRegion(region, queryOptions));
    }
}