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

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

Introduction

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

Prototype

public static String join(Collection<?> collection, String separator) 

Source Link

Document

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

Usage

From source file:com.wakacommerce.common.util.DependencyLicenseCopy.java

@SuppressWarnings("unchecked")
public void execute() throws BuildException {
    super.execute();
    try {//w  w w .j  a v  a  2  s . com
        for (int i = 0; i < rcs.size(); i++) {
            ResourceCollection rc = (ResourceCollection) rcs.elementAt(i);
            Iterator<Resource> resources = rc.iterator();
            while (resources.hasNext()) {
                Resource r = (Resource) resources.next();
                if (!r.isExists()) {
                    continue;
                }
                if (r instanceof FileResource) {
                    FileResource fr = (FileResource) r;
                    String baseDir = fr.getBaseDir().getAbsolutePath();
                    String file = fr.getFile().getAbsolutePath();
                    file = file.substring(baseDir.length(), file.length());
                    String[] parts = file.split("/");
                    if (parts.length <= 1) {
                        parts = file.split("\\\\");
                    }
                    if (parts.length <= 1) {
                        throw new BuildException(
                                "Unable to recognize the path separator for src file: " + file);
                    }
                    String[] specificParts = new String[parts.length - 1];
                    System.arraycopy(parts, 0, specificParts, 0, specificParts.length);
                    String specificFilePart = StringUtils.join(specificParts, '/') + "/license.txt";
                    File specificFile = new File(licenseDir, specificFilePart);
                    File specificDestinationFile = new File(destDir, specificFilePart);
                    if (specificFile.exists()) {
                        fileUtils.copyFile(specificFile, specificDestinationFile);
                        continue;
                    }

                    String[] generalParts = new String[3];
                    System.arraycopy(parts, 0, generalParts, 0, 3);
                    String generalFilePart = StringUtils.join(generalParts, '/') + "/license.txt";
                    File generalFile = new File(licenseDir, generalFilePart);
                    if (generalFile.exists()) {
                        fileUtils.copyFile(generalFile, specificDestinationFile);
                        continue;
                    }

                    String[] moreGeneralParts = new String[2];
                    System.arraycopy(parts, 0, moreGeneralParts, 0, 2);
                    String moreGeneralFilePart = StringUtils.join(moreGeneralParts, '/') + "/license.txt";
                    File moreGeneralFile = new File(licenseDir, moreGeneralFilePart);
                    if (moreGeneralFile.exists()) {
                        fileUtils.copyFile(moreGeneralFile, specificDestinationFile);
                    }
                }
            }
        }
    } catch (IOException e) {
        throw new BuildException(e);
    }
}

From source file:de.tudarmstadt.ukp.experiments.argumentation.sequence.feature.morpho.POSNgram.java

public static FrequencyDistribution<String> getSentencePosNGrams(JCas jcas, int minN, int maxN,
        boolean useCanonical, Sentence Sentence) {
    FrequencyDistribution<String> result = new FrequencyDistribution<>();

    List<String> posTagString = new ArrayList<>();
    for (POS p : JCasUtil.selectCovered(jcas, POS.class, Sentence)) {
        if (useCanonical) {
            posTagString.add(p.getClass().getSimpleName());
        } else {//  www.j a va2  s  .  c o m
            posTagString.add(p.getPosValue());
        }
    }
    String[] posAsArray = posTagString.toArray(new String[posTagString.size()]);

    for (List<String> nGram : new NGramStringListIterable(posAsArray, minN, maxN)) {
        result.inc(StringUtils.join(nGram, NGramUtils.NGRAM_GLUE));

    }

    return result;
}

From source file:au.org.ala.delta.intkey.directives.StandardIntkeyDirective.java

@Override
public IntkeyDirectiveInvocation doProcess(IntkeyContext context, String data) throws Exception {
    StringBuilder stringRepresentationBuilder = new StringBuilder();
    stringRepresentationBuilder.append(StringUtils.join(getControlWords(), " ").toUpperCase());

    List<String> tokens = ParsingUtils.tokenizeDirectiveCall(data);
    Queue<String> tokenQueue = new ArrayDeque<String>(tokens);

    IntkeyDirectiveInvocation invoc = buildCommandObject();

    if (_intkeyFlagsList != null && tokenQueue.size() > 0) {
        boolean matchingFlags = true;
        while (matchingFlags) {
            boolean tokenMatched = false;
            String token = tokenQueue.peek();

            if (token != null) {
                for (IntkeyDirectiveFlag flag : _intkeyFlagsList) {
                    if (flag.takesStringValue()) {
                        // Flag can have a string value supplied with it in
                        // format "/X=string", where X is the character
                        // symbol. Note that
                        // it is acceptable to supply such a flag without a
                        // following equals sign and string value.
                        if (token.matches("^/[" + Character.toLowerCase(flag.getSymbol())
                                + Character.toUpperCase(flag.getSymbol()) + "](=.+)?")) {

                            // If string value is not supplied, it defaults
                            // to empty string
                            String flagStringValue = "";

                            String[] tokenPieces = token.split("=");

                            // There should only be 0 or 1 equals sign. If
                            // more than none is supplied, no match.
                            if (tokenPieces.length < 3) {
                                if (tokenPieces.length == 2) {
                                    flagStringValue = tokenPieces[1];
                                }//from   w  ww .j a  v a2  s.c  o m

                                BeanUtils.setProperty(invoc, flag.getName(), flagStringValue);
                                tokenQueue.remove();
                                tokenMatched = true;
                                stringRepresentationBuilder.append(" ");
                                stringRepresentationBuilder.append(token);
                                break;
                            }
                        }
                    } else {
                        if (token.equalsIgnoreCase("/" + flag.getSymbol())) {

                            BeanUtils.setProperty(invoc, flag.getName(), true);
                            tokenQueue.remove();
                            tokenMatched = true;
                            stringRepresentationBuilder.append(" ");
                            stringRepresentationBuilder.append(token);
                            break;
                        }
                    }
                }

                matchingFlags = tokenMatched;
            } else {
                matchingFlags = false;
            }
        }
    }

    // The arguments list needs to be generated each time a call to the
    // directive is processed. This is
    // because most arguments need to have provided with an initial value
    // which is used when prompting the user.
    // This initial value needs to be read out of the IntkeyContext at the
    // time of parsing.
    // E.g. the integer argument for the SET TOLERANCE directive will have
    // an initial value equal to the
    // the value of the tolerance setting before the call to the directive.
    List<IntkeyDirectiveArgument<?>> intkeyArgsList = generateArgumentsList(context);

    if (intkeyArgsList != null) {
        for (IntkeyDirectiveArgument<?> arg : intkeyArgsList) {
            Object parsedArgumentValue = arg.parseInput(tokenQueue, context,
                    StringUtils.join(_controlWords, " "), stringRepresentationBuilder);
            if (parsedArgumentValue != null) {
                BeanUtils.setProperty(invoc, arg.getName(), parsedArgumentValue);
            } else {
                // No argument value supplied, user cancelled out of the
                // prompt dialog.
                return null;
            }
        }
    }

    invoc.setStringRepresentation(stringRepresentationBuilder.toString());

    return invoc;
}

From source file:de.tudarmstadt.ukp.experiments.argumentation.sequence.feature.deeplearning.EmbeddingFeatures.java

@Override
protected List<Feature> extract(JCas jCas, Sentence sentence, String sentencePrefix)
        throws TextClassificationException {
    // and load the appropriate distance to centroids
    List<Embeddings> embeddingsList = JCasUtil.selectCovered(Embeddings.class, sentence);

    if (embeddingsList.size() != 1) {
        throw new TextClassificationException(
                new IllegalStateException("Expected 1 embedding annotations for sentence, but "
                        + embeddingsList.size() + " found." + "Sentence: " + sentence.getBegin()
                        + sentence.getEnd() + ", " + StringUtils.join(embeddingsList.iterator(), "\n")));
    }/* w  ww .j  a va  2 s.c  o m*/

    Embeddings embeddings = embeddingsList.iterator().next();
    DenseVector embeddingsVector = new DenseVector(embeddings.getVector().toArray());

    List<Feature> result = new ArrayList<>(embeddingsVector.size());

    for (int i = 0; i < embeddingsVector.size(); i++) {
        double entry = embeddingsVector.get(i);
        result.add(new Feature(sentencePrefix + FEATURE_NAME + i, entry));
    }

    return result;
}

From source file:com.mmj.app.common.util.PushSMSUtils.java

private void sendPushMsg(String msg, String... mobile) {
    if (Argument.isEmptyArray(mobile)) {
        return;/*from w w w.  j ava 2  s  . c  o m*/
    }
    sendPushMsg(msg, StringUtils.join(mobile, ","));
}

From source file:com.adobe.acs.commons.reports.models.StringReportCellCSVExporterTest.java

@Test
public void testMultiple() throws IllegalAccessException {
    log.info("testMultiple");
    StringReportCellCSVExporter exporter = new StringReportCellCSVExporter();
    FieldUtils.writeField(exporter, "property", "multiple", true);
    assertEquals(StringUtils.join(ARRAY_VALUE, ";"), exporter.getValue(mockResource));
    log.info("Test successful!");
}

From source file:com.ritesh.idea.plugin.ui.toolswindow.ReviewTableModel.java

@Override
public Object getValueAt(int rowIndex, int columnIndex) {
    switch (columnIndex) {
    case 0://w  w  w  .  ja  v  a  2 s .c om
        return reviews.get(rowIndex).summary;
    case 1:
        return StringUtils.join(reviews.get(rowIndex).targetPeople, ',');
    case 2:
        return reviews.get(rowIndex).submitter;
    case 3:
        return reviews.get(rowIndex).lastUpdated;
    }
    return null;
}

From source file:edu.northwestern.bioinformatics.studycalendar.domain.delta.DeltaNodeTypeTest.java

public void testThereIsOneDeltaNodeTypePerDeltaClass() throws Exception {
    List<String> errors = new ArrayList<String>();
    for (Class<? extends Delta> deltaClass : domainReflections.getSubTypesOf(Delta.class)) {
        if (Modifier.isAbstract(deltaClass.getModifiers()) || deltaClass.isAnonymousClass())
            continue;
        try {//from w w w  .  j a  va 2s .  c o  m
            DeltaNodeType.valueForDeltaClass(deltaClass);
        } catch (IllegalArgumentException iae) {
            errors.add(iae.getMessage());
        }
    }

    if (!errors.isEmpty()) {
        fail("* " + StringUtils.join(errors.iterator(), "\n* "));
    }
}

From source file:de.tudarmstadt.ukp.dkpro.tc.features.ngram.SkipNgramStringListIterableTest.java

@Test
public void ngramTest_size3() {

    String[] tokens = "A B C D E".split(" ");

    Set<String> ngrams = new HashSet<String>();
    ngrams.add("A B C");
    ngrams.add("B C D");
    ngrams.add("C D E");
    ngrams.add("A B D");
    ngrams.add("A B E");
    ngrams.add("A C D");
    ngrams.add("A D E");
    ngrams.add("B C E");
    ngrams.add("B D E");
    ngrams.add("A C E");

    int i = 0;//  w  w  w  . j  ava  2s.c o  m
    for (List<String> ngram : new SkipNgramStringListIterable(tokens, 3, 3, 2)) {
        String joined = StringUtils.join(ngram, " ");
        assertTrue(joined, ngrams.contains(joined));
        //            System.out.println(ngram);
        i++;
    }
    assertEquals(ngrams.size(), i);
}

From source file:easycare.web.patient.PhysicianConverter.java

public String generatePhysicianName(User currentUser) {
    String titleOfPhysician = null;
    if (currentUser.getTitle() != null) {
        titleOfPhysician = messageSource.getMessage(currentUser.getTitle().generateMessageKeyForTitle());
    }/* w w  w  .  j a  v a  2 s  .  co m*/
    return StringUtils
            .join(new String[] { titleOfPhysician, currentUser.getFirstName(), currentUser.getLastName() }, ' ')
            .trim();

}