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.formkiq.core.service.workflow.WorkflowEditorServiceImplTest.java

/**
 * testEventStepdown03()./*from   w  ww. j  a v a2 s.co  m*/
 * _eventId_stepdown up at max size.
 * @throws IOException IOException
 */
@Test
public void testEventStepdown03() throws IOException {
    // given

    // when
    Workflow wf = expectAction();

    replayAll();
    this.ws.eventIdstepdown(this.flow, this.request, new String[] { "-1" });

    // then
    verifyAll();

    assertEquals("1,2,3", String.join(",", wf.getSteps()));
    assertEquals("1,2,3", String.join(",", wf.getPrintsteps()));
}

From source file:es.fdi.reservas.reserva.business.boundary.ReservaService.java

public void eliminarExdate(ReservaDTO rf) {
     Reserva r = reserva_repository.findOne(rf.getId());
     List<String> s = r.getReglasRecurrencia();
     String[] w = s.get(1).split(":");
     String[] st = w[1].split(";");
     List<String> aux = new ArrayList<>();
     int i = 0;/*from www  .j a v  a 2  s.c  o  m*/
     if (st.length == 1) {
         s.remove(1);
     } else {// si tiene ms de un EXDATE
         while (i < st.length - 1) {
             aux.add(st[i]);
             i++;
         }
         String q = "EXDATE:" + String.join(";", aux);
         r.removeValorRegla(w[0], q);
     }

     reserva_repository.save(r);

 }

From source file:org.wallride.service.ArticleService.java

@CacheEvict(value = WallRideCacheConfiguration.ARTICLE_CACHE, allEntries = true)
public Article saveArticle(ArticleUpdateRequest request, AuthorizedUser authorizedUser) {
    postRepository.lock(request.getId());
    Article article = articleRepository.findOneByIdAndLanguage(request.getId(), request.getLanguage());
    LocalDateTime now = LocalDateTime.now();

    String code = request.getCode();
    if (code == null) {
        try {//from www  .ja v  a  2s.co m
            code = new CodeFormatter().parse(request.getTitle(), LocaleContextHolder.getLocale());
        } catch (ParseException e) {
            throw new ServiceException(e);
        }
    }
    if (!StringUtils.hasText(code)) {
        if (!article.getStatus().equals(Post.Status.DRAFT)) {
            throw new EmptyCodeException();
        }
    }
    if (!article.getStatus().equals(Post.Status.DRAFT)) {
        Post duplicate = postRepository.findOneByCodeAndLanguage(code, request.getLanguage());
        if (duplicate != null && !duplicate.equals(article)) {
            throw new DuplicateCodeException(code);
        }
    }

    if (!article.getStatus().equals(Post.Status.DRAFT)) {
        article.setCode(code);
        article.setDraftedCode(null);
    } else {
        article.setCode(null);
        article.setDraftedCode(code);
    }

    Media cover = null;
    if (request.getCoverId() != null) {
        cover = entityManager.getReference(Media.class, request.getCoverId());
    }
    article.setCover(cover);
    article.setTitle(request.getTitle());
    article.setBody(request.getBody());

    //      User author = null;
    //      if (request.getAuthorId() != null) {
    //         author = entityManager.getReference(User.class, request.getAuthorId());
    //      }
    //      article.setAuthor(author);

    LocalDateTime date = request.getDate();
    if (!Post.Status.DRAFT.equals(article.getStatus())) {
        if (date == null) {
            date = now;
        } else if (date.isAfter(now)) {
            article.setStatus(Post.Status.SCHEDULED);
        } else {
            article.setStatus(Post.Status.PUBLISHED);
        }
    }
    article.setDate(date);
    article.setLanguage(request.getLanguage());

    article.getCategories().clear();
    for (long categoryId : request.getCategoryIds()) {
        article.getCategories().add(entityManager.getReference(Category.class, categoryId));
    }

    article.getTags().clear();
    Set<String> tagNames = StringUtils.commaDelimitedListToSet(request.getTags());
    if (!CollectionUtils.isEmpty(tagNames)) {
        for (String tagName : tagNames) {
            Tag tag = tagRepository.findOneForUpdateByNameAndLanguage(tagName, request.getLanguage());
            if (tag == null) {
                tag = new Tag();
                tag.setName(tagName);
                tag.setLanguage(request.getLanguage());
                article.setCreatedAt(now);
                article.setCreatedBy(authorizedUser.toString());
                article.setUpdatedAt(now);
                article.setUpdatedBy(authorizedUser.toString());
                tag = tagRepository.saveAndFlush(tag);
            }
            article.getTags().add(tag);
        }
    }

    article.getRelatedPosts().clear();
    Set<Post> relatedPosts = new HashSet<>();
    for (long relatedId : request.getRelatedPostIds()) {
        relatedPosts.add(entityManager.getReference(Post.class, relatedId));
    }
    article.setRelatedToPosts(relatedPosts);

    Seo seo = new Seo();
    seo.setTitle(request.getSeoTitle());
    seo.setDescription(request.getSeoDescription());
    seo.setKeywords(request.getSeoKeywords());
    article.setSeo(seo);

    List<Media> medias = new ArrayList<>();
    if (StringUtils.hasText(request.getBody())) {
        //         Blog blog = blogService.getBlogById(Blog.DEFAULT_ID);
        String mediaUrlPrefix = wallRideProperties.getMediaUrlPrefix();
        Pattern mediaUrlPattern = Pattern.compile(String.format("%s([0-9a-zA-Z\\-]+)", mediaUrlPrefix));
        Matcher mediaUrlMatcher = mediaUrlPattern.matcher(request.getBody());
        while (mediaUrlMatcher.find()) {
            Media media = mediaRepository.findOneById(mediaUrlMatcher.group(1));
            medias.add(media);
        }
    }
    article.setMedias(medias);

    article.setUpdatedAt(now);
    article.setUpdatedBy(authorizedUser.toString());

    Map<CustomField, CustomFieldValue> valueMap = new LinkedHashMap<>();
    for (CustomFieldValue value : article.getCustomFieldValues()) {
        valueMap.put(value.getCustomField(), value);
    }

    article.getCustomFieldValues().clear();
    if (!CollectionUtils.isEmpty(request.getCustomFieldValues())) {
        for (CustomFieldValueEditForm valueForm : request.getCustomFieldValues()) {
            CustomField customField = entityManager.getReference(CustomField.class,
                    valueForm.getCustomFieldId());
            CustomFieldValue value = valueMap.get(customField);
            if (value == null) {
                value = new CustomFieldValue();
            }
            value.setCustomField(customField);
            value.setPost(article);
            if (valueForm.getFieldType().equals(CustomField.FieldType.CHECKBOX)) {
                if (!ArrayUtils.isEmpty(valueForm.getTextValues())) {
                    value.setTextValue(String.join(",", valueForm.getTextValues()));
                } else {
                    value.setTextValue(null);
                }
            } else {
                value.setTextValue(valueForm.getTextValue());
            }
            value.setStringValue(valueForm.getStringValue());
            value.setNumberValue(valueForm.getNumberValue());
            value.setDateValue(valueForm.getDateValue());
            value.setDatetimeValue(valueForm.getDatetimeValue());
            if (!value.isEmpty()) {
                article.getCustomFieldValues().add(value);
            }
        }
    }

    return articleRepository.save(article);
}

From source file:com.searchcode.app.jobs.IndexGitRepoJob.java

public String getBlameFilePath(String fileLocationFilename) {
    String[] split = fileLocationFilename.split("/");
    String newString = String.join("/", Arrays.asList(split).subList(1, split.length));
    return newString;
}

From source file:com.viewer.controller.ViewerController.java

@RequestMapping(value = "/GetDocumentPageHtml", method = RequestMethod.POST, headers = {
        "Content-type=application/json" })
@ResponseBody//from w w w.  ja va 2s  .co m
public final Map<String, Object> GetDocumentPageHtml(@RequestBody GetDocumentPageHtmlParameters parameters,
        HttpServletRequest request) throws Exception {

    if (DotNetToJavaStringHelper.isNullOrWhiteSpace(parameters.getPath())) {
        System.out.println("A document path must be specified path");
    }

    String[] cssList = null;
    int pageNumber = parameters.getPageIndex() + 1;

    HtmlOptions htmlOptions = new HtmlOptions();
    htmlOptions.setPageNumber(parameters.getPageIndex() + 1);
    htmlOptions.setCountPagesToConvert(1);
    htmlOptions.setResourcesEmbedded(true);
    htmlOptions.setHtmlResourcePrefix("/GetResourceForHtml?documentPath=" + parameters.getPath()
            + "&pageNumber={page-number}&resourceName=");

    List<PageHtml> htmlPages = GetHtmlPages(parameters.getPath(), htmlOptions);

    String pageHtml = htmlPages.size() > 0 ? htmlPages.get(0).getHtmlContent() : "";
    String[] pageCss = temp_cssList.size() > 0 ? new String[] { String.join(" ", temp_cssList) }
            : new String[] {};

    Map<String, Object> a = new HashMap<String, Object>();
    a.put("pageHtml", pageHtml);
    a.put("pageCss", pageCss);
    return a;
}

From source file:com.formkiq.core.service.workflow.WorkflowEditorServiceImplTest.java

/**
 * testEventStepup01().//w w w . j  a va 2s.  c  om
 * _eventId_stepup. No Change.
 * @throws IOException IOException
 */
@Test
public void testEventStepup01() throws IOException {
    // given
    Workflow wf = expectAction();

    replayAll();
    this.ws.eventIdstepup(this.flow, this.request, new String[] { "0" });

    // then
    verifyAll();

    assertEquals("1,2,3", String.join(",", wf.getSteps()));
    assertEquals("1,2,3", String.join(",", wf.getPrintsteps()));
}

From source file:org.graylog2.indexer.indices.Indices.java

public Map<String, Set<String>> getAllMessageFieldsForIndices(final String[] writeIndexWildcards) {
    final String indices = String.join(",", writeIndexWildcards);
    final State request = new State.Builder().indices(indices).withMetadata().build();

    final JestResult jestResult = JestUtils.execute(jestClient, request,
            () -> "Couldn't read cluster state for indices " + indices);

    final JsonObject indicesJson = getClusterStateIndicesMetadata(jestResult.getJsonObject());
    final ImmutableMap.Builder<String, Set<String>> fields = ImmutableMap.builder();
    for (Map.Entry<String, JsonElement> entry : indicesJson.entrySet()) {
        final String indexName = entry.getKey();
        final Set<String> fieldNames = Optional.ofNullable(asJsonObject(entry.getValue()))
                .map(index -> asJsonObject(index.get("mappings")))
                .map(mappings -> asJsonObject(mappings.get(IndexMapping.TYPE_MESSAGE)))
                .map(messageType -> asJsonObject(messageType.get("properties"))).map(JsonObject::entrySet)
                .map(Set::stream).orElseGet(Stream::empty).map(Map.Entry::getKey).collect(toSet());

        if (!fieldNames.isEmpty()) {
            fields.put(indexName, fieldNames);
        }/* www. j ava  2s.  c  o  m*/
    }

    return fields.build();
}

From source file:gov.pnnl.goss.gridappsd.app.AppManagerImpl.java

@Override
public String startAppForSimultion(String appId, String runtimeOptions, Map simulationContext) {

    String simulationId = simulationContext.get("simulationId").toString();

    appId = appId.trim();//from ww w  . j  a v  a2  s .co m
    String instanceId = appId + "-" + new Date().getTime();
    // get execution path
    AppInfo appInfo = apps.get(appId);
    if (appInfo == null) {
        throw new RuntimeException("App not found: " + appId);
    }

    // are multiple allowed? if not check to see if it is already running,
    // if it is then fail
    if (!appInfo.isMultiple_instances() && listRunningApps(appId).size() > 0) {
        throw new RuntimeException("App is already running and multiple instances are not allowed: " + appId);
    }

    // build options
    // might need a standard method for replacing things like SIMULATION_ID
    // in the input/output options
    /*String optionsString = appInfo.getOptions();
    if (simulationId != null) {
       if (optionsString.contains("SIMULATION_ID")) {
    optionsString = optionsString.replace("SIMULATION_ID",
          simulationId);
       }
       if (runtimeOptions.contains("SIMULATION_ID")) {
    runtimeOptions = runtimeOptions.replace("SIMULATION_ID",
          simulationId);
       }
    }*/

    File appDirectory = new File(getAppConfigDirectory().getAbsolutePath() + File.separator + appId);

    Process process = null;
    // something like
    if (AppType.PYTHON.equals(appInfo.getType())) {
        List<String> commands = new ArrayList<String>();
        commands.add("python");
        commands.add(appInfo.getExecution_path());

        //Check if static args contain any replacement values
        List<String> staticArgsList = appInfo.getOptions();
        for (String staticArg : staticArgsList) {
            if (staticArg != null) {
                if (staticArg.contains("(")) {
                    String[] replaceArgs = StringUtils.substringsBetween(staticArg, "(", ")");
                    for (String args : replaceArgs) {
                        staticArg = staticArg.replace("(" + args + ")", simulationContext.get(args).toString());
                    }
                }
                commands.add(staticArg);
            }
        }

        if (runtimeOptions != null && !runtimeOptions.isEmpty()) {
            String runTimeString = runtimeOptions.replace(" ", "").replace("\n", "");
            commands.add(runTimeString);
        }

        ProcessBuilder processAppBuilder = new ProcessBuilder(commands);
        processAppBuilder.redirectErrorStream(true);
        processAppBuilder.redirectOutput();
        processAppBuilder.directory(appDirectory);
        logManager.log(new LogMessage(this.getClass().getSimpleName(), simulationId, new Date().getTime(),
                "Starting app with command " + String.join(" ", commands), LogLevel.DEBUG,
                ProcessStatus.RUNNING, true), GridAppsDConstants.topic_simulationLog + simulationId);
        try {
            process = processAppBuilder.start();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        // ProcessBuilder fncsBridgeBuilder = new ProcessBuilder("python",
        // getPath(GridAppsDConstants.FNCS_BRIDGE_PATH),
        // simulationConfig.getSimulation_name());
        // fncsBridgeBuilder.redirectErrorStream(true);
        // fncsBridgeBuilder.redirectOutput(new
        // File(defaultLogDir.getAbsolutePath()+File.separator+"fncs_goss_bridge.log"));
        // fncsBridgeProcess = fncsBridgeBuilder.start();
        // // Watch the process
        // watch(fncsBridgeProcess, "FNCS GOSS Bridge");
        // during watch, send stderr/out to logmanager

    } else if (AppType.JAVA.equals(appInfo.getType())) {
        // ProcessBuilder fncsBridgeBuilder = new ProcessBuilder("python",
        // getPath(GridAppsDConstants.FNCS_BRIDGE_PATH),
        // simulationConfig.getSimulation_name());
        // fncsBridgeBuilder.redirectErrorStream(true);
        // fncsBridgeBuilder.redirectOutput(new
        // File(defaultLogDir.getAbsolutePath()+File.separator+"fncs_goss_bridge.log"));
        // fncsBridgeProcess = fncsBridgeBuilder.start();
        // // Watch the process
        // watch(fncsBridgeProcess, "FNCS GOSS Bridge");
        // during watch, send stderr/out to logmanager

    } else if (AppType.WEB.equals(appInfo.getType())) {
        // ProcessBuilder fncsBridgeBuilder = new ProcessBuilder("python",
        // getPath(GridAppsDConstants.FNCS_BRIDGE_PATH),
        // simulationConfig.getSimulation_name());
        // fncsBridgeBuilder.redirectErrorStream(true);
        // fncsBridgeBuilder.redirectOutput(new
        // File(defaultLogDir.getAbsolutePath()+File.separator+"fncs_goss_bridge.log"));
        // fncsBridgeProcess = fncsBridgeBuilder.start();
        // // Watch the process
        // watch(fncsBridgeProcess, "FNCS GOSS Bridge");
        // during watch, send stderr/out to logmanager

    } else {
        throw new RuntimeException("Type not recognized " + appInfo.getType());
    }

    // create appinstance object
    AppInstance appInstance = new AppInstance(instanceId, appInfo, runtimeOptions, simulationId, simulationId,
            process);
    appInstance.setApp_info(appInfo);
    watch(appInstance);
    // add to app instances map
    appInstances.put(instanceId, appInstance);

    return instanceId;
}