Example usage for org.apache.commons.lang3 StringUtils abbreviateMiddle

List of usage examples for org.apache.commons.lang3 StringUtils abbreviateMiddle

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils abbreviateMiddle.

Prototype

public static String abbreviateMiddle(final String str, final String middle, final int length) 

Source Link

Document

Abbreviates a String to the length passed, replacing the middle characters with the supplied replacement String.

This abbreviation only occurs if the following criteria is met:

  • Neither the String for abbreviation nor the replacement String are null or empty
  • The length to truncate to is less than the length of the supplied String
  • The length to truncate to is greater than 0
  • The abbreviated String will have enough room for the length supplied replacement String and the first and last characters of the supplied String for abbreviation

Otherwise, the returned String will be the same as the supplied String for abbreviation.

Usage

From source file:de.fau.cs.osr.hddiff.tree.DiffNode.java

@Override
public String toString() {
    String nodeStr = StringUtils.abbreviateMiddle(getNativeNode().toString(), "...", 32);
    String partnerStr = null;//w ww .j a  v a2 s . c  om
    if (getPartner() != null)
        partnerStr = StringUtils.abbreviateMiddle(getPartner().getNativeNode().toString(), "...", 32);
    return String.format(
            "" + "DiffNode:\n" + "  WOM node: \"%s\"\n" + "  Partner WOM node: %s\n" + "  Common: %d\n"
                    + "  Weight: %d\n" + "  Subtree hash: %d\n",
            nodeStr, (partnerStr == null ? "" : "\"" + partnerStr + "\""), common, weight, subtreeHash);
}

From source file:it.cnr.ilc.clavius.controller.ProofReaderController.java

public List<String> getSentences() {
    List<String> ret = new ArrayList<String>();
    for (String sent : getDocumentTei().getSentences().values()) {
        ret.add(StringUtils.abbreviateMiddle(sent, "...", 40));
    }//from  w  ww. j a  v a2 s  .c  o  m

    return ret;
}

From source file:de.fau.cs.osr.hddiff.HDDiff.java

private static String abbreviateRep(String label) {
    label = label.replace("\n", "\\n");
    label = label.replace("\"", "\\\"");
    label = StringUtils.abbreviateMiddle(label, "...", 64);
    return label;
}

From source file:org.dbgl.gui.MainWindow.java

private void updateViewProfileSubmenu(final Profile prof) {
    MenuItem parent = viewProfileSubMenu.getParentItem();
    viewProfileSubMenu.dispose();/*  w w  w  .j a  v  a 2 s  .  c  o m*/
    viewProfileSubMenu = new Menu(parent);
    parent.setMenu(viewProfileSubMenu);

    if (prof != null) {
        for (int i = 0; i < prof.getLinks().length; i++) {
            String link = prof.getLink(i);
            if (link.length() > 0) {
                final MenuItem linkMenuItem = new MenuItem(viewProfileSubMenu, SWT.NONE);
                String url = link;
                String tag = link;
                if (url.indexOf("://") == -1) {
                    url = "file://" + FileUtils.canonicalToData(url).getPath();
                    tag = FileUtils.makeRelativeToDosroot(FileUtils.canonicalToData(tag)).getPath();
                }
                String title = prof.getLinkTitle(i);
                if (title != null && !"".equals(title))
                    tag = title;
                linkMenuItem.setData(url);
                linkMenuItem.setText(StringUtils.abbreviateMiddle(tag, "....", 80));
                linkMenuItem.addSelectionListener(new SelectionAdapter() {
                    public void widgetSelected(final SelectionEvent event) {
                        PlatformUtils.openForBrowsing((String) linkMenuItem.getData());
                    }
                });
            }
        }
        final MenuItem linkMenuItem = new MenuItem(viewProfileSubMenu, SWT.NONE);
        linkMenuItem.setText(settings.msg("dialog.main.profile.view.conf"));
        linkMenuItem.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(final SelectionEvent event) {
                PlatformUtils.openForEditing(prof.getCanonicalConfFile());
            }
        });
    }
}

From source file:org.incode.module.commchannel.dom.impl.postaladdress.PostalAddress.java

public String title() {
    if (getPlaceId() != null) {
        return getFormattedAddress();
    } else {/*from ww w. ja v a  2  s .  co  m*/
        final TitleBuffer buf = new TitleBuffer();
        buf.append(getAddressLine1()).append(",", getAddressLine2()).append(",", getAddressLine3())
                .append(",", getAddressLine4()).append(",", getPostalCode()).append(",", getCountry());
        return StringUtils.abbreviateMiddle(buf.toString(), "...", 30);
    }
}

From source file:org.jenkinsci.plugins.zanata.cli.HasSyncJobDetail.java

static String mask(String secret) {
    if (Strings.isNullOrEmpty(secret)) {
        return secret;
    }/* ww w . j av a  2  s. co m*/
    if (secret.length() < 3) {
        return "*";
    }
    if (secret.length() < 5) {
        // when secret is too short, we only show the first and last character
        return secret.charAt(0) + "*" + secret.substring(secret.length() - 1);
    }
    return StringUtils.abbreviateMiddle(secret, "*", 4);
}

From source file:org.kalypso.wspwin.core.CalculationBean.java

public static void writeBerFile(final File outputFile, final CalculationBean[] calculations)
        throws IOException {
    try (final PrintWriter pw = new PrintWriter(outputFile)) {
        pw.println(calculations.length);

        for (final CalculationBean calculation : calculations) {
            final String name = calculation.getName();
            final String shortName = StringUtils.abbreviateMiddle(name, ".", 57); //$NON-NLS-1$

            final BigDecimal fromStation = calculation.getFromStation();
            final BigDecimal toStation = calculation.getToStation();
            final String calcFilename = calculation.getFileName();

            pw.format(Locale.US, "%-57s %9.4f %9.4f  %12s%n", shortName, fromStation, toStation, calcFilename); //$NON-NLS-1$
        }//from  ww w  .j a v a2 s. co m

        if (pw.checkError())
            throw new IOException();

        pw.close();
    }
}

From source file:org.kalypso.wspwin.core.ProfileBean.java

public static String shortenName(final String name, final int maxLength) {
    final String noSpaces = StringUtils.remove(name, ' '); //$NON-NLS-1$
    return StringUtils.abbreviateMiddle(noSpaces, "_", maxLength); //$NON-NLS-1$
}

From source file:org.kalypso.wspwin.core.RunOffEventBean.java

public static void write(final File outputFile, final RunOffEventBean[] fixation) throws IOException {
    try (final PrintWriter pw = new PrintWriter(outputFile)) {
        for (final RunOffEventBean runOff : fixation) {
            final String name = runOff.getName();
            final String cleanName = StringUtils.remove(name, ' ');
            final String shortName = StringUtils.abbreviateMiddle(cleanName, ".", 20); //$NON-NLS-1$

            final Map<BigDecimal, BigDecimal> entries = runOff.getEntries();

            pw.format("%s %d%n", shortName, entries.size()); //$NON-NLS-1$
            for (final Entry<BigDecimal, BigDecimal> entry : entries.entrySet()) {
                final BigDecimal station = entry.getKey();
                final BigDecimal value = entry.getValue();
                pw.format(Locale.US, "%.4f %.4f%n", station, value); //$NON-NLS-1$
            }//from w  ww.ja v  a  2s .c  om
        }

        if (pw.checkError())
            throw new IOException();

        pw.close();
    }
}

From source file:org.panther.tap5cay3.utils.UrlUtils.java

/**
 * Shorten the given Url string/*from  w w w.  j  a v  a 2 s .  c  o  m*/
 * 
 * @param url
 * @return
 */
public static String shorten(String url, int length) {

    if (url == null) {
        return "";
    }

    // remove leading http:// or https://
    String newUrl = removeProtocol(url);

    // remove trailing slash, if any
    if (newUrl.endsWith("/")) {
        newUrl = newUrl.substring(0, newUrl.length() - 1);
    }

    if (newUrl.startsWith(CORE_DOCUMENTATION_URL_PREFIX)) {
        return "..." + newUrl.substring(CORE_DOCUMENTATION_URL_PREFIX.length());
    }
    return StringUtils.abbreviateMiddle(newUrl, "...", length);
}