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:org.mabb.fontverter.woff.WoffOutputStream.java

public void writeUIntBase128(int num) throws IOException {
    List<Byte> bytes = new ArrayList<Byte>();
    String binary = Integer.toBinaryString(num);

    while (!binary.isEmpty()) {
        if (binary.length() < 7)
            binary = StringUtils.repeat("0", 7 - (binary.length() % 7)) + binary;

        String byteBinary = binary.substring(binary.length() - 7, binary.length());

        // last (or only) byte signficant bit must be 0 all others sig bit must be 1
        int sigbit = bytes.size() == 0 ? 0 : 128;
        byte byteOn = (byte) (sigbit + Integer.parseInt(byteBinary, 2));
        bytes.add(0, byteOn);/*from  www . j av a  2  s  .com*/

        binary = binary.substring(0, binary.length() - 7);
    }

    for (byte byteOn : bytes)
        write(byteOn);
}

From source file:org.mabb.fontverter.woff.WoffOutputStream.java

public void writeFlagByte(int flag, int transform) throws IOException {
    String binary = Integer.toBinaryString(flag);
    String transBinary = Integer.toBinaryString(transform);
    if (transBinary.length() < 2)
        transBinary = StringUtils.repeat("0", 2 - transBinary.length()) + transBinary;
    if (binary.length() < 6)
        binary = StringUtils.repeat("0", 6 - binary.length()) + binary;

    binary = transBinary + binary;/*from  ww  w.jav  a  2 s.  c  o  m*/
    byte byteOn = (Byte.parseByte(binary, 2));
    write(byteOn);
}

From source file:org.meresco.triplestore.TransactionLogTest.java

@Test
public void testBigCurrentFileInTransactionLog() throws Exception {
    String filedata = StringUtils.repeat(StringUtils.repeat("ignored", 1024), 100);
    String tsItem = "<transaction_item>\n" + "    <action>add</action>\n"
            + "    <identifier>test1.rdf</identifier>\n" + "    <filedata>" + filedata + "</filedata>\n"
            + "</transaction_item>\n";
    FileWriter fw = new FileWriter(transactionLog.transactionLogFilePath);
    for (int i = 0; i < 100; i++) {
        fw.write(tsItem);/*  w w w .j a va 2  s  .c  o  m*/
    }
    fw.close();
    class MyTSMock extends TSMock {
        public void add(String identifier, String data) {
            actions.add("add:" + identifier);
        }
    }
    tsMock = new MyTSMock();
    transactionLog = new TransactionLog(tsMock, tempdir);
    transactionLog.init();
    assertEquals(StringUtils.repeat(".", 50) + " 50Mb", stdout.toString(), stdout.toString());
}

From source file:org.mskcc.shenkers.control.alignment.AlignmentWeaver.java

public static void printAli(List<List<Pos>> ali) {
    for (List<Pos> l : ali) {
        int pO = 0;
        for (Pos p : l) {
            System.out.print(StringUtils.repeat("\t", p.order - pO) + "" + p.loc);
            pO = p.order;//from   ww  w.j  a v a  2s .c o  m
        }
        System.out.println();
    }
}

From source file:org.mskcc.shenkers.control.alignment.AlignmentWeaver.java

public void printAli2(List<Genome> gOrder) {
    Integer max = order.values().stream().flatMap(o -> o.stream()).max((i1, i2) -> i1 - i2).get();
    logger.info("MAX {}", max);
    for (Genome g : gOrder) {
        //            int pO = 0;
        StringBuilder b = new StringBuilder(StringUtils.repeat("-", max + 1));
        List<Integer> l = order.get(g);
        //            StringBuilder b = new StringBuilder();
        for (Integer porder : l) {
            //                logger.info("PORDER {}",porder);
            //                b.append(StringUtils.repeat("\t", porder - pO) + "X");
            b.setCharAt(porder, 'X');
            //                pO = porder;
        }/*from w  w w .j  a  va  2  s  .  c o m*/
        logger.info(b.toString());
    }
}

From source file:org.mskcc.shenkers.control.alignment.chain.ChainAlignmentSource.java

@Override
public List<LocalAlignment> getAlignment(GenomeSpan span1, GenomeSpan span2) {
    Interval interval = new Interval(span1.getChr(), span1.getStart(), span1.getEnd());

    List<LocalAlignment> chainIntersections = instance.getChainIntersections(interval);
    for (LocalAlignment blocks : chainIntersections) {
        StringBuilder gapped1 = new StringBuilder();
        StringBuilder gapped2 = new StringBuilder();

        // TODO need to make sure there are not zero blocks
        gapped1.append(StringUtils.repeat("X", blocks.getBlockSize(0)));
        gapped2.append(StringUtils.repeat("X", blocks.getBlockSize(0)));
        int last1 = blocks.getFromBlock(0).getValue();
        int last2 = blocks.getToNegativeStrand() ? blocks.getToBlock(0).getKey()
                : blocks.getToBlock(0).getValue();
        for (int i = 1; i < blocks.getNBlocks(); i++) {
            System.out.println(String.format("%s:%d-%d", blocks.getFromSequenceName(),
                    blocks.getFromBlock(i).getKey(), blocks.getFromBlock(i).getValue()));
            System.out.println(String.format("%s:%d-%d", blocks.getToSequenceName(),
                    blocks.getToBlock(i).getKey(), blocks.getToBlock(i).getValue()));
            System.err.println("");

            gapped1.append(StringUtils.repeat("X", blocks.getFromBlock(i).getKey() - last1 - 1));
            gapped2.append(StringUtils.repeat("-", blocks.getFromBlock(i).getKey() - last1 - 1));
            int gap2 = blocks.getToNegativeStrand() ? last2 - blocks.getToBlock(i).getValue() - 1
                    : blocks.getToBlock(i).getKey() - last2 - 1;
            gapped2.append(StringUtils.repeat("X", gap2));
            gapped1.append(StringUtils.repeat("-", gap2));

            gapped1.append(StringUtils.repeat("X", blocks.getBlockSize(i)));
            gapped2.append(StringUtils.repeat("X", blocks.getBlockSize(i)));

            last1 = blocks.getFromBlock(i).getValue();
            last2 = blocks.getToNegativeStrand() ? blocks.getToBlock(i).getKey()
                    : blocks.getToBlock(i).getValue();

        }// w ww  . j  a va  2  s .co m
        System.out.println(gapped1.toString());
        System.out.println(gapped2.toString());
        System.out.println(gapped1.toString().replaceAll("-", "").length());
        System.out.println(gapped2.toString().replaceAll("-", "").length());
        System.out.println(74869 - 74548 + 1);
        System.out.println(42438 - 42085 + 1);
    }
    return chainIntersections;
}

From source file:org.mskcc.shenkers.control.alignment.ChainParserNGTest.java

/**
 * Test of getChainIntersections method, of class ChainParser.
 *///from   w ww.jav  a 2s. com
@Test
public void testGetChainIntersections() throws FileNotFoundException {
    //        File f = new File("/home/sol/Downloads/dm3.droYak2.chain");
    File f = new File("/home/sol/Downloads/dm3.droYak2.chain");

    //        Scanner scan = new Scanner(f);
    //        int i=0;
    //        int j=0;
    //        PrintStream out = new PrintStream(new File("C:/Users/sol/Downloads/dm3.droYak2.chain"));
    //        while(scan.hasNext()){
    //            String line = scan.nextLine();
    //            System.out.println(i+"\t"+line);
    //            i++;
    //            
    //            if(i==185681)
    //                break;
    //            
    //            out.println(line);
    //            
    //        }
    //        out.close();
    //        System.exit(0);
    //        chrX:411720-413080
    //        chr3R 27905053 28832112
    //        chain 747933599 chr3R 27905053 + 46 27900188 chr3R 28832112 + 366441 28829329 2
    //        chr3R:9536-9791
    //        90   chain 970691389 chr3L 24543557 + 43412 23775837 chr3L 24197627 + 750 24183090 1
    //chr3L:74548-74869
    Interval interval = new Interval("chr3L", 74548, 74869);

    System.out.println("loading chain file");
    ChainParser instance = new ChainParser(f);
    System.out.println("calculating intersections");
    List<LocalAlignment> chainIntersections = instance.getChainIntersections(interval);
    for (LocalAlignment blocks : chainIntersections) {
        //            chr3L:74548-74869
        //chr3L:42085-42438
        blocks = trim(blocks, new GenomeSpan("chr3L", 74548, 74869, false),
                new GenomeSpan("chr3L", 42088, 42438, false));
        StringBuilder gapped1 = new StringBuilder();
        StringBuilder gapped2 = new StringBuilder();

        gapped1.append(StringUtils.repeat("X", blocks.blockSizes.get(0)));
        gapped2.append(StringUtils.repeat("X", blocks.blockSizes.get(0)));
        int last1 = blocks.fromBlocks.get(0).getValue();
        int last2 = blocks.toNegativeStrand ? blocks.toBlocks.get(0).getKey()
                : blocks.toBlocks.get(0).getValue();
        for (int i = 1; i < blocks.fromBlocks.size(); i++) {
            System.out.println(String.format("%s:%d-%d %d", blocks.fromSequenceName,
                    blocks.fromBlocks.get(i).getKey(), blocks.fromBlocks.get(i).getValue(),
                    blocks.fromBlocks.get(i).getValue() - blocks.fromBlocks.get(i).getKey()));
            System.out.println(String.format("%s:%d-%d %d", blocks.toSequenceName,
                    blocks.toBlocks.get(i).getKey(), blocks.toBlocks.get(i).getValue(),
                    blocks.toBlocks.get(i).getValue() - blocks.toBlocks.get(i).getKey()));
            System.err.println("");

            gapped1.append(StringUtils.repeat("X", blocks.fromBlocks.get(i).getKey() - last1 - 1));
            gapped2.append(StringUtils.repeat("-", blocks.fromBlocks.get(i).getKey() - last1 - 1));
            int gap2 = blocks.toNegativeStrand ? last2 - blocks.toBlocks.get(i).getValue() - 1
                    : blocks.toBlocks.get(i).getKey() - last2 - 1;
            gapped2.append(StringUtils.repeat("X", gap2));
            gapped1.append(StringUtils.repeat("-", gap2));

            gapped1.append(StringUtils.repeat("X", blocks.blockSizes.get(i)));
            gapped2.append(StringUtils.repeat("X", blocks.blockSizes.get(i)));

            last1 = blocks.fromBlocks.get(i).getValue();
            last2 = blocks.toNegativeStrand ? blocks.toBlocks.get(i).getKey()
                    : blocks.toBlocks.get(i).getValue();

        }
        System.out.println(gapped1.toString());
        System.out.println(gapped2.toString());
        System.out.println(gapped1.toString().replaceAll("-", "").length());
        System.out.println(gapped2.toString().replaceAll("-", "").length());
        System.out.println(74869 - 74548 + 1);
        System.out.println(42438 - 42085 + 1);
    }

    //        chr3L:74548-74869
    //chr3L:42085-42438
    System.out.println(chainIntersections.size());
    //        List expResult = null;
    //        List result = instance.getChainIntersections(interval);
    //        assertEquals(result, expResult);
    //        // TODO review the generated test code and remove the default call to fail.
    //        fail("The test case is a prototype.");
    ;
}

From source file:org.mskcc.shenkers.view.IntervalViewNGTest.java

public void testStackIntervalView() throws InterruptedException {
    System.out.println("testStackIntervalView");
    int[][] d = new int[][] { { 2, 6 }, { 7, 10 }, { 1, 3 }, { 4, 6 }, { 8, 10 }, { 1, 2 }, { 3, 7 }, { 9, 10 },
            { 1, 2 }, { 3, 5 }, { 6, 7 }, { 8, 10 }, { 2, 5 }, { 8, 10 } };
    List<int[]> asList = Arrays.asList(d);
    Collections.sort(asList, new Comparator<int[]>() {

        @Override//from w  ww . j  a v a 2  s  .c  o m
        public int compare(int[] o1, int[] o2) {
            return o1[0] - o2[0];
        }
    });
    List<TreeRangeSet<Integer>> rows = new ArrayList<>();
    rows.add(TreeRangeSet.create());
    for (int[] r : d) {
        Range<Integer> R = Range.closed(r[0], r[1]);
        int i = 0;
        added: {
            while (i < rows.size()) {
                TreeRangeSet<Integer> set = rows.get(i);
                RangeSet<Integer> intersection = set.subRangeSet(Range.closed(r[0] - 1, r[1] + 1));
                if (intersection.isEmpty()) {
                    set.add(R);
                    break added;
                }
                i++;
            }
            //                Stri i = ;
            TreeRangeSet<Integer> row = TreeRangeSet.create();
            row.add(R);
            rows.add(row);
        }
    }
    TilePane p = new TilePane();
    p.setSnapToPixel(false);
    for (int i = 0; i < rows.size(); i++) {
        p.getChildren().add(get(rows.get(i), 0, 11));
        System.out.println(rows.get(i).toString());
        StringBuilder sb = new StringBuilder(11);
        sb.append(StringUtils.repeat(".", 11));
        for (int j = 0; j < 11; j++) {
            if (rows.get(i).contains(j)) {
                sb.setCharAt(j, 'X');
            }
        }
        System.out.println(sb.toString());
    }
    //        p.prefWidth(100);
    //        p.prefHeight(100);
    ScrollPane sp = new ScrollPane(p);
    ScrollBar sb = new ScrollBar();
    sb.maxProperty().bind(sp.vmaxProperty());
    sb.minProperty().bind(sp.vminProperty());
    sb.visibleAmountProperty().bind(sp.heightProperty().divide(p.prefHeightProperty()));
    sb.setOrientation(Orientation.VERTICAL);
    sp.vvalueProperty().bindBidirectional(sb.valueProperty());
    HiddenSidesPane hsp = new HiddenSidesPane();
    hsp.setContent(sp);
    hsp.setRight(sb);
    sp.setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
    sp.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
    p.setOrientation(Orientation.VERTICAL);
    p.prefTileHeightProperty().bind(new SimpleDoubleProperty(40));
    //        p.minHeightProperty().bind(new SimpleDoubleProperty(20).multiply(Bindings.size(p.getChildren())));
    p.prefTileWidthProperty().bind(sp.widthProperty());
    p.prefHeightProperty()
            .bind(new SimpleDoubleProperty(50).multiply(Bindings.size(p.getChildren())).subtract(10));
    p.prefWidthProperty().bind(sp.widthProperty());
    sp.setPadding(Insets.EMPTY);
    p.setVgap(10);

    CountDownLatch l = new CountDownLatch(1);
    Platform.runLater(() -> {

        Stage stage = new Stage();
        stage.setOnHidden(e -> {
            l.countDown();
        });
        Scene scene = new Scene(hsp, 300, 300, Color.GRAY);
        stage.setTitle("JavaFX Scene Graph Demo");
        stage.setScene(scene);
        stage.show();

    });
    l.await();
}

From source file:org.nuxeo.ecm.platform.userworkspace.core.tests.TestUserWorkspace.java

String alongname(String name) {
    return StringUtils.repeat("a", pathSegments.getMaxSize()).concat(name);
}

From source file:org.ohdsi.webapi.service.CohortDefinitionService.java

private String getInclusionRuleTreemapData(int id, int inclusionRuleCount, Source source) {
    String resultsTableQualifier = source.getTableQualifier(SourceDaimon.DaimonType.Results);
    String smulationResultsQuery = String.format(
            "select inclusion_rule_mask, person_count from %s.cohort_inclusion_result where cohort_definition_id = %d",
            resultsTableQualifier, id);/*from   w w  w.  jav a 2 s  .com*/
    String translatedSql = SqlTranslate.translateSql(smulationResultsQuery, "sql server",
            source.getSourceDialect(), SessionUtils.sessionId(), resultsTableQualifier);

    // [0] is the inclusion rule bitmask, [1] is the count of the match
    List<Long[]> items = this.getSourceJdbcTemplate(source).query(translatedSql, inclusionRuleResultItemMapper);
    Map<Integer, List<Long[]>> groups = new HashMap<>();
    for (Long[] item : items) {
        int bitsSet = countSetBits(item[0]);
        if (!groups.containsKey(bitsSet)) {
            groups.put(bitsSet, new ArrayList<Long[]>());
        }
        groups.get(bitsSet).add(item);
    }

    StringBuilder treemapData = new StringBuilder("{\"name\" : \"Everyone\", \"children\" : [");

    List<Integer> groupKeys = new ArrayList<>(groups.keySet());
    Collections.sort(groupKeys);
    Collections.reverse(groupKeys);

    int groupCount = 0;
    // create a nested treemap data where more matches (more bits set in string) appear higher in the hierarchy)
    for (Integer groupKey : groupKeys) {
        if (groupCount > 0) {
            treemapData.append(",");
        }

        treemapData.append(String.format("{\"name\" : \"Group %d\", \"children\" : [", groupKey));

        int groupItemCount = 0;
        for (Long[] groupItem : groups.get(groupKey)) {
            if (groupItemCount > 0) {
                treemapData.append(",");
            }

            //sb_treemap.Append("{\"name\": \"" + cohort_identifer + "\", \"size\": " + cohorts[cohort_identifer].ToString() + "}");
            treemapData.append(String.format("{\"name\": \"%s\", \"size\": %d}",
                    formatBitMask(groupItem[0], inclusionRuleCount), groupItem[1]));
            groupItemCount++;
        }
        groupCount++;
    }

    treemapData.append(StringUtils.repeat("]}", groupCount + 1));

    return treemapData.toString();
}