List of usage examples for org.apache.commons.lang StringUtils repeat
public static String repeat(String str, int repeat)
Repeat a String repeat
times to form a new String.
From source file:com.kelveden.rastajax.core.RestDescriber.java
private static void logLoadingHeader() { LOGGER.info(StringUtils.repeat("=", UNDERLINE_LENGTH)); LOGGER.info("Loading resource classes..."); LOGGER.info(StringUtils.repeat("=", UNDERLINE_LENGTH)); }
From source file:net.bible.service.format.osistohtml.LHandler.java
public void startL(Attributes attrs) { // Refer to Gen 3:14 in ESV for example use of type=x-indent String type = attrs.getValue(OSISUtil.OSIS_ATTR_TYPE); int level = TagHandlerHelper.getAttribute(OSISUtil.OSIS_ATTR_LEVEL, attrs, 1); // make numIndents default to zero int numIndents = Math.max(0, level - 1); LType ltype = LType.IGNORE;//from w ww . j av a 2s. c o m if (StringUtils.isNotEmpty(type)) { if (type.contains("indent")) { // this tag is specifically for indenting so ensure there is an indent numIndents = numIndents + 1; writer.write(StringUtils.repeat(indent_html, numIndents)); ltype = LType.INDENT; } else if (type.contains("br")) { writer.write(HTML.BR); ltype = LType.BR; } else { ltype = LType.IGNORE; log.debug("Unknown <l> tag type:" + type); } } else if (TagHandlerHelper.isAttr(OSISUtil.OSIS_ATTR_SID, attrs)) { writer.write(StringUtils.repeat(indent_html, numIndents)); ltype = LType.IGNORE; } else if (TagHandlerHelper.isAttr(OSISUtil.OSIS_ATTR_EID, attrs)) { // e.g. Isaiah 40:12 writer.write(HTML.BR); ltype = LType.BR; } else { //simple <l> writer.write(StringUtils.repeat(indent_html, numIndents)); ltype = LType.END_BR; } stack.push(ltype); }
From source file:kr.ac.korea.dbserver.parser.SQLParseError.java
private String getDetailedMessageWithLocation() { StringBuilder sb = new StringBuilder(); int displayLimit = 80; String queryPrefix = "LINE " + line + ":" + charPositionInLine + " "; String prefixPadding = StringUtils.repeat(" ", queryPrefix.length()); String locationString;/* www. j a v a 2s. co m*/ int tokenLength = offendingToken.getStopIndex() - offendingToken.getStartIndex() + 1; if (tokenLength > 0) { locationString = StringUtils.repeat(" ", charPositionInLine) + StringUtils.repeat("^", tokenLength); } else { locationString = StringUtils.repeat(" ", charPositionInLine) + "^"; } sb.append("ERROR: ").append(header).append("\n"); sb.append(queryPrefix); if (errorLine.length() > displayLimit) { int padding = (displayLimit / 2); String ellipsis = " ... "; int startPos = locationString.length() - padding - 1; if (startPos <= 0) { startPos = 0; sb.append(errorLine.substring(startPos, displayLimit)).append(ellipsis).append("\n"); sb.append(prefixPadding).append(locationString); } else if (errorLine.length() - (locationString.length() + padding) <= 0) { startPos = errorLine.length() - displayLimit - 1; sb.append(ellipsis).append(errorLine.substring(startPos)).append("\n"); sb.append(prefixPadding).append(StringUtils.repeat(" ", ellipsis.length())) .append(locationString.substring(startPos)); } else { sb.append(ellipsis).append(errorLine.substring(startPos, startPos + displayLimit)).append(ellipsis) .append("\n"); sb.append(prefixPadding).append(StringUtils.repeat(" ", ellipsis.length())) .append(locationString.substring(startPos)); } } else { sb.append(errorLine).append("\n"); sb.append(prefixPadding).append(locationString); } return sb.toString(); }
From source file:com.firewallid.util.FISQL.java
public static void updateRowInsertIfNotExist(Connection conn, String tableName, Map<String, String> updateConditions, Map<String, String> fields) throws SQLException { /* Query *//*from w w w. ja v a2 s . c o m*/ String query = "SELECT " + Joiner.on(", ").join(updateConditions.keySet()) + " FROM " + tableName + " WHERE " + Joiner.on(" = ? AND ").join(updateConditions.keySet()) + " = ?"; /* Execute */ PreparedStatement pst = conn.prepareStatement(query); int i = 1; for (String value : updateConditions.values()) { pst.setString(i, value); i++; } ResultSet executeQuery = pst.executeQuery(); if (executeQuery.next()) { /* Update */ query = "UPDATE " + tableName + " SET " + Joiner.on(" = ?, ").join(fields.keySet()) + " = ? WHERE " + Joiner.on(" = ? AND ").join(updateConditions.keySet()) + " = ?"; pst = conn.prepareStatement(query); i = 1; for (String value : fields.values()) { pst.setString(i, value); i++; } for (String value : updateConditions.values()) { pst.setString(i, value); i++; } pst.executeUpdate(); return; } /* Row is not exists. Insert */ query = "INSERT INTO " + tableName + " (" + Joiner.on(", ").join(fields.keySet()) + ", " + Joiner.on(", ").join(updateConditions.keySet()) + ") VALUES (" + StringUtils.repeat("?, ", fields.size() + updateConditions.size() - 1) + "?)"; pst = conn.prepareStatement(query); i = 1; for (String value : fields.values()) { pst.setString(i, value); i++; } for (String value : updateConditions.values()) { pst.setString(i, value); i++; } pst.execute(); }
From source file:com.cloudbees.plugins.credentials.cli.ListCredentialsProvidersCommand.java
/** * {@inheritDoc}/*from www . java 2 s. co m*/ */ @Override protected int run() throws Exception { Map<String, CredentialsProvider> providersByName = CredentialsSelectHelper.getProvidersByName(); int maxNameLen = 0, maxDisplayLen = 0; for (Map.Entry<String, CredentialsProvider> entry : providersByName.entrySet()) { maxNameLen = Math.max(maxNameLen, entry.getKey().length()); maxDisplayLen = Math.max(maxDisplayLen, entry.getValue().getDisplayName().length()); } stdout.println(StringUtils.rightPad("Name", maxNameLen) + " Provider"); stdout.println(StringUtils.repeat("=", maxNameLen) + " " + StringUtils.repeat("=", maxDisplayLen)); for (Map.Entry<String, CredentialsProvider> entry : providersByName.entrySet()) { stdout.println( StringUtils.rightPad(entry.getKey(), maxNameLen) + " " + entry.getValue().getDisplayName()); } return 0; }
From source file:eu.alpinweiss.filegen.util.generator.impl.SequenceGenerator.java
public SequenceGenerator(FieldDefinition fieldDefinition) { this.fieldDefinition = fieldDefinition; final String pattern = this.fieldDefinition.getPattern(); if (!pattern.isEmpty() && pattern.matches(SEQUENCE_WITH_SUFFIX_AND_PREFIX)) { sequencePattern = cropPattern(pattern); try (Scanner scanner = new Scanner(sequencePattern[1])) { scanner.useDelimiter("\\D+"); startNum = scanner.nextInt(); digitCount = scanner.nextInt(); }/*from www . j a va 2s .c o m*/ maxValue = Integer.parseInt(StringUtils.repeat("9", digitCount)); shouldFail = sequencePattern[1].contains("FAIL"); } }
From source file:de.tudarmstadt.ukp.dkpro.core.io.text.TextWriterTest.java
@Test public void testCompressed() throws Exception { String text = StringUtils.repeat("This is a test. ", 100000); File outputPath = testContext.getTestOutputFolder(); JCas jcas = JCasFactory.createJCas(); jcas.setDocumentText(text);//from ww w . j a v a 2 s . co m DocumentMetaData meta = DocumentMetaData.create(jcas); meta.setDocumentId("dummy"); AnalysisEngineDescription writer = createEngineDescription(TextWriter.class, TextWriter.PARAM_COMPRESSION, CompressionMethod.GZIP, TextWriter.PARAM_TARGET_LOCATION, outputPath); runPipeline(jcas, writer); File input = new File(outputPath, "dummy.txt.gz"); InputStream is = CompressionUtils.getInputStream(input.getPath(), new FileInputStream(input)); assertEquals(text, IOUtils.toString(is)); }
From source file:musite.io.xml.PredictionResultXMLWriter.java
/** * {@inheritDoc}/*from w w w.ja v a2 s .c o m*/ */ public void write(final OutputStream os, final PredictionResult data) throws IOException { if (data == null) { throw new IllegalArgumentException(); } int indent = getIndent(); String prefix0 = StringUtils.repeat("\t", indent); String prefix1 = prefix0 + "\t"; OutputStreamWriter osw = new OutputStreamWriter(os); BufferedWriter bufWriter = new BufferedWriter(osw); if (root != null) bufWriter.write(prefix0 + "<" + root + ">\n"); bufWriter.write(prefix0 + "<model-list>\n"); CollectionXMLWriter collectionWriter = new CollectionXMLWriter(); //collectionWriter.setIndent(indent+3); Set<PredictionModel> models = data.getModels(); for (PredictionModel model : models) { String name = model.getName(); bufWriter.write(prefix0 + "<model name=\"" + name + "\">\n"); PTM ptm = model.getSupportedPTM(); if (ptm != null) bufWriter.write(prefix1 + "<ptm>" + StringEscapeUtils.escapeXml(ptm.name()) + "</ptm>\n"); Set<AminoAcid> aminoAcids = model.getSupportedAminoAcid(); if (aminoAcids != null && !aminoAcids.isEmpty()) { bufWriter.write(prefix1 + "<amino-acids>"); Iterator<AminoAcid> it = aminoAcids.iterator(); bufWriter.write(StringEscapeUtils.escapeXml(it.next().name())); while (it.hasNext()) bufWriter.write(StringEscapeUtils.escapeXml(";" + it.next().name())); bufWriter.write("</amino-acids>\n"); } SpecificityEstimator se = model.getSpecEstimator(); if (se instanceof SpecificityEstimatorImpl) { bufWriter.write(prefix1 + "<spec-estimate-data>"); bufWriter.flush(); SpecificityEstimatorImpl sei = (SpecificityEstimatorImpl) se; List<Double> train = sei.trainingPredictions(); collectionWriter.write(os, train); bufWriter.write("</spec-estimate-data>\n"); } String comment = model.getComment(); if (comment != null && comment.length() > 0) { comment = comment.replaceAll("\n", "%EOL%"); bufWriter.write(prefix1 + "<comment>"); bufWriter.write(StringEscapeUtils.escapeXml(comment)); bufWriter.write("</comment>\n"); } bufWriter.write(prefix0 + "</model>\n"); } bufWriter.write("</model-list>\n"); bufWriter.flush(); proteinsWriter.write(os, data); if (root != null) bufWriter.write(prefix0 + "</" + root + ">"); bufWriter.flush(); }
From source file:de.tudarmstadt.ukp.dkpro.core.api.resources.CompressionUtilsTest.java
@Test public void testPrintWriter() throws IOException { CompressionMethod compressionMethod = CompressionMethod.XZ; String text = StringUtils.repeat("This is a test. ", 100000); File file = new File("compressed" + compressionMethod.getExtension()); PrintWriter printWriter = new PrintWriter(CompressionUtils.getOutputStream(file)); printWriter.write(text);//from w w w.j a v a 2 s. com printWriter.close(); InputStream is = CompressionUtils.getInputStream(file.getPath(), new FileInputStream(file)); assertEquals(text, IOUtils.toString(is)); is.close(); file.delete(); }
From source file:de.csdev.ebus.utils.EBusConsoleUtils.java
/** * Returns device table information/*from ww w. j ava 2 s. com*/ * * @return */ public static String getDeviceTableInformation(Collection<IEBusCommandCollection> collections, EBusDeviceTable deviceTable) { StringBuilder sb = new StringBuilder(); Map<String, String> mapping = new HashMap<String, String>(); for (IEBusCommandCollection collection : collections) { for (String identification : collection.getIdentification()) { mapping.put(identification, collection.getId()); } } EBusDevice ownDevice = deviceTable.getOwnDevice(); sb.append(String.format("%-2s | %-2s | %-14s | %-14s | %-25s | %-2s | %-10s | %-10s | %-20s\n", "MA", "SA", "Identifier", "Device", "Manufacture", "ID", "Firmware", "Hardware", "Last Activity")); sb.append(String.format("%-2s-+-%-2s-+-%-14s-+-%-14s-+-%-20s-+-%-2s-+-%-10s-+-%-10s-+-%-20s\n", StringUtils.repeat("-", 2), StringUtils.repeat("-", 2), StringUtils.repeat("-", 14), StringUtils.repeat("-", 14), StringUtils.repeat("-", 20), StringUtils.repeat("-", 2), StringUtils.repeat("-", 10), StringUtils.repeat("-", 10), StringUtils.repeat("-", 20))); for (EBusDevice device : deviceTable.getDeviceTable()) { boolean isBridge = device.equals(ownDevice); String masterAddress = EBusUtils.toHexDumpString(device.getMasterAddress()); String slaveAddress = EBusUtils.toHexDumpString(device.getSlaveAddress()); String activity = device.getLastActivity() == 0 ? "---" : new Date(device.getLastActivity()).toString(); String id = EBusUtils.toHexDumpString(device.getDeviceId()).toString(); String deviceName = isBridge ? "<interface>" : mapping.getOrDefault(id, "---"); String manufacture = isBridge ? "eBUS Library" : device.getManufacturerName(); sb.append(String.format("%-2s | %-2s | %-14s | %-14s | %-25s | %-2s | %-10s | %-10s | %-20s\n", masterAddress, slaveAddress, id, deviceName, manufacture, EBusUtils.toHexDumpString(device.getManufacturer()), device.getSoftwareVersion(), device.getHardwareVersion(), activity)); } sb.append(StringUtils.repeat("-", 118) + "\n"); sb.append("MA = Master Address / SA = Slave Address / ID = Manufacture ID\n"); return sb.toString(); }