Example usage for java.lang StringBuilder insert

List of usage examples for java.lang StringBuilder insert

Introduction

In this page you can find the example usage for java.lang StringBuilder insert.

Prototype

@Override
public StringBuilder insert(int offset, double d) 

Source Link

Usage

From source file:calliope.handler.post.AeseMixedImportHandler.java

private String addCRs(String log) {
    StringBuilder sb = new StringBuilder(log);
    for (int i = log.length() - 1; i > 0; i--) {
        if (log.charAt(i) == '\n')
            sb.insert(i, "<br>");
    }/*from   w  ww  .  java  2s.c  om*/
    sb.insert(0, "<!doctype html><head><meta charset=\"UTF-8\">"
            + "<style type=\"text/css\">body { font: 12px ariel, " + "sans-serif }</style></head><body>");
    sb.append("</body></html>");
    return sb.toString();
}

From source file:com.thetechwarriors.cidrutils.Subnet.java

private String longToIp(long ip) {
    StringBuilder result = new StringBuilder(15);
    for (int i = 0; i < 4; i++) {
        result.insert(0, Long.toString(ip & 0xff));
        if (i < 3) {
            result.insert(0, '.');
        }//w  w w. j av a 2s . com
        ip = ip >> 8;
    }
    return result.toString();
}

From source file:com.heske.alexandria.activities.BookDetailFragment.java

public void displayBook(String ean) {
    mBook = DbUtils.dbLookupBook(mActivity, ean);
    if (mBook == null)
        return;/*from   w  w  w.ja  v a2  s . c om*/

    if (mShareActionProvider != null)
        mShareActionProvider.setShareIntent(getShareIntent());

    String bookSubTitle = mBook.getSubtitle();
    if (bookSubTitle.isEmpty())
        tvBookTitle.setText(mBook.getTitle());
    else
        tvBookTitle.setText(mBook.getTitle() + ": " + mBook.getSubtitle());
    tvBookDesc.setText(mBook.getDescription());
    String authors = mBook.getAuthors().get(0);
    tvAuthors.setText(authors);
    StringBuilder strISBN = new StringBuilder(mBook.getBookId());
    strISBN.insert(3, "-");
    tvISBN.setText("ISBN-13: " + strISBN);
    tvCategories.setText(mBook.getCategories().get(0));
    String imgUrl = mBook.getThumbnail();
    if (Patterns.WEB_URL.matcher(imgUrl).matches()) {
        Picasso.with(getActivity()).load(imgUrl).placeholder(R.mipmap.ic_launcher).error(R.mipmap.ic_launcher)
                .into(imgBookCover);
        imgBookCover.setVisibility(View.VISIBLE);
    }
}

From source file:com.vmware.identity.interop.PlatformUtils.java

public static String canonicalizeStringForLdapDN(String name) {
    //@see RFC 2253
    StringBuilder sb = new StringBuilder();
    if ((name.length() > 0) && ((name.charAt(0) == ' ') || (name.charAt(0) == '#'))) {
        sb.append('\\');
    }/*from   w  w w  .  j  a  v a2s .  co m*/
    for (int i = 0; i < name.length(); i++) {
        char curChar = name.charAt(i);
        switch (curChar) {
        case '\\':
            sb.append("\\\\");
            break;
        case ',':
            sb.append("\\,");
            break;
        case '+':
            sb.append("\\+");
            break;
        case '"':
            sb.append("\\\"");
            break;
        case '<':
            sb.append("\\<");
            break;
        case '>':
            sb.append("\\>");
            break;
        case ';':
            sb.append("\\;");
            break;
        default:
            sb.append(curChar);
        }
    }
    if ((name.length() > 1) && (name.charAt(name.length() - 1) == ' ')) {
        sb.insert(sb.length() - 1, '\\');
    }
    return sb.toString();
}

From source file:chat.viska.xmpp.Jid.java

/**
 * Returns the {@link String} representation of this JID.
 * @return never {@code null}.//from  www. j  a v a2s  .  c  om
 */
@Override
public String toString() {
    if (isEmpty()) {
        return "";
    }
    StringBuilder result = new StringBuilder(domainPart);
    if (!localPart.isEmpty()) {
        result.insert(0, '@').insert(0, localPart);
    }
    if (!resourcePart.isEmpty()) {
        result.append('/').append(resourcePart);
    }
    return result.toString();
}

From source file:net.jforum.util.JForumConfig.java

private void normalizeTemplateDirectory() {
    StringBuilder sb = new StringBuilder(getValue(ConfigKeys.TEMPLATE_DIRECTORY));

    if (sb.charAt(0) != '/') {
        sb.insert(0, '/');
    }//from   ww w. ja  va  2 s . c om

    if (sb.charAt(sb.length() - 1) != '/') {
        sb.append('/');
    }

    setProperty(ConfigKeys.TEMPLATE_DIRECTORY, sb.toString());
}

From source file:org.web4thejob.web.panel.DefaultPanelCommandsAuthorizationPanel.java

@Override
public void render(Listitem item, Command data, int index) throws Exception {
    Listcell listcell = new Listcell();
    listcell.setParent(item);/*from ww  w . j ava  2 s  . co m*/

    StringBuilder sb = new StringBuilder();
    Command ref = data;
    while (ref instanceof Command) {

        sb.insert(0, ref.getName());

        String image = CoreUtil.getCommandImage(ref.getId(), null);
        if (image != null) {
            StringBuilder sbHelp = new StringBuilder();
            sbHelp.append("<img src=\"");
            sbHelp.append(image);
            sbHelp.append("\" style=\"padding-left:5px;padding-right:5px;\" />");
            sb.insert(0, sbHelp.toString());
        }
        sb.insert(0, " -> ");

        if (ref instanceof Subcommand) {
            ref = ((Subcommand) ref).getParent();
        } else {
            ref = null;
        }
    }

    sb.insert(0, data.getOwner().toString());
    StringBuilder sbHelp = new StringBuilder();
    sbHelp.append("<img src=\"");
    if (data.getOwner() instanceof Panel) {
        sbHelp.append(((Panel) data.getOwner()).getImage());
    } else {
        sbHelp.append(Command.DEFAULT_COMMAND_IMAGE);
    }
    sbHelp.append("\" style=\"padding-right:5px;\" />");
    sb.insert(0, sbHelp.toString());

    Html html = new Html(sb.toString().trim());
    html.setParent(listcell);

    item.setValue(data);
    item.setStyle("white-space:nowrap;");
}

From source file:nl.mpi.lamus.archive.implementation.LamusCorpusStructureBridge.java

private void insertStringInTheBeginning(StringBuilder path, String toInsert) {
    if (path.length() > 0) {
        path.insert(0, File.separator);
    }//from  w  w  w. j ava2  s  . c  o  m
    path.insert(0, toInsert);
}

From source file:com.anrisoftware.prefdialog.miscswing.filetextfield.FileDisplayFormatter.java

private String createShortPath() {
    StringBuilder builder = new StringBuilder();
    int i;//from www  .  j a v  a  2s . c  om
    for (i = splitAbsolutePath.length - 1; i >= 0 && isInMaxWidth(builder); i--) {
        builder.insert(0, splitAbsolutePath[i]);
        builder.insert(0, separatorChar);
    }
    if (i > 0) {
        builder.insert(0, "..");
    }
    return builder.toString();
}

From source file:com.liferay.ide.gradle.core.parser.GradleDependencyUpdater.java

public FindDependenciesVisitor insertDependency(String dependency) throws IOException {
    FindDependenciesVisitor visitor = new FindDependenciesVisitor();

    walkScript(visitor);/*w  w w  .  j  a  va2s  .  c  o  m*/

    _gradleFileContents = FileUtils.readLines(_file);

    if (!dependency.startsWith("\t")) {
        dependency = "\t" + dependency;
    }

    if (visitor.getDependenceLineNum() == -1) {
        _gradleFileContents.add("");
        _gradleFileContents.add("dependencies {");
        _gradleFileContents.add(dependency);
        _gradleFileContents.add("}");
    } else {
        if (visitor.getColumnNum() != -1) {
            _gradleFileContents = Files.readAllLines(Paths.get(_file.toURI()), StandardCharsets.UTF_8);

            StringBuilder builder = new StringBuilder(
                    _gradleFileContents.get(visitor.getDependenceLineNum() - 1));

            builder.insert(visitor.getColumnNum() - 2, "\n" + dependency + "\n");
            String dep = builder.toString();

            if (CoreUtil.isWindows()) {
                dep.replace("\n", "\r\n");
            } else if (CoreUtil.isMac()) {
                dep.replace("\n", "\r");
            }

            _gradleFileContents.remove(visitor.getDependenceLineNum() - 1);
            _gradleFileContents.add(visitor.getDependenceLineNum() - 1, dep);
        } else {
            _gradleFileContents.add(visitor.getDependenceLineNum() - 1, dependency);
        }
    }

    return visitor;
}