Example usage for com.google.common.base Strings repeat

List of usage examples for com.google.common.base Strings repeat

Introduction

In this page you can find the example usage for com.google.common.base Strings repeat.

Prototype

public static String repeat(String string, int count) 

Source Link

Document

Returns a string consisting of a specific number of concatenated copies of an input string.

Usage

From source file:adwords.axis.auth.AddProductPartitionTree.java

/**
 * Recursively display a node and each of its children
 *///  w  w w . ja  v 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:ezbake.deployer.utilities.Utilities.java

private static String ppMap(Map<?, ?> map, int depth) {
    List<String> entries = Lists.newArrayList();
    final String indent = Strings.repeat("  ", depth);
    for (Map.Entry entry : map.entrySet()) {
        entries.add(indent + ppObject(entry.getKey(), depth) + " = " + ppObject(entry.getValue(), depth));
    }//  w  w  w  . jav  a2 s .co  m

    return entries.isEmpty() ? "{}"
            : s("{\n%s\n%s}", Joiner.on(",\n").join(entries), Strings.repeat("  ", depth - 1));
}

From source file:alluxio.cli.fsadmin.report.CapacityCommand.java

/**
 * Prints worker capacity information.//from   w w w  .j  a v a 2 s. c  om
 *
 * @param workerInfoList the worker info list to get info from
 */
private void printWorkerInfo(List<WorkerInfo> workerInfoList) {
    mIndentationLevel = 0;
    if (mCapacityTierInfoMap.size() == 0) {
        return;
    } else if (mCapacityTierInfoMap.size() == 1) {
        // Do not print Total value when only one tier exists
        printShortWorkerInfo(workerInfoList);
        return;
    }
    Set<String> tiers = mCapacityTierInfoMap.keySet();
    String tiersInfo = String.format(Strings.repeat("%-14s", tiers.size()), tiers.toArray());
    print(String.format("%n" + LONG_INFO_FORMAT, "Worker Name", "Last Heartbeat", "Storage", "Total",
            tiersInfo));

    for (WorkerInfo info : workerInfoList) {
        String workerName = info.getAddress().getHost();

        long usedBytes = info.getUsedBytes();
        long capacityBytes = info.getCapacityBytes();

        String usedPercentageInfo = "";
        if (capacityBytes != 0) {
            int usedPercentage = (int) (100L * usedBytes / capacityBytes);
            usedPercentageInfo = String.format(" (%s%%)", usedPercentage);
        }

        String capacityTierInfo = getWorkerFormattedTierValues(mCapacityTierInfoMap, workerName);
        String usedTierInfo = getWorkerFormattedTierValues(mUsedTierInfoMap, workerName);

        print(String.format(LONG_INFO_FORMAT, workerName, info.getLastContactSec(), "capacity",
                FormatUtils.getSizeFromBytes(capacityBytes), capacityTierInfo));
        print(String.format(LONG_INFO_FORMAT, "", "", "used",
                FormatUtils.getSizeFromBytes(usedBytes) + usedPercentageInfo, usedTierInfo));
    }
}

From source file:edu.mit.streamjit.util.bytecode.Klass.java

/**
 * Creates the array class with the given component type and (additional)
 * dimensions.//from  ww  w.  java  2  s  .  c o m
 * @param componentType
 * @param dimensions
 * @param module
 */
public Klass(Klass componentType, int dimensions, Module module) {
    checkNotNull(componentType);
    checkArgument(dimensions >= 1);
    checkNotNull(module);
    StringBuilder nameBuilder = new StringBuilder(Strings.repeat("[", dimensions));
    //Always a reference type; if not already an array, add L and ;.
    nameBuilder.append(componentType.isArray() ? componentType.getName() : "L" + componentType.getName() + ";");
    this.name = nameBuilder.toString();
    checkArgument(module.getKlass(name) == null, "array klass %s already in module", name);
    module.klasses().add(this); //sets parent
    //The access modifier for an array class is that of its element type.
    //Even if the element type is mutable, we only check the modifier once.
    this.modifiers = ImmutableSet.<Modifier>builder().addAll(componentType.getAccess().modifiers())
            .add(Modifier.ABSTRACT).add(Modifier.FINAL).build();
    this.superclass = module.getKlass(Object.class);
    this.interfaces = ImmutableList.of(module.getKlass(Cloneable.class), module.getKlass(Serializable.class));
    this.fields = ImmutableList.of();
    this.methods = ImmutableList.of();
    this.backingClass = null;
}

From source file:se.toxbee.sleepfighter.text.DateTextUtils.java

/**
 * Returns an array of strings with weekday names.
 *
 * @param indiceLength how long each string should be.
 * @param locale the desired locale./*from   w ww .ja  va2s.c om*/
 * @return the array of strings.
 */
public static final String[] getWeekdayNames(int indiceLength, Locale locale) {
    DateTimeFormatter fmt = DateTimeFormat.forPattern(Strings.repeat("E", indiceLength)).withLocale(locale);

    MutableDateTime time = new MutableDateTime();
    time.setDayOfWeek(DateTimeConstants.MONDAY);

    String[] names = new String[DateTimeConstants.DAYS_PER_WEEK];

    for (int day = 0; day < DateTimeConstants.DAYS_PER_WEEK; day++) {
        String name = fmt.print(time);

        if (name.length() > indiceLength) {
            name = name.substring(0, indiceLength);
        }

        names[day] = name;

        time.addDays(1);
    }

    return names;
}

From source file:com.android.tools.perflib.vmtrace.Call.java

private void printCallHierarchy(@NonNull StringBuilder sb, Formatter formatter) {
    sb.append(" -> ");
    sb.append(formatter.format(this));

    List<Call> callees = getCallees();

    int lineStart = sb.lastIndexOf("\n");
    int depth = sb.length() - (lineStart + 1);

    for (int i = 0; i < callees.size(); i++) {
        if (i != 0) {
            sb.append("\n");
            sb.append(Strings.repeat(" ", depth));
        }/*from ww  w .  j a va 2s .co  m*/

        Call callee = callees.get(i);
        callee.printCallHierarchy(sb, formatter);
    }
}

From source file:ee.ria.xroad.opmonitordaemon.OperationalDataRecordsGenerator.java

private static String getDummyStr(int length) {
    return Strings.repeat("X", length);
}

From source file:com.davidbracewell.Application.java

/**
 * Runs the application.//from   w  ww.jav a2 s  .com
 *
 * @param args the command line arguments
 */
public final void run(String[] args) {
    if (args == null) {
        args = new String[0];
    }
    try {

        Reflect reflect = Reflect.onObject(this).allowPrivilegedAccess();

        CommandLineParser parser = new CommandLineParser();

        //Build out the command lines using the annotations on the application
        Map<CommandLineOption, Pair<Field, CommandLine>> fieldCommandLine = Maps.newHashMap();
        for (Field field : reflect.getFields()) {
            CommandLine command = field.getAnnotation(CommandLine.class);
            if (command != null) {
                String spec;
                if (command.specification().isEmpty()) {
                    if (field.getType().isInstance(Boolean.class)
                            || field.getType().isInstance(boolean.class)) {
                        spec = "--" + field.getName();
                    } else {
                        spec = "--" + field.getName() + "=ARG" + (command.optional() ? "" : "+");
                    }
                } else {
                    spec = command.specification();
                }
                fieldCommandLine.put(parser.addOption(spec, command.description(), command.aliases()),
                        Pair.of(field, command));
            }
        }

        //Parse the command line
        nonNamedArguments = Config.initialize(applicationName, args, parser);
        if (packageName != null) {
            Config.loadConfig(Resources.fromClasspath(packageName.replace(".", "/") + "/default.conf"));
        }

        //Now we set the field values based on what we found on the command line
        for (Map.Entry<CommandLineOption, Pair<Field, CommandLine>> entry : fieldCommandLine.entrySet()) {
            CommandLineOption option = entry.getKey();

            CommandLine annotation = entry.getValue().getValue();
            Val value = option.wasSeen(parser) ? option.getValue(parser) : getDefaultValue(annotation);
            Field field = entry.getValue().getKey();

            if (value != null) {
                Class<?> clazz = field.getType();
                if (Collection.class.isAssignableFrom(clazz)) {
                    Class<?> genericType = (Class<?>) ((ParameterizedType) field.getGenericType())
                            .getActualTypeArguments()[0];
                    reflect.set(field.getName(), value.asCollection(clazz, genericType));
                } else if (Map.class.isAssignableFrom(clazz)) {
                    Class<?> keyType = (Class<?>) ((ParameterizedType) field.getGenericType())
                            .getActualTypeArguments()[0];
                    Class<?> valueType = (Class<?>) ((ParameterizedType) field.getGenericType())
                            .getActualTypeArguments()[1];
                    reflect.set(field.getName(), value.asMap(clazz, keyType, valueType));
                } else {
                    reflect.set(field.getName(), value);
                }
            }

        }

        if (CommandLineOption.HELP.wasSeen(parser)) {
            String equals = Strings.repeat("=", 40) + "\n";
            String description = equals + applicationName + "\n";
            if (this.getClass().isAnnotationPresent(Description.class)) {
                description += Strings.repeat("-", 40) + "\n"
                        + this.getClass().getAnnotation(Description.class).value() + "\n";
            }
            description += equals;
            parser.showHelp(description);
            System.exit(0);
        }

        run();
    } catch (Exception e) {
        log.severe(e);
        System.exit(-1);
    }
}

From source file:com.github.jsdossier.JsDoc.java

private void parse() {
    if (parsed) {
        return;//from w  w  w .j ava 2  s  .c  o m
    }
    parsed = true;

    String original = Strings.nullToEmpty(info.getOriginalCommentString());
    if (original.isEmpty()) {
        return;
    }
    if (info.getStaticSourceFile() != null && info.getOriginalCommentPosition() > 0) {
        int offset = info.getOriginalCommentPosition();
        int column = info.getStaticSourceFile().getColumnOfOffset(offset);
        if (column > 0) {
            original = Strings.repeat(" ", column) + original;
        }
    }
    original = original.substring(0, original.length() - 2); // subtract closing */

    Iterable<String> lines = Splitter.on(EOL_PATTERN).split(original);
    int firstAnnotation = findFirstAnnotationLine(lines);
    int annotationOffset = 0;
    if (firstAnnotation != -1 && !info.getMarkers().isEmpty()) {
        blockComment = processBlockCommentLines(Iterables.limit(lines, firstAnnotation));

        JSDocInfo.StringPosition firstAnnotationPosition = info.getMarkers().iterator().next().getAnnotation();

        annotationOffset = firstAnnotationPosition.getStartLine() - firstAnnotation;
    } else {
        blockComment = processBlockCommentLines(lines);
    }

    // If we failed to extract a block comment, yet the original JSDoc has one, we've
    // probably encountered a case where the compiler merged multiple JSDoc comments
    // into one. Try to recover by parsing the compiler's provided block comment.
    if (isNullOrEmpty(blockComment) && !isNullOrEmpty(info.getBlockDescription())) {
        blockComment = processBlockCommentLines(Splitter.on('\n').split(info.getBlockDescription()));
    }

    for (JSDocInfo.Marker marker : info.getMarkers()) {
        Optional<Annotation> annotation = Annotation.forMarker(marker);
        if (!annotation.isPresent()) {
            continue; // Unrecognized/unsupported annotation.
        }

        JSDocInfo.StringPosition description = marker.getDescription();
        if (description == null) {
            continue;
        }

        int startLine = description.getStartLine() - annotationOffset;
        Iterable<String> descriptionLines = Iterables.skip(lines, startLine);

        int numLines = Math.max(description.getEndLine() - description.getStartLine(), 1);
        descriptionLines = Iterables.limit(descriptionLines, numLines);

        switch (annotation.get()) {
        case DEFINE:
            defineComment = processDescriptionLines(descriptionLines, description);
            break;
        case DEPRECATED:
            deprecationReason = processDescriptionLines(descriptionLines, description);
            break;
        case FILEOVERVIEW:
            fileoverview = processDescriptionLines(descriptionLines, description);
            break;
        case PARAM:
            String name = marker.getNameNode().getItem().getString();
            parameters.put(name, new Parameter(name, getJsTypeExpression(marker),
                    processDescriptionLines(descriptionLines, description)));
            break;
        case RETURN:
            returnDescription = processDescriptionLines(descriptionLines, description);
            break;
        case SEE:
            seeClauses.add(processDescriptionLines(descriptionLines, description));
            break;
        case THROWS:
            throwsClauses.add(new ThrowsClause(getJsTypeExpression(marker),
                    processDescriptionLines(descriptionLines, description)));
            break;
        }
    }

    if (isNullOrEmpty(blockComment)) {
        if (!isNullOrEmpty(fileoverview)) {
            blockComment = fileoverview;
        } else if (!isNullOrEmpty(defineComment)) {
            blockComment = defineComment;
        }
    }
}

From source file:ee.ria.xroad.opmonitordaemon.OperationalDataRecordsGenerator.java

private static Long getDummyLong(int length) {
    return Long.parseLong(Strings.repeat("1", length));
}