List of usage examples for org.apache.commons.lang3 StringUtils repeat
public static String repeat(final char ch, final int repeat)
From source file:com.navercorp.pinpoint.common.buffer.FixedBufferTest.java
@Test public void testPadString() throws Exception { int TOTAL_LENGTH = 20; int TEST_SIZE = 10; int PAD_SIZE = TOTAL_LENGTH - TEST_SIZE; Buffer buffer = new FixedBuffer(32); String test = StringUtils.repeat('a', TEST_SIZE); buffer.putPadString(test, TOTAL_LENGTH); byte[] result = buffer.getBuffer(); String decodedString = new String(result); String trimString = decodedString.trim(); Assert.assertEquals(result.length, TOTAL_LENGTH); Assert.assertEquals("check data", test, trimString); String padString = new String(result, TOTAL_LENGTH - TEST_SIZE, PAD_SIZE, UTF8_CHARSET.name()); byte[] padBytes = new byte[TOTAL_LENGTH - TEST_SIZE]; Assert.assertEquals("check pad", padString, new String(padBytes, UTF8_CHARSET)); }
From source file:challenge302.intermediate.ASCIIHistogramMaker.java
private static void printChart(IntBasedBarChart c, int size) { ArrayList<int[]> data = c.getData(); if (data.size() == size) { //what is the step between elements int step = ((c.getBounds().getMaxX() - c.getBounds().getMinX()) / size); //find the MAX # of chars for each entry in the chart //if chart starts at 0 and goes to 100, the step should be 3 chars int charStep = String.valueOf(c.getMaxX()).length(); char chartChar = '*'; int numColumns = ((size + 1) * (charStep + 1)); // System.out.println("MinY="+c.getMinY()); // System.out.println("MaxY="+c.getMaxY()); // System.out.println("MinX="+c.getMinX()); // System.out.println("MaxX="+c.getMaxX()); // System.out.println("number of X columns="+numColumns); //chreate a 2D char array to store the final barChart //the height is the difference between maxX-minX +1 (for x axis labels) // char[][] graph = new char[c.getMaxX()-c.getMinX()+1] // //and the width of the chart is the charStep // [(charStep+1)*size]; int yAxisCharMax = String.valueOf(c.getMaxY()).length(); //print the x axis guide significant digit // System.out.print(StringUtils.repeat(" ", yAxisCharMax)); // for(int i=1;i<numColumns;i++){ // if(i/10 >0) // System.out.print(i/10); // else // System.out.print(" "); // } // System.out.println("|"); //print the x axis guide // System.out.print(StringUtils.repeat(" ", yAxisCharMax)); // for(int i=1;i<numColumns;i++){ // System.out.print(i%10); // } // System.out.println("|"); ////w w w.j a v a2 s . co m //print if this column is a printing column // System.out.print(StringUtils.repeat(" ", yAxisCharMax)); // for(int i=1;i<numColumns;i++){ // if(i % (charStep+1) == 0 && i >0) // System.out.print("p"); // else // System.out.print(" "); // } // System.out.println("|"); // for (int y = c.getMaxY(); y >= c.getMinY(); y--) { System.out.print(String.format("%0" + yAxisCharMax + "d", y)); int maxX = 0; for (int x = 1; x < numColumns; x++) { //need to find if the current column is a printing column if (x % (charStep + 1) == 0 && x > 0) { //calc the current column in the data, check the value //if the data value is <= current y axis, print chartChar if (y <= data.get(x / (charStep + 1) - 1)[2]) { System.out.print(chartChar); } else {//Y is > data value, so print space System.out.print(" "); } } else {//not a printing column, print space System.out.print(" "); } maxX = x; } //end looping through x Axis //print newline at the end of the X axis on this level of Y axis System.out.println();//end the printed line } //end of loop on data // //print if this column is a printing column // System.out.print(StringUtils.repeat(" ", yAxisCharMax)); // for(int i=1;i<numColumns;i++){ // if(i % (charStep+1) == 0 && i >0) // System.out.print("p"); // else // System.out.print(" "); // } // System.out.println("|"); // //print the X axis System.out.print(StringUtils.repeat(" ", yAxisCharMax)); for (int[] d : c.getData()) { System.out.print(String.format("%0" + String.valueOf(c.getMaxX()).length() + "d", d[0]) + " "); } System.out.println(String.valueOf(c.getMaxX())); } //the data we got returned is the expected size else { System.out.println("ERROR: data size \"" + data.size() + "\" is !=" + size); } }
From source file:com.streamsets.pipeline.stage.origin.kinesis.TestKinesisSource.java
private KinesisConsumerConfigBean getKinesisConsumerConfig() { KinesisConsumerConfigBean conf = new KinesisConsumerConfigBean(); conf.dataFormatConfig = new DataParserFormatConfig(); conf.awsConfig = new AWSConfig(); conf.awsConfig.awsAccessKeyId = "AKIAAAAAAAAAAAAAAAAA"; conf.awsConfig.awsSecretAccessKey = StringUtils.repeat("a", 40); conf.region = Regions.US_WEST_1;//from w ww . j a v a2 s . c om conf.streamName = STREAM_NAME; conf.dataFormat = DataFormat.JSON; conf.dataFormatConfig.jsonContent = JsonMode.MULTIPLE_OBJECTS; conf.dataFormatConfig.charset = "UTF-8"; conf.dataFormatConfig.jsonMaxObjectLen = 1024; conf.applicationName = "test_app"; conf.idleTimeBetweenReads = 1000; conf.initialPositionInStream = InitialPositionInStream.LATEST; conf.maxBatchSize = 1000; conf.maxWaitTime = 1000; return conf; }
From source file:net.ripe.ipresource.Ipv6Address.java
private static String expandMissingColons(String ipAddressString) { int colonCount = isInIpv4EmbeddedIpv6Format(ipAddressString) ? COLON_COUNT_FOR_EMBEDDED_IPV4 : COLON_COUNT_IPV6;/* www . jav a 2 s .c om*/ return ipAddressString.replace("::", StringUtils.repeat(":", colonCount - StringUtils.countMatches(ipAddressString, ":") + 2)); }
From source file:com.azaptree.services.spring.application.SpringApplicationService.java
private static void validate(final String[] args) { if (args.length == 0) { final StringWriter sw = new StringWriter(256); final PrintWriter pw = new PrintWriter(sw); pw.println();/*w w w. ja v a 2 s . co m*/ pw.println(StringUtils.repeat("=", 160)); pw.println( "Usage: java com.azaptree.services.spring.application.SpringApplicationService <config.xml>"); pw.println(); pw.println( " where <config.xml> = XML file location (loaded using Spring ResourceLoader) that must validate against spring-application-service.xsd"); pw.println(StringUtils.repeat("=", 160)); throw new IllegalArgumentException(sw.toString()); } }
From source file:com.seleniumtests.core.aspects.LogAction.java
@Around("execution(public * com.seleniumtests.uipage.PageObject+.* (..)) " + "|| execution(public * com.seleniumtests.uipage.htmlelements.HtmlElement+.* (..))") public Object logDebug(ProceedingJoinPoint joinPoint) throws Throwable { if (LogAction.indent.get(Thread.currentThread()) == null) { LogAction.indent.put(Thread.currentThread(), 0); }//from w w w. j a v a 2 s . co m String currentIndent = StringUtils.repeat(" ", LogAction.indent.get(Thread.currentThread())); logger.debug(String.format("%sEntering %s", currentIndent, joinPoint.getSignature())); Object reply = null; try { LogAction.indent.put(Thread.currentThread(), LogAction.indent.get(Thread.currentThread()) + 2); reply = joinPoint.proceed(joinPoint.getArgs()); } catch (Throwable e) { logger.debug(String.format("%sError in %s: %s - %s", currentIndent, joinPoint.getSignature(), e.getClass().getName(), e.getMessage())); throw e; } finally { LogAction.indent.put(Thread.currentThread(), LogAction.indent.get(Thread.currentThread()) - 2); logger.debug(String.format("%sFinishing %s: %s", currentIndent, joinPoint.getSignature(), buildReplyValues(reply))); } return reply; }
From source file:com.blackducksoftware.integration.hub.detect.workflow.report.DetectConfigurationReporter.java
public void printWarnings(ReportWriter writer, final List<DetectOption> detectOptions) { final List<DetectOption> sortedOptions = sortOptions(detectOptions); final List<DetectOption> allWarnings = sortedOptions.stream().filter(it -> it.getWarnings().size() > 0) .collect(Collectors.toList()); if (allWarnings.size() > 0) { writer.writeLine(""); writer.writeLine(StringUtils.repeat("*", 60)); if (allWarnings.size() == 1) { writer.writeLine("WARNING (" + allWarnings.size() + ")"); } else {//w w w. ja v a 2s . c o m writer.writeLine("WARNINGS (" + allWarnings.size() + ")"); } for (final DetectOption option : allWarnings) { for (final String warning : option.getWarnings()) { writer.writeLine(option.getDetectProperty().getPropertyKey() + ": " + warning); } } writer.writeLine(StringUtils.repeat("*", 60)); writer.writeLine(""); } }
From source file:com.spotify.heroic.grammar.CoreQueryParser.java
@Override public String stringifyQuery(final Query q, Optional<Integer> indent) { final String prefix = indent.map(i -> StringUtils.repeat(' ', i)).orElse(""); final Joiner joiner = indent.map(i -> Joiner.on("\n" + prefix)).orElseGet(() -> Joiner.on(" ")); final List<String> parts = new ArrayList<>(); parts.add(q.getAggregation().map(Aggregation::toDSL).orElse("*")); q.getSource().ifPresent(source -> { parts.add("from"); parts.add(prefix + q.getRange().map(range -> { return source.identifier() + range.toDSL(); }).orElseGet(source::identifier)); });/*from w w w. ja v a2 s .c o m*/ q.getFilter().ifPresent(filter -> { parts.add("where"); parts.add(prefix + filter.toDSL()); }); return joiner.join(parts); }
From source file:com.gmarciani.gmparser.commons.TestDeterministicFunction.java
@Test public void createCompleteAndRemoveAllXY() { System.out.println("#createCompleteAndRemoveAllXY"); GSet<Character> domainX = new GSet<Character>(); domainX.add('a'); domainX.add('b'); domainX.add('c'); GSet<Integer> domainY = new GSet<Integer>(); domainY.add(1);//w ww.j a v a 2s .co m domainY.add(2); domainY.add(3); GSet<String> domainZ = new GSet<String>(); for (Character c : domainX) for (Integer n : domainY) domainZ.add(StringUtils.repeat(c, n)); Function<Character, Integer, String> function = new DeterministicFunction<Character, Integer, String>( domainX, domainY, domainZ); for (Character c : domainX) for (Integer n : domainY) function.add(c, n, StringUtils.repeat(c, n)); function.removeAllForXY('b', 2); System.out.println(function); System.out.println(function.toFormattedFunction()); }
From source file:com.logsniffer.fields.FieldsMapJsonTest.java
@Test public void testDeserializationSpeed() throws IOException { final FieldsMap map = new FieldsMap(); map.put("_severity", new SeverityLevel("DEBUG", 2, SeverityClassification.DEBUG)); map.put("_timestamp", new Date()); // Ca 1k raw message map.put("_raw", StringUtils.repeat("some text with len 23", 50)); for (int i = 0; i < 7; i++) { map.put("somestrfield" + i, StringUtils.repeat("some text " + i, 5)); }//from w w w.j a v a 2s.c o m for (int i = 0; i < 3; i++) { map.put("someintfield" + i, (int) (Math.random() * 1000000)); } for (int i = 0; i < 2; i++) { map.put("somedoublefield" + i, (Math.random() * 1000000)); } final String jsonStr = mapper.writeValueAsString(map); LOGGER.info("Serialized to: {}", jsonStr); final long start = System.currentTimeMillis(); int i = 0; FieldsMap desrerializedMap = null; for (; i < 1000; i++) { desrerializedMap = mapper.readValue(jsonStr, FieldsMap.class); } LOGGER.info("Deserialized fields {} times in {}ms", i, System.currentTimeMillis() - start); Assert.assertEquals(map, desrerializedMap); }