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.opensymphony.xwork2.conversion.impl.NumberConverterTest.java
public void testStringToFloatConversionPL() throws Exception { // given/*www .ja va 2 s . co m*/ NumberConverter converter = new NumberConverter(); Map<String, Object> context = new HashMap<>(); context.put(ActionContext.LOCALE, new Locale("pl", "PL")); // when has max fraction digits Object value = converter.convertValue(context, null, null, null, "0," + StringUtils.repeat('0', 44) + "1401298464324817", Float.class); // then does not lose fraction digits assertEquals(Float.MIN_VALUE, value); // when has max integer digits value = converter.convertValue(context, null, null, null, "34028234663852886" + StringUtils.repeat('0', 22) + ",0", Float.class); // then does not lose integer digits assertEquals(Float.MAX_VALUE, value); }
From source file:com.baidu.oped.apm.common.buffer.FixedBufferTest.java
@Test public void readPadStringAndRightTrim() { String testString = StringUtils.repeat('a', 10); Buffer writeBuffer = new FixedBuffer(32); writeBuffer.putPadString(testString, 20); writeBuffer.put(255);// ww w . ja va 2 s . co m Buffer readBuffer = new FixedBuffer(writeBuffer.getBuffer()); String readPadString = readBuffer.readPadStringAndRightTrim(20); Assert.assertEquals(testString, readPadString); int readInt = readBuffer.readInt(); Assert.assertEquals(255, readInt); }
From source file:at.ac.tuwien.big.moea.print.SolutionWriter.java
protected SolutionWriter<S> increaseIndent(final int spaces) { return setIndent(StringUtils.repeat(' ', spaces + getIndent().length())); }
From source file:com.streamsets.pipeline.stage.destination.kinesis.TestKinesisTarget.java
private KinesisProducerConfigBean getKinesisTargetConfig() { KinesisProducerConfigBean conf = new KinesisProducerConfigBean(); conf.dataFormatConfig = new DataGeneratorFormatConfig(); conf.awsConfig = new AWSConfig(); conf.awsConfig.awsAccessKeyId = "AKIAAAAAAAAAAAAAAAAA"; conf.awsConfig.awsSecretAccessKey = StringUtils.repeat("a", 40); conf.region = Regions.US_WEST_1;//from ww w .j a v a2s .c o m conf.streamName = STREAM_NAME; conf.dataFormat = DataFormat.JSON; conf.dataFormatConfig.jsonMode = JsonMode.MULTIPLE_OBJECTS; conf.dataFormatConfig.charset = "UTF-8"; conf.partitionStrategy = PartitionStrategy.RANDOM; conf.preserveOrdering = false; conf.producerConfigs = new HashMap<>(); return conf; }
From source file:ch.digitalfondue.jfiveparse.TreeConstructionTest.java
private static void renderNode(Node node, int depth, StringBuilder sb) { int spaces = depth == 0 ? 1 : depth * 2 + 1; sb.append("|").append(StringUtils.repeat(' ', spaces)); int depthsForTemplatesChilds = 0; if (node instanceof Element) { Element elem = (Element) node; sb.append("<"); if (Node.NAMESPACE_MATHML.equals(elem.getNamespaceURI())) { sb.append("math "); } else if (Node.NAMESPACE_SVG.equals(elem.getNamespaceURI())) { sb.append("svg "); }//from www. j ava 2 s . com sb.append(elem.getNodeName()).append(">"); Set<String> attributesName = new TreeSet<>(elem.getAttributes().keySet()); if (!attributesName.isEmpty()) { sb.append("\n"); for (String k : attributesName) { sb.append("|").append(StringUtils.repeat(' ', spaces + 2)); AttributeNode attribute = elem.getAttributes().get(k); if (attribute.getNamespace() != null) { if (Node.NAMESPACE_XLINK.equals(attribute.getNamespace())) { sb.append("xlink "); } else if (Node.NAMESPACE_XML.equals(attribute.getNamespace())) { sb.append("xml "); } else if (Node.NAMESPACE_XMLNS.equals(attribute.getNamespace())) { sb.append("xmlns "); } } sb.append(k).append("=\"").append(attribute.getValue()).append("\"\n"); } sb.deleteCharAt(sb.length() - 1); } if (elem.is("template", Node.NAMESPACE_HTML)) { sb.append("\n|").append(StringUtils.repeat(' ', spaces + 2)).append("content"); depthsForTemplatesChilds += 1; } } else if (node instanceof Text) { sb.append("\"").append(((Text) node).getData()).append("\""); } else if (node instanceof Comment) { sb.append("<!-- ").append(((Comment) node).getData()).append(" -->"); } else if (node instanceof DocumentType) { DocumentType dt = (DocumentType) node; sb.append("<!DOCTYPE "); sb.append(dt.getName()); if (StringUtils.isNotBlank(dt.getPublicId()) || StringUtils.isNotBlank(dt.getSystemId())) { sb.append(" "); sb.append("\"").append(dt.getPublicId()).append("\""); sb.append(" "); sb.append("\"").append(dt.getSystemId()).append("\""); } sb.append(">"); } sb.append("\n"); for (Node childNode : node.getChildNodes()) { renderNode(childNode, depth + 1 + depthsForTemplatesChilds, sb); } }
From source file:com.chiorichan.http.Route.java
public String match(String domain, String subdomain, String uri) { String prop = params.get("pattern"); if (prop == null) prop = params.get("page"); if (prop == null) { Log.get().warning("The `pattern` attribute was null for route '" + this + "'. Unusable!"); return null; }// ww w . java2 s .c o m prop = StringUtils.trimToEmpty(prop); uri = StringUtils.trimToEmpty(uri); if (prop.startsWith("/")) { prop = prop.substring(1); params.put("pattern", prop); } if (!StringUtils.trimToEmpty(params.get("subdomain")).equals("*") && !subdomain.equals(params.get("subdomain"))) { Log.get().finer("The subdomain does not match for " + uri + " on route " + this); return null; } String[] propsRaw = prop.split("[.//]"); String[] urisRaw = uri.split("[.//]"); ArrayList<String> props = Lists.newArrayList(); ArrayList<String> uris = Lists.newArrayList(); for (String s : propsRaw) if (s != null && !s.isEmpty()) props.add(s); for (String s : urisRaw) if (s != null && !s.isEmpty()) uris.add(s); if (uris.isEmpty()) uris.add(""); if (props.isEmpty()) props.add(""); if (props.size() > uris.size()) { Log.get().finer("The length of elements in route " + this + " is LONGER then the length of elements on the uri; " + uris); return null; } if (props.size() < uris.size()) { Log.get().finer("The length of elements in route " + this + " is SHORTER then the length of elements on the uri; " + uris); return null; } String weight = StringUtils.repeat("?", Math.max(props.size(), uris.size())); boolean match = true; for (int i = 0; i < Math.max(props.size(), uris.size()); i++) try { Log.get().finest(prop + " --> " + props.get(i) + " == " + uris.get(i)); if (props.get(i).matches("\\[([a-zA-Z0-9]+)=\\]")) { weight = StringFunc.replaceAt(weight, i, "Z"); String key = props.get(i).replaceAll("[\\[\\]=]", ""); String value = uris.get(i); rewrites.put(key, value); // PREG MATCH Log.get().finer("Found a PREG match for " + prop + " on route " + this); } else if (props.get(i).equals(uris.get(i))) { weight = StringFunc.replaceAt(weight, i, "A"); Log.get().finer("Found a match for " + prop + " on route " + this); // MATCH } else { match = false; Log.get().finer("Found no match for " + prop + " on route " + this); break; // NO MATCH } } catch (ArrayIndexOutOfBoundsException e) { match = false; break; } return match ? weight : null; }
From source file:com.navercorp.pinpoint.common.buffer.FixedBufferTest.java
@Test public void readPadStringAndRightTrim() { String testString = StringUtils.repeat('a', 10); Buffer writeBuffer = new FixedBuffer(32); writeBuffer.putPadString(testString, 20); writeBuffer.putInt(255);//from ww w.j a v a 2s .co m Buffer readBuffer = new FixedBuffer(writeBuffer.getBuffer()); String readPadString = readBuffer.readPadStringAndRightTrim(20); Assert.assertEquals(testString, readPadString); int readInt = readBuffer.readInt(); Assert.assertEquals(255, readInt); }
From source file:com.gmarciani.gmparser.commons.TestDeterministicFunction.java
@Test public void createIncompleteFunction() { System.out.println("#createIncompleteFunction"); GSet<Character> domainX = new GSet<Character>(); domainX.add('a'); domainX.add('b'); domainX.add('c'); GSet<Integer> domainY = new GSet<Integer>(); domainY.add(1);//from w ww. ja va2 s. com 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); function.add('a', 1, "a"); function.add('b', 2, "bb"); function.add('c', 3, "ccc"); System.out.println(function); System.out.println(function.toFormattedFunction()); }
From source file:io.wcm.devops.conga.generator.FileGenerator.java
/** * Format comment lines./*from www .j a v a2s .c om*/ * @param lines Unformatted comment lines * @return Formatted comment lines */ private List<String> formatFileHeaderCommentLines(List<String> lines) { List<String> formattedLines = new ArrayList<>(); // create separator with same length as longest comment entry int maxLength = lines.stream().map(entry -> entry.length()).max(Integer::compare).get(); String separator = StringUtils.repeat("*", maxLength + 4); formattedLines.add(separator); formattedLines.add(""); lines.forEach(line -> formattedLines.add(" " + line)); formattedLines.add(""); formattedLines.add(separator); return formattedLines; }
From source file:com.conversantmedia.mapreduce.tool.AnnotatedToolContext.java
@Override public String toString() { int lc = getLeftColumnWidth(), rc = getRightColumnWidth(); StringBuffer buf = new StringBuffer(); // Overriding this method solely to sub out the name in the output buf.append("\n").append(this.bean.getClass().getSimpleName()).append(":\n"); buf.append(StringUtils.repeat("=", lc + rc)); buf.append("\n"); argsToString(buf, lc, rc);/*from w ww . j av a 2 s . co m*/ buf.append(StringUtils.repeat("=", lc + rc)); buf.append("\n"); return buf.toString(); }