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

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

Introduction

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

Prototype

public static String padEnd(String string, int minLength, char padChar) 

Source Link

Document

Returns a string, of length at least minLength , consisting of string appended with as many copies of padChar as are necessary to reach that length.

Usage

From source file:pt.ist.fenix.task.exportData.academic.EnrolmentStatistics.java

private void writeResults() {
    taskLog("Total -> " + totalEnrolments);
    taskLog("********************************");
    int total = 0;
    for (Entry<Integer, Integer> entry : enrolmentsNumber.entrySet()) {
        Integer value = entry.getValue();
        taskLog(entry.getKey() + " Inscricao -> " + value);
        total += value;// www . ja va 2 s  .c o m
    }

    taskLog("Total de alunos inscritos -> " + total);
    taskLog("********************************");
    int totalEnrolments = 0;
    for (Entry<DegreeCurricularPlan, GenericPair<Integer, Integer>> entry : degreesMap.entrySet()) {
        String degreeName = Strings.padEnd(entry.getKey().getName(), 12, ' ');
        //degree name -> students enrolled - number of enrolments
        taskLog(degreeName + " -> " + Strings.padStart(entry.getValue().getLeft().toString(), 3, ' ') + "  "
                + Strings.padStart(entry.getValue().getRight().toString(), 3, ' '));
        totalEnrolments += entry.getValue().getRight();
    }
    taskLog("********************************");
    taskLog("Total inscries -> " + totalEnrolments);
}

From source file:tableCreator.ConsoleStringTable.java

public String getTableAsString(int padding) {
    String out = "";
    for (int r = 0; r < numRows; r++) {
        for (int c = 0; c < numColumns; c++) {
            int columSize = getColumSize(c);
            String content = getString(r, c);
            int pad = c == numColumns - 1 ? 0 : padding;
            out += Strings.padEnd(content, columSize + pad, ' ');
        }// w ww  .  ja v  a2 s  . c o m

        if (r < numRows - 1) {
            out += "\n";
        }
        if (r == 0) {
            out += Strings.padEnd("", getTableSize(), '-');
            out += "\n";
        }
    }
    return out;
}

From source file:edu.uci.ics.sourcerer.tools.java.component.identifier.stats.ClusterStats.java

public static void calculate(JarCollection jars, ClusterCollection clusters) {
    if (CLUSTER_LISTING.getValue() == null) {
        return;/*from   ww  w .j  a va 2s. c  om*/
    }
    TaskProgressLogger task = TaskProgressLogger.get();
    task.start("Logging cluster listing to: " + CLUSTER_LISTING.getValue().getPath());

    // Print out list of clusters, ordered by number of jars
    try (LogFileWriter log = IOUtils.createLogFileWriter(CLUSTER_LISTING)) {
        Cluster[] sorted = Iterators.toArray(clusters, new Cluster[clusters.size()]);

        Arrays.sort(sorted, new Comparator<Cluster>() {
            @Override
            public int compare(Cluster one, Cluster two) {
                return Integer.compare(two.getJars().size(), one.getJars().size());
            }
        });

        Integer maxJarsToShow = null;//GeneralStats.MAX_TABLE_COLUMNS.getValue();

        for (Cluster cluster : sorted) {
            // Collect all the jars that overlap with this jar
            Jar[] containedJars = null;
            {
                Set<Jar> sortedJars = new TreeSet<>(new Comparator<Jar>() {
                    @Override
                    public int compare(Jar o1, Jar o2) {
                        String name1 = o1.getJar().toString();
                        String name2 = o2.getJar().toString();
                        return name1 == null ? (name2 == null ? 0 : -1)
                                : (name2 == null ? 1 : name1.compareTo(name2));
                    }
                });
                for (Jar jar : cluster.getJars()) {
                    sortedJars.add(jar);
                }
                containedJars = new Jar[sortedJars.size()];

                int i = 0;
                for (Jar jar : sortedJars) {
                    containedJars[i++] = jar;
                }
            }

            // Log the header info
            log.writeAndIndent("Cluster of " + containedJars.length + " jars");
            log.writeAndIndent("Listing jars in cluster");

            // Log the list of jars in this cluster
            int c = 1;
            for (Jar jar : containedJars) {
                log.write(Strings.padEnd(c++ + ": ", 5, ' ') + jar + " "
                        + jar.getJar().getProperties().HASH.getValue());
            }
            c = maxJarsToShow == null ? containedJars.length : Math.min(maxJarsToShow, containedJars.length);
            log.unindent();
            log.unindent();

            // Start with the core FQNs
            // Log the number line
            for (int i = 1; i <= c; i++) {
                log.writeFragment(Integer.toString(i % 10));
            }
            log.writeFragment(" Core FQNs");
            log.newLine();

            // sort them alphabetically
            Collection<VersionedFqnNode> coreFqns = new TreeSet<>(cluster.getCoreFqns());
            for (VersionedFqnNode fqn : coreFqns) {
                for (Jar jar : containedJars) {
                    // Does this jar contain the FQN?
                    if (fqn.getJars().contains(jar)) {
                        log.writeFragment("*");
                    } else {
                        log.writeFragment(" ");
                    }
                }
                log.writeFragment(" " + fqn.getFqn());
                log.newLine();
            }
            coreFqns = cluster.getCoreFqns();

            // Log the versioned core fqns
            if (!cluster.getVersionFqns().isEmpty()) {
                // Log the number line
                for (int i = 1; i <= c; i++) {
                    log.writeFragment(Integer.toString(i % 10));
                }
                log.writeFragment(" Versioned Core FQNs");
                log.newLine();

                Collection<VersionedFqnNode> versionedCoreFqns = new TreeSet<>(cluster.getVersionFqns());
                for (VersionedFqnNode fqn : versionedCoreFqns) {
                    for (Jar jar : containedJars) {
                        // Does this jar contain the FQN?
                        if (fqn.getJars().contains(jar)) {
                            log.writeFragment("*");
                        } else {
                            log.writeFragment(" ");
                        }
                    }
                    log.writeFragment(" " + fqn.getFqn());
                    log.newLine();
                }
            }

            //        // See if there are any other extra fqns
            //        Collection<VersionedFqnNode> extraFqns = new TreeSet<>();
            //        for (VersionedFqnNode fqn : cluster.getExtraFqns()) {
            //          if (!nonCoreExemplar.contains(fqn)) {
            //            extraFqns.add(fqn);
            //          }
            //        }
            //         
            //        // Log the extra fqns
            //        if (!extraFqns.isEmpty()) {
            //          // Log the number line
            //          for (int i = 1; i <= c; i++) {
            //            log.writeFragment(Integer.toString(i % 10));
            //          }
            //          log.writeFragment(" Extra FQNs");
            //          log.newLine();
            //          
            //          for (VersionedFqnNode fqn : extraFqns) {
            //            for (Jar jar : containedJars) {
            //              // Does this other jar contain the FQN?
            //              if (fqn.getVersions().getJars().contains(jar)) {
            //                log.writeFragment("*");
            //              } else {
            //                log.writeFragment(" ");
            //              }
            //            }
            //            log.writeFragment(" " + fqn.getFqn());
            //            log.newLine();
            //          }
            //        } 
        }
    } catch (IOException e) {
        logger.log(Level.SEVERE, "Error in writing logs", e);
    }
    task.finish();
}

From source file:fathom.security.SecurityManager.java

@Override
public void start() {
    allRealms = Collections.emptyList();

    // configure the SecurityManager
    URL configFileUrl = settings.getFileUrl("security.configurationFile", "classpath:conf/realms.conf");

    if (configFileUrl == null) {
        throw new FathomException("Failed to find Security Realms file '{}'",
                settings.getString("security.configurationFile", "classpath:conf/realms.conf"));
    }//  w  ww .j a  v a  2 s  .  com

    Config config;
    try (InputStreamReader reader = new InputStreamReader(configFileUrl.openStream())) {
        config = ConfigFactory.parseReader(reader).resolve();
        log.info("Configured Security Realms from '{}'", configFileUrl);
    } catch (IOException e) {
        throw new FathomException(e, "Failed to parse Security Realms file '{}'", configFileUrl);
    }

    allRealms = parseDefinedRealms(config);

    // configure an expiring account cache
    int cacheTtl = 0;
    if (config.hasPath("cacheTtl")) {
        cacheTtl = config.getInt("cacheTtl");
    }

    int cacheMax = 100;
    if (config.hasPath("cacheMax")) {
        cacheMax = config.getInt("cacheMax");
    }

    if (cacheTtl > 0 && cacheMax > 0) {
        accountCache = CacheBuilder.newBuilder().expireAfterAccess(cacheTtl, TimeUnit.MINUTES)
                .maximumSize(cacheMax).build();
    }

    String border = Strings.padEnd("", Constants.MIN_BORDER_LENGTH, '-');
    log.info(border);
    log.info("Starting realms");
    log.info(border);
    for (Realm realm : allRealms) {
        log.debug("{} '{}'", realm.getClass().getName(), realm.getRealmName());
    }
    for (Realm realm : allRealms) {
        try {
            log.info("Starting realm '{}'", realm.getRealmName());
            realm.start();
        } catch (Exception e) {
            log.error("Failed to start realm '{}'", realm.getRealmName(), e);
        }
    }
}

From source file:org.fenixedu.idcards.ui.IdentificationCardDA.java

private String getIdentificationCardState(Person person) {
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();

    factory.setServiceClass(IRegistersInfo.class);
    factory.setAddress("https://portal.sibscartoes.pt/wcf/RegistersInfo.svc");
    factory.setBindingId("http://schemas.xmlsoap.org/wsdl/soap12/");
    factory.getFeatures().add(new WSAddressingFeature());
    IRegistersInfo port = (IRegistersInfo) factory.create();

    /*define WSDL policy*/
    Client client = ClientProxy.getClient(port);
    HTTPConduit http = (HTTPConduit) client.getConduit();
    http.getAuthorization().setUserName(IdCardsConfiguration.getConfiguration().sibsWebServiceUsername());
    http.getAuthorization().setPassword(IdCardsConfiguration.getConfiguration().sibsWebServicePassword());

    final String userName = Strings.padEnd(person.getUsername(), 10, 'x');
    RegisterData statusInformation = port.getRegister(userName);

    return statusInformation.getStatusDate().getValue().replaceAll("-", "/") + " : "
            + statusInformation.getStatus().getValue() + " - " + statusInformation.getStatusDesc().getValue();

}

From source file:org.cinchapi.concourse.util.TLinkedHashMap.java

@Override
public String toString() {
    String format = "| %-" + keyLength + "s | %-" + valueLength + "s |%n";
    String hr = Strings.padEnd("+", keyLength + valueLength + 6, '-'); // there
                                                                       // are
                                                                       // 6
                                                                       // spaces
                                                                       // in
                                                                       // the
                                                                       // #format
    hr += "+" + System.getProperty("line.separator");
    StringBuilder sb = new StringBuilder();
    sb.append(System.getProperty("line.separator"));
    sb.append(hr);/* w w  w. jav a 2s . c o m*/
    sb.append(String.format(format, keyName, valueName));
    sb.append(hr);
    for (Map.Entry<K, V> entry : entrySet()) {
        sb.append(String.format(format, entry.getKey(), entry.getValue()));
    }
    sb.append(hr);
    return sb.toString();
}

From source file:ninja.bodyparser.BodyParserEngineManagerImpl2.java

final protected void logBodyParserEngines() {
    List<String> outputTypes = Lists.newArrayList(getContentTypes());
    Collections.sort(outputTypes);

    int maxContentTypeLen = 0;
    int maxBodyParserEngineLen = 0;

    for (String contentType : outputTypes) {

        BodyParserEngine bodyParserEngine = getBodyParserEngineForContentType(contentType);

        maxContentTypeLen = Math.max(maxContentTypeLen, contentType.length());
        maxBodyParserEngineLen = Math.max(maxBodyParserEngineLen,
                bodyParserEngine.getClass().getName().length());

    }// w  w  w. j a va2s  . co m

    int borderLen = 6 + maxContentTypeLen + maxBodyParserEngineLen;
    String border = Strings.padEnd("", borderLen, '-');

    logger.info(border);
    logger.info("Registered request bodyparser engines");
    logger.info(border);

    for (String contentType : outputTypes) {

        BodyParserEngine templateEngine = getBodyParserEngineForContentType(contentType);
        logger.info("{}  =>  {}", Strings.padEnd(contentType, maxContentTypeLen, ' '),
                templateEngine.getClass().getName());

    }

}

From source file:ninja.bodyparser.BodyParserEngineManagerImpl.java

protected void logBodyParserEngines() {
    List<String> outputTypes = Lists.newArrayList(getContentTypes());
    Collections.sort(outputTypes);

    int maxContentTypeLen = 0;
    int maxBodyParserEngineLen = 0;

    for (String contentType : outputTypes) {

        BodyParserEngine bodyParserEngine = getBodyParserEngineForContentType(contentType);

        maxContentTypeLen = Math.max(maxContentTypeLen, contentType.length());
        maxBodyParserEngineLen = Math.max(maxBodyParserEngineLen,
                bodyParserEngine.getClass().getName().length());

    }/* w w w.  j a  v  a 2  s . c  o m*/

    int borderLen = 6 + maxContentTypeLen + maxBodyParserEngineLen;
    String border = Strings.padEnd("", borderLen, '-');

    logger.info(border);
    logger.info("Registered request bodyparser engines");
    logger.info(border);

    for (String contentType : outputTypes) {

        BodyParserEngine templateEngine = getBodyParserEngineForContentType(contentType);
        logger.info("{}  =>  {}", Strings.padEnd(contentType, maxContentTypeLen, ' '),
                templateEngine.getClass().getName());

    }

}

From source file:com.google.cloud.spanner.Timestamp.java

/**
 * Creates a Timestamp instance from the given string. String is in the RFC 3339 format without
 * the timezone offset (always ends in "Z").
 *///from www  . ja v  a2 s.  c  om
public static Timestamp parseTimestamp(String timestamp) {
    Matcher matcher = FORMAT_REGEXP.matcher(timestamp);
    if (!matcher.matches()) {
        throw new IllegalArgumentException("Cannot parse input: " + timestamp);
    }
    String secondsPart = matcher.group(1);
    String nanosPart = matcher.group(2);
    long seconds;
    seconds = format.parseMillis(secondsPart) / 1000;
    int nanos = 0;
    if (nanosPart != null) {
        String padded = Strings.padEnd(nanosPart.substring(1), 9, '0');
        nanos = Integer.parseInt(padded);
        if (nanos >= TimeUnit.SECONDS.toNanos(1)) {
            throw new IllegalArgumentException("Cannot parse input: " + timestamp + " (nanos out of range)");
        }
    }
    return ofTimeSecondsAndNanos(seconds, nanos);
}

From source file:ninja.template.TemplateEngineManagerImpl2.java

final protected void logTemplateEngines() {
    List<String> outputTypes = Lists.newArrayList(getContentTypes());
    Collections.sort(outputTypes);

    if (outputTypes.isEmpty()) {

        logger.error("No registered template engines?! Please install a template module!");
        return;//  w  w  w .  j a v a  2 s. c  om

    }

    int maxContentTypeLen = 0;
    int maxTemplateEngineLen = 0;

    for (String contentType : outputTypes) {

        TemplateEngine templateEngine = getTemplateEngineForContentType(contentType);

        maxContentTypeLen = Math.max(maxContentTypeLen, contentType.length());
        maxTemplateEngineLen = Math.max(maxTemplateEngineLen, templateEngine.getClass().getName().length());

    }

    int borderLen = 6 + maxContentTypeLen + maxTemplateEngineLen;
    String border = Strings.padEnd("", borderLen, '-');

    logger.info(border);
    logger.info("Registered response template engines");
    logger.info(border);

    for (String contentType : outputTypes) {

        TemplateEngine templateEngine = getTemplateEngineForContentType(contentType);
        logger.info("{}  =>  {}", Strings.padEnd(contentType, maxContentTypeLen, ' '),
                templateEngine.getClass().getName());

    }

}