List of usage examples for com.google.common.base Strings repeat
public static String repeat(String string, int count)
From source file:com.google.security.zynamics.binnavi.disassembly.types.BaseType.java
/** * Creates the type name for the value type of the given base type with the specified pointer * level, e.g. returns "int **" for ("int *", 2). * * @param baseType The base type for which to create a string type representation with the given * pointer level./*from w w w .j ava2s . com*/ * @param pointerLevel The absolute pointer level to use when generating the string. * @return The string representation of the respective pointer type. */ public static String getPointerTypeName(final BaseType baseType, final int pointerLevel) { Preconditions.checkNotNull(baseType, "Error: base type argument can not be null."); Preconditions.checkArgument(pointerLevel > 0, "Error: pointer level must be greater than zero."); return String.format("%s %s", BaseType.getValueTypeName(baseType), Strings.repeat("*", pointerLevel)); }
From source file:com.facebook.presto.sql.planner.PlanPrinter.java
private static String indentString(int indent) { return Strings.repeat(" ", indent); }
From source file:org.dllearner.cli.DocumentationGenerator.java
private String getComponentConfigString(Class<?> component, Class<?> category) { // heading + anchor StringBuilder sb = new StringBuilder(); String klass = component.getName(); String header = "component: " + klass; String description = ""; String catString = "component"; String usage = null;// w ww . j av a 2 s . c o m // some information about the component if (Component.class.isAssignableFrom(component)) { Class<? extends Component> ccomp = (Class<? extends Component>) component; header = "component: " + AnnComponentManager.getName(ccomp) + " (" + klass + ") v" + AnnComponentManager.getVersion(ccomp); description = AnnComponentManager.getDescription(ccomp); catString = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, category.getSimpleName()); ComponentAnn catAnn = category.getAnnotation(ComponentAnn.class); if (catAnn != null) { catString = catAnn.shortName(); } for (Entry<Class, String> entry : varNameMapping.entrySet()) { Class cls = entry.getKey(); if (cls.isAssignableFrom(component)) { catString = entry.getValue(); } } usage = "conf file usage: " + catString + ".type = \"" + AnnComponentManager.getShortName(ccomp) + "\"\n"; } else { ComponentAnn ann = component.getAnnotation(ComponentAnn.class); if (ann != null) { header = "component: " + ann.name() + " (" + klass + ") v" + ann.version(); } description = ann.description(); if (component.equals(GlobalDoc.class)) { catString = ""; usage = ""; } else { catString = "cli"; usage = "conf file usage: " + catString + ".type = \"" + klass + "\"\n"; } } header += "\n" + Strings.repeat("=", header.length()) + "\n"; sb.append(header); if (description.length() > 0) { sb.append(description + "\n"); } sb.append("\n"); sb.append(usage + "\n"); optionsTable(sb, component, catString); return sb.toString(); }
From source file:com.ngdata.hbaseindexer.cli.ListIndexersCli.java
/** * Prints out an array of arguments./*from w w w . j a v a2 s. com*/ */ private void printArguments(String[] args, int indent, PrintStream ps, boolean dump) throws Exception { String prefix = Strings.repeat(" ", indent); if (args == null) { ps.println(prefix + "(none)"); } else { if (dump) { ps.println(prefix + Joiner.on(" ").join(args)); } else { ps.println(prefix + args.length + " arguments, use -dump to see content"); } } }
From source file:org.languagetool.dev.RuleSimplifier.java
private void simplify(PatternRule rule, List<String> xmlLines) { List<Integer> linesToRemove = new ArrayList<>(); String currentRuleId = null;/*from w ww . j a v a 2s . co m*/ Pattern pattern = Pattern.compile(".*id=[\"'](.*?)[\"'].*"); String expectedSubId = rule.getSubId(); int lineCount = 0; int subRuleCount = 0; int removedCount = 0; boolean inRuleGroup = false; String newRegex = null; boolean inAntiPattern = false; for (lineCount = 0; lineCount < xmlLines.size(); lineCount++) { //for (String xmlLine : xmlLines) { String xmlLine = xmlLines.get(lineCount); if (xmlLine.contains("<rulegroup")) { subRuleCount = 0; inRuleGroup = true; } else if (xmlLine.contains("</rulegroup>")) { subRuleCount = 0; inRuleGroup = false; } else if ((xmlLine.contains("<rule ") || xmlLine.contains("<rule>")) && inRuleGroup) { subRuleCount++; } Matcher m = pattern.matcher(xmlLine); if (m.matches()) { currentRuleId = m.group(1); } if (currentRuleId != null && !currentRuleId.equals(rule.getId())) { continue; } if (!inRuleGroup) { subRuleCount = 1; } if (!expectedSubId.equals("0") && !expectedSubId.equals(String.valueOf(subRuleCount))) { continue; } if (xmlLine.matches(".*<antipattern.*")) { inAntiPattern = true; } if (inAntiPattern) { continue; } if (xmlLine.matches(".*</antipattern.*")) { inAntiPattern = false; continue; } if (xmlLine.matches(".*<(token|pattern).*") || xmlLine.matches("\\s*</?marker>.*")) { linesToRemove.add(lineCount); } if (xmlLine.matches(".*</pattern.*")) { linesToRemove.add(lineCount); int lastTokenIndent = xmlLine.indexOf("<"); newRegex = Strings.repeat(" ", lastTokenIndent) + getRegex(rule); } } Collections.reverse(linesToRemove); // start from end, as we need to remove items for (Integer s : linesToRemove) { xmlLines.remove(s.intValue()); removedCount++; } if (removedCount == 0) { System.err.println("No line removed: " + rule + "[" + expectedSubId + "]"); } else { xmlLines.add(linesToRemove.get(linesToRemove.size() - 1), newRegex); touchedRulesCount++; } }
From source file:org.languagetool.dev.archive.RuleSimplifier.java
private void simplify(PatternRule rule, List<String> xmlLines) { List<Integer> linesToRemove = new ArrayList<>(); String currentRuleId = null;/*from w w w. j a v a 2 s . co m*/ Pattern pattern = Pattern.compile(".*id=[\"'](.*?)[\"'].*"); String expectedSubId = rule.getSubId(); int lineCount = 0; int subRuleCount = 0; int removedCount = 0; boolean inRuleGroup = false; String newRegex = null; boolean inAntiPattern = false; for (lineCount = 0; lineCount < xmlLines.size(); lineCount++) { //for (String xmlLine : xmlLines) { String xmlLine = xmlLines.get(lineCount); if (xmlLine.contains("<rulegroup")) { subRuleCount = 0; inRuleGroup = true; } else if (xmlLine.contains("</rulegroup>")) { subRuleCount = 0; inRuleGroup = false; } else if ((xmlLine.contains("<rule ") || xmlLine.contains("<rule>")) && inRuleGroup) { subRuleCount++; } Matcher m = pattern.matcher(xmlLine); if (m.matches()) { currentRuleId = m.group(1); } if (currentRuleId != null && !currentRuleId.equals(rule.getId())) { continue; } if (!inRuleGroup) { subRuleCount = 1; } if (!expectedSubId.equals("0") && !expectedSubId.equals(String.valueOf(subRuleCount))) { continue; } if (xmlLine.matches(".*<antipattern.*")) { inAntiPattern = true; } if (inAntiPattern) { continue; } if (xmlLine.matches(".*</antipattern.*")) { inAntiPattern = false; continue; } if (xmlLine.matches(".*<(token|pattern).*") || xmlLine.matches("\\s*</?marker>.*")) { linesToRemove.add(lineCount); } if (xmlLine.matches(".*</pattern.*")) { linesToRemove.add(lineCount); int lastTokenIndent = xmlLine.indexOf('<'); newRegex = Strings.repeat(" ", lastTokenIndent) + getRegex(rule); } } Collections.reverse(linesToRemove); // start from end, as we need to remove items for (Integer s : linesToRemove) { xmlLines.remove(s.intValue()); removedCount++; } if (removedCount == 0) { System.err.println("No line removed: " + rule + "[" + expectedSubId + "]"); } else { xmlLines.add(linesToRemove.get(linesToRemove.size() - 1), newRegex); touchedRulesCount++; } }
From source file:adwords.axis.v201409.shoppingcampaigns.AddProductPartitionTree.java
/** * Recursively display a node and each of its children *///from w ww. j av a 2 s. c o m private static void displayTree(ProductPartition node, Map<Long, List<ProductPartition>> children, int level) { String value = null; String type = null; if (node.getCaseValue() != null) { ProductDimension nodeCaseValue = node.getCaseValue(); type = nodeCaseValue.getProductDimensionType(); if (nodeCaseValue instanceof ProductCanonicalCondition) { value = String.valueOf(((ProductCanonicalCondition) nodeCaseValue).getCondition()); } else if (nodeCaseValue instanceof ProductBiddingCategory) { ProductBiddingCategory productBiddingCategory = (ProductBiddingCategory) nodeCaseValue; value = String.format("%s(%s)", productBiddingCategory.getType(), productBiddingCategory.getValue()); } else if (nodeCaseValue instanceof ProductBrand) { ProductBrand productBrand = (ProductBrand) nodeCaseValue; value = productBrand.getValue(); } else { value = nodeCaseValue.toString(); } } System.out.printf("%sid: %d, type: %s, value: %s%n", Strings.repeat(" ", level), node.getId(), type, value); for (ProductPartition childNode : children.get(node.getId())) { displayTree(childNode, children, level + 1); } }
From source file:org.praat.PraatTextFile.java
@Override public void writeLine(String format, Object... args) throws IOException { writer.write(Strings.repeat(" ", tabSize * indent)); writer.write(String.format(Locale.US, format, args)); writeLine();//from w w w . j a v a 2s. c om }
From source file:adwords.axis.v201402.shoppingcampaigns.AddProductPartitionTree.java
/** * Recursively display a node and each of its children */// w w w . j a v a 2s. c o m private static void displayTree(ProductPartition node, Map<Long, List<ProductPartition>> children, int level) { String value = null; String type = null; if (node.getCaseValue() != null) { ProductDimension nodeCaseValue = node.getCaseValue(); type = nodeCaseValue.getProductDimensionType(); if (nodeCaseValue instanceof ProductCanonicalCondition) { value = String.valueOf(((ProductCanonicalCondition) nodeCaseValue).getCondition()); } else if (nodeCaseValue instanceof ProductBiddingCategory) { ProductBiddingCategory productBiddingCategory = (ProductBiddingCategory) nodeCaseValue; value = String.format("%s(%s)", productBiddingCategory.getType(), productBiddingCategory.getValue()); } else if (nodeCaseValue instanceof ProductBrand) { ProductBrand productBrand = (ProductBrand) nodeCaseValue; value = productBrand.getValue(); } else { value = nodeCaseValue.toString(); } } System.out.printf("%sid: %d, type: %s, value: %s%n", Strings.repeat(" ", level), node.getId(), type, value); for (ProductPartition childNode : children.get(node.getId())) { displayTree(childNode, children, level + 1); } }
From source file:org.apache.calcite.util.TimeString.java
/** Converts this TimestampString to a string, truncated or padded with * zeroes to a given precision. */ public String toString(int precision) { Preconditions.checkArgument(precision >= 0); final int p = precision(); if (precision < p) { return round(precision).toString(precision); }//from w ww . j a v a 2 s.c om if (precision > p) { String s = v; if (p == 0) { s += "."; } return s + Strings.repeat("0", precision - p); } return v; }