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

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

Introduction

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

Prototype

public static String repeat(final char ch, final int repeat) 

Source Link

Document

<p>Returns padding using the specified delimiter repeated to a given length.</p> <pre> StringUtils.repeat('e', 0) = "" StringUtils.repeat('e', 3) = "eee" StringUtils.repeat('e', -2) = "" </pre> <p>Note: this method doesn't not support padding with <a href="http://www.unicode.org/glossary/#supplementary_character">Unicode Supplementary Characters</a> as they require a pair of char s to be represented.

Usage

From source file:nl.uva.DataHandler.Request.java

private void generateUserQuery() throws IOException {
    String PositiveQuery = "";
    String NegativeQuery = "";
    String PositiveTags = "";
    String NegativeTags = "";
    String PositiveAll = this.duration + " " + this.group + " " + this.pGender + " " + this.season + " "
            + this.tripType;
    for (RatedDoc rd : this.ratedPrefrences) {
        if (rd.rate == -1 || rd.rate == 2)
            continue;
        String qStr = rd.text + " ";
        String tagStr = StringUtils.join(rd.tags, " ") + " ";
        if (rd.rate > 2) {
            if (rd.rate == 4.0)
                rd.setNewRate(2.0);/*from w ww .  jav  a 2  s . c o m*/
            if (rd.rate == 3.0)
                rd.setNewRate(1.0);
            PositiveQuery += StringUtils.repeat(qStr, rd.rate.intValue());
            PositiveTags += StringUtils.repeat(tagStr, rd.rate.intValue());
        } else if (rd.rate < 2) {
            if (rd.rate == 0.0)
                rd.setNewRate(2.0);
            if (rd.rate == 1.0)
                rd.setNewRate(1.0);
            NegativeQuery += StringUtils.repeat(qStr, rd.rate.intValue());
            NegativeTags += StringUtils.repeat(tagStr, rd.rate.intValue());
        }
    }
    this.PositiveQueryString = PositiveQuery;
    this.NegativeQueryString = NegativeQuery;
    this.PositiveTagsString = PositiveTags;
    this.NegativeTagsString = NegativeTags;
    this.PositiveAllString = StringUtils.repeat(PositiveAll, 5) + PositiveQuery + PositiveTags;
}

From source file:no.uio.medisin.bag.biojavagb.GBRead.java

public static void main(String[] args) throws Exception {

    logger.info("\n\n" + StringUtils.repeat("*", 80) + "\n");
    logger.info("                  GenBank parse");
    logger.info("\n\n" + StringUtils.repeat("*", 80) + "\n");
    //        String ax = StringUtils.repeat("*", 80);
    //        String gx = Strings.repeat("*", 3);

    /*/* w  w  w.  j a va2s  .com*/
     * Method 1: With the GenbankProxySequenceReader
     */
    //Try with the GenbankProxySequenceReader
    GenbankProxySequenceReader<AminoAcidCompound> genbankProteinReader = new GenbankProxySequenceReader<AminoAcidCompound>(
            "/tmp", "NP_000257", AminoAcidCompoundSet.getAminoAcidCompoundSet());
    ProteinSequence proteinSequence = new ProteinSequence(genbankProteinReader);
    genbankProteinReader.getHeaderParser().parseHeader(genbankProteinReader.getHeader(), proteinSequence);
    logger.info("Sequence" + "(" + proteinSequence.getAccession() + "," + proteinSequence.getLength() + ")="
            + proteinSequence.getSequenceAsString().substring(0, 10) + "...\n\n");

    GenbankProxySequenceReader<NucleotideCompound> genbankDNAReader = new GenbankProxySequenceReader<NucleotideCompound>(
            "/tmp", "NM_001126", DNACompoundSet.getDNACompoundSet());
    DNASequence dnaSequence = new DNASequence(genbankDNAReader);
    genbankDNAReader.getHeaderParser().parseHeader(genbankDNAReader.getHeader(), dnaSequence);
    logger.info("Sequence" + "(" + dnaSequence.getAccession() + "," + dnaSequence.getLength() + ")="
            + dnaSequence.getSequenceAsString().substring(0, 10) + "...\n\n");
    /*
     * Method 2: With the GenbankReaderHelper
     */
    //Try with the GenbankReaderHelper
    File dnaFile = new File("src/test/resources/NM_000266.gb");
    File protFile = new File("src/test/resources/BondFeature.gb");

    logger.info("\n\nREAD dna file " + dnaFile + "\n\n");
    LinkedHashMap<String, DNASequence> dnaSequences = GenbankReaderHelper.readGenbankDNASequence(dnaFile);
    for (DNASequence sequence : dnaSequences.values()) {
        //logger.info( sequence.getSequenceAsString() );

        String notes = sequence.getOriginalHeader();
        sequence.getDescription();
        List fr = sequence.getFeaturesByType("source");

        //                List<FeatureInterface<AbstractSequence<NucleotideCompound>, NucleotideCompound>> fr = sequence.getFeaturesByType("SOURCE");
        //                for (FeatureInterface fi : fr) {
        //                    logger.info("DESCRIPTION\t" + fi.getDescription());                    
        //                }                
        logger.info(sequence.getDatabaseReferences());
        logger.info(sequence.getDescription());

        List<FeatureInterface<AbstractSequence<NucleotideCompound>, NucleotideCompound>> fl = sequence
                .getFeatures();
        for (FeatureInterface fi : fl) {
            logger.info("DESCRIPTION\t" + fi.getDescription());
            logger.info("CHILDREN\t" + fi.getChildrenFeatures());
            logger.info("LOCATIONS\t" + fi.getLocations());
            logger.info("PARENT\t" + fi.getParentFeature());

            logger.info("QUALIFIERS");
            HashMap<String, Qualifier> quals = fi.getQualifiers();
            for (Map.Entry<String, Qualifier> entry : quals.entrySet()) {
                logger.info("--\t" + entry.getKey() + "\t|\t" + entry.getValue().getName() + "  /  "
                        + entry.getValue().getValue() + "\\" + entry.getValue().toString());
            }

            logger.info("\n");
            logger.info("SHORT\t" + fi.getShortDescription());
            logger.info("SOURCE\t" + fi.getSource());
            logger.info("TYPE\t" + fi.getType());
            logger.info("HASHCODE\t" + fi.hashCode());
            logger.info("-");
        }
        //                Annotation seqAn = seq.getAnnotation();
        //                for (Iterator i = seqAn.keys().iterator(); i.hasNext(); ) {
        //                    Object key = i.next();
        //                    Object value = seqAn.getProperty(key);
        //                    logger.info(key.toString() + ": " + value.toString());
        //                }                
    }

    LinkedHashMap<String, ProteinSequence> protSequences = GenbankReaderHelper
            .readGenbankProteinSequence(protFile);
    for (ProteinSequence sequence : protSequences.values()) {
        logger.info(sequence.getSequenceAsString());
    }
    /*
     * Method 3: With the GenbankReader Object 
     */
    //Try reading with the GanbankReader
    FileInputStream is = new FileInputStream(dnaFile);
    GenbankReader<DNASequence, NucleotideCompound> dnaReader = new GenbankReader<DNASequence, NucleotideCompound>(
            is, new GenericGenbankHeaderParser<DNASequence, NucleotideCompound>(),
            new DNASequenceCreator(DNACompoundSet.getDNACompoundSet()));
    dnaSequences = dnaReader.process();
    is.close();
    logger.info(dnaSequences);

    is = new FileInputStream(protFile);
    GenbankReader<ProteinSequence, AminoAcidCompound> protReader = new GenbankReader<ProteinSequence, AminoAcidCompound>(
            is, new GenericGenbankHeaderParser<ProteinSequence, AminoAcidCompound>(),
            new ProteinSequenceCreator(AminoAcidCompoundSet.getAminoAcidCompoundSet()));
    protSequences = protReader.process();
    is.close();
    logger.info(protSequences);
}

From source file:onejarmulticonfig.Main.java

public static void main(String[] args) {
    System.out.println("Hello, onejar" + StringUtils.repeat("!", 4));
    System.out.println("Temp directory path: " + FileUtils.getTempDirectoryPath());
}

From source file:onejarsimpletest.Main.java

public static void main(String[] args) {
    System.out.println("Hello, onejar" + StringUtils.repeat("!", 4));
}

From source file:org.apache.cassandra.db.ScrubTest.java

private void overrideWithGarbage(SSTableReader sstable, long startPosition, long endPosition)
        throws IOException {
    RandomAccessFile file = new RandomAccessFile(sstable.getFilename(), "rw");
    file.seek(startPosition);/*from  ww  w  .j  av a  2  s. c  o  m*/
    file.writeBytes(StringUtils.repeat('z', (int) (endPosition - startPosition)));
    file.close();
}

From source file:org.apache.cassandra.db.VerifyTest.java

@Test
public void testVerifyCorruptRowCorrectDigest() throws IOException, WriteTimeoutException {
    CompactionManager.instance.disableAutoCompaction();
    Keyspace keyspace = Keyspace.open(KEYSPACE);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CORRUPT_CF2);

    fillCF(cfs, KEYSPACE, CORRUPT_CF2, 2);

    List<Row> rows = cfs.getRangeSlice(Util.range("", ""), null, new IdentityQueryFilter(), 1000);

    SSTableReader sstable = cfs.getSSTables().iterator().next();

    // overwrite one row with garbage
    long row0Start = sstable.getPosition(RowPosition.ForKey.get(ByteBufferUtil.bytes("0"), sstable.partitioner),
            SSTableReader.Operator.EQ).position;
    long row1Start = sstable.getPosition(RowPosition.ForKey.get(ByteBufferUtil.bytes("1"), sstable.partitioner),
            SSTableReader.Operator.EQ).position;
    long startPosition = row0Start < row1Start ? row0Start : row1Start;
    long endPosition = row0Start < row1Start ? row1Start : row0Start;

    RandomAccessFile file = new RandomAccessFile(sstable.getFilename(), "rw");
    file.seek(startPosition);/* www .j  ava  2s  . co  m*/
    file.writeBytes(StringUtils.repeat('z', (int) 2));
    file.close();

    // Update the Digest to have the right Checksum
    writeChecksum(simpleFullChecksum(sstable.getFilename()), sstable.descriptor.filenameFor(Component.DIGEST));

    Verifier verifier = new Verifier(cfs, sstable, false);

    // First a simple verify checking digest, which should succeed
    try {
        verifier.verify(false);
    } catch (CorruptSSTableException err) {
        fail("Simple verify should have succeeded as digest matched");
    }

    // Now try extended verify
    try {
        verifier.verify(true);

    } catch (CorruptSSTableException err) {
        return;
    }
    fail("Expected a CorruptSSTableException to be thrown");

}

From source file:org.apache.cassandra.service.ClientWarningsTest.java

private String createBatchStatement(int minSize) {
    return String.format("BEGIN UNLOGGED BATCH INSERT INTO %s.%s (pk, v) VALUES (1, '%s') APPLY BATCH;",
            KEYSPACE, currentTable(), StringUtils.repeat('1', minSize));
}

From source file:org.apache.cassandra.service.ClientWarningsTest.java

private String createBatchStatement2(int minSize) {
    return String.format(
            "BEGIN UNLOGGED BATCH INSERT INTO %s.%s (pk, v) VALUES (1, '%s'); INSERT INTO %s.%s (pk, v) VALUES (2, '%s'); APPLY BATCH;",
            KEYSPACE, currentTable(), StringUtils.repeat('1', minSize), KEYSPACE, currentTable(),
            StringUtils.repeat('1', minSize));
}

From source file:org.apache.drill.exec.util.BatchPrinter.java

public static void printBatch(VectorAccessible batch) {
    List<String> columns = Lists.newArrayList();
    List<ValueVector> vectors = Lists.newArrayList();
    for (VectorWrapper vw : batch) {
        columns.add(vw.getValueVector().getField().getAsSchemaPath().toExpr());
        vectors.add(vw.getValueVector());
    }//from w  w w  .  ja  v a 2s  .  c om
    int width = columns.size();
    int rows = vectors.get(0).getMetadata().getValueCount();
    for (int row = 0; row < rows; row++) {
        if (row % 50 == 0) {
            System.out.println(StringUtils.repeat("-", width * 17 + 1));
            for (String column : columns) {
                System.out.printf("| %-15s", width <= 15 ? column : column.substring(0, 14));
            }
            System.out.printf("|\n");
            System.out.println(StringUtils.repeat("-", width * 17 + 1));
        }
        for (ValueVector vv : vectors) {
            Object o = vv.getAccessor().getObject(row);
            if (o instanceof byte[]) {
                String value = new String((byte[]) o);
                System.out.printf("| %-15s", value.length() <= 15 ? value : value.substring(0, 14));
            } else {
                String value = o.toString();
                System.out.printf("| %-15s", value.length() <= 15 ? value : value.substring(0, 14));
            }
        }
        System.out.printf("|\n");
    }
}

From source file:org.apache.drill.exec.util.VectorUtil.java

public static void showVectorAccessibleContent(VectorAccessible va, int[] columnWidths) {
    int width = 0;
    int columnIndex = 0;
    List<String> columns = Lists.newArrayList();
    List<String> formats = Lists.newArrayList();
    for (VectorWrapper<?> vw : va) {
        int columnWidth = getColumnWidth(columnWidths, columnIndex);
        width += columnWidth + 2;/*ww w.j  a  va 2 s .c  om*/
        formats.add("| %-" + columnWidth + "s");
        MaterializedField field = vw.getValueVector().getField();
        columns.add(field.getPath().getAsUnescapedPath() + "<" + field.getType().getMinorType() + "("
                + field.getType().getMode() + ")" + ">");
        columnIndex++;
    }

    int rows = va.getRecordCount();
    for (int row = 0; row < rows; row++) {
        // header, every 50 rows.
        if (row % 50 == 0) {
            System.out.println(StringUtils.repeat("-", width + 1));
            columnIndex = 0;
            for (String column : columns) {
                int columnWidth = getColumnWidth(columnWidths, columnIndex);
                System.out.printf(formats.get(columnIndex),
                        column.length() <= columnWidth ? column : column.substring(0, columnWidth - 1));
                columnIndex++;
            }
            System.out.printf("|\n");
            System.out.println(StringUtils.repeat("-", width + 1));
        }
        // column values
        columnIndex = 0;
        for (VectorWrapper<?> vw : va) {
            int columnWidth = getColumnWidth(columnWidths, columnIndex);
            Object o = vw.getValueVector().getAccessor().getObject(row);
            String cellString;
            if (o instanceof byte[]) {
                cellString = DrillStringUtils.toBinaryString((byte[]) o);
            } else {
                cellString = DrillStringUtils.escapeNewLines(String.valueOf(o));
            }
            System.out.printf(formats.get(columnIndex),
                    cellString.length() <= columnWidth ? cellString : cellString.substring(0, columnWidth - 1));
            columnIndex++;
        }
        System.out.printf("|\n");
    }
    if (rows > 0) {
        System.out.println(StringUtils.repeat("-", width + 1));
    }

    for (VectorWrapper<?> vw : va) {
        vw.clear();
    }
}