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:net.sf.diningout.app.ui.FriendsFragment.java

@Override
public Loader<ReadCursor> onCreateLoader(int id, Bundle args) {
    String[] proj = { min(_ID), groupConcat(Contacts.GLOBAL_ID), Contacts.ANDROID_LOOKUP_KEY,
            Contacts.ANDROID_ID, Contacts.NAME, groupConcat(Contacts.EMAIL, "\t"), max(Contacts.FOLLOWING),
            Contacts.COLOR };//from w  w w.  j a v  a 2 s.co m
    StringBuilder sel = new StringBuilder(Contacts.STATUS_ID).append(" = ?");
    String[] selArgs;
    Uri uri = Uris.groupBy(Contacts.CONTENT_URI, Contacts.ANDROID_ID);
    StringBuilder order = new StringBuilder(
            Contacts.GLOBAL_ID + " IS NOT NULL DESC, " + Contacts.NAME + ", " + _ID);
    String searchQuery = args != null ? args.getString(SEARCH_QUERY) : null;
    if (!TextUtils.isEmpty(searchQuery)) {
        sel.append(" AND ").append(Contacts.NORMALISED_NAME).append(" LIKE ?");
        String filter = '%' + SQLite.normalise(searchQuery) + '%';
        selArgs = new String[] { String.valueOf(ACTIVE.id), filter, filter.substring(1) };
        order.insert(0, " LIKE ? DESC, ").insert(0, Contacts.NORMALISED_NAME);
    } else {
        selArgs = new String[] { String.valueOf(ACTIVE.id) };
    }
    return new ReadCursorLoader(a, uri, proj, sel.toString(), selArgs, order.toString());
}

From source file:de.schildbach.wallet.litecoin.service.BlockchainServiceImpl.java

private void notifyCoinsReceived(final Address from, final BigInteger amount) {
    if (notificationCount == 1)
        nm.cancel(NOTIFICATION_ID_COINS_RECEIVED);

    notificationCount++;// ww  w. j a v a  2  s .co m
    notificationAccumulatedAmount = notificationAccumulatedAmount.add(amount);
    if (from != null && !notificationAddresses.contains(from))
        notificationAddresses.add(from);

    final int precision = Integer.parseInt(
            prefs.getString(Constants.PREFS_KEY_LTC_PRECISION, Integer.toString(Constants.LTC_PRECISION)));

    final String tickerMsg = getString(R.string.notification_coins_received_msg,
            WalletUtils.formatValue(amount, precision)) + Constants.NETWORK_SUFFIX;

    final String msg = getString(R.string.notification_coins_received_msg,
            WalletUtils.formatValue(notificationAccumulatedAmount, precision)) + Constants.NETWORK_SUFFIX;

    final StringBuilder text = new StringBuilder();
    for (final Address address : notificationAddresses) {
        if (text.length() > 0)
            text.append(", ");
        text.append(address.toString());
    }

    if (text.length() == 0)
        text.append("unknown");

    text.insert(0, "From ");

    final NotificationCompat.Builder notification = new NotificationCompat.Builder(this);
    notification.setSmallIcon(R.drawable.stat_notify_received);
    notification.setTicker(tickerMsg);
    notification.setContentTitle(msg);
    notification.setContentText(text);
    notification
            .setContentIntent(PendingIntent.getActivity(this, 0, new Intent(this, WalletActivity.class), 0));
    notification.setNumber(notificationCount == 1 ? 0 : notificationCount);
    notification.setWhen(System.currentTimeMillis());
    notification.setSound(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.coins_received));
    nm.notify(NOTIFICATION_ID_COINS_RECEIVED, notification.getNotification());
}

From source file:me.doshou.admin.maintain.staticresource.web.controller.StaticResourceVersionController.java

/**
 * ??// w w  w  . j av  a 2  s . c o m
 * @param fileNames
 * @param contents
 * @return
 * @throws java.io.IOException
 */
@RequestMapping("batchSwitch")
@ResponseBody
public String batchSwitchStaticResource(@RequestParam("fileNames[]") String[] fileNames,
        @RequestParam("contents[]") String[] contents,
        @RequestParam(value = "min", required = false, defaultValue = "false") boolean isMin

) throws IOException {

    String rootRealPath = sc.getRealPath("/WEB-INF");
    String versionedResourceRealPath = sc.getRealPath(versionedResourcePath);

    StringBuilder success = new StringBuilder();
    StringBuilder error = new StringBuilder();

    for (int i = 0, l = fileNames.length; i < l; i++) {
        try {
            String fileName = fileNames[i];
            String content = contents[i];
            StaticResource resource = switchStaticResourceContent(rootRealPath, versionedResourceRealPath,
                    fileName, content, isMin);
            success.append("???" + resource.getUrl() + "<br/>");
        } catch (Exception e) {
            error.append("?" + e.getMessage() + "<br/>");
        }
    }

    return success.insert(0, "??<br/>").append("<br/>?<br/>").append(error)
            .toString();
}

From source file:nl.strohalm.cyclos.controls.reports.statistics.graphs.StatisticalDataProducer.java

/**
 * gets the X-axis label. If the language resource key for this label was not defined, it returns an empty string. It adjusts the label
 * automatically for any scaling done: if so, the scalefactor is appended to the label, between parenthesis (like "( x 1000)")
 * @return the x-axis label of the graph
 *//*from  w w  w .ja  v  a 2 s  .c  o  m*/
public String getX_axis() {
    if (x_axis.startsWith("???") & x_axis.endsWith("???")) {// in case of key not defined
        return "";
    }
    final StringBuilder sb = new StringBuilder();
    sb.append(x_axis);
    if (resultObject.getScaleFactorX() == null) {
        if (resultObject.getXAxisUnits().length() > 0) {
            sb.append("  ").append("(").append(resultObject.getXAxisUnits()).append(")");
        }
        return sb.toString();
    }
    sb.append("   ").append(resultObject.getScaleFactorX());
    if (resultObject.getXAxisUnits().length() > 0) {
        sb.insert(sb.length() - 1, " ").insert(sb.length() - 1, resultObject.getXAxisUnits());
    }
    return sb.toString();

}

From source file:hashengineering.digitalcoin.wallet.service.BlockchainServiceImpl.java

private void notifyCoinsReceived(@Nullable final Address from, @Nonnull final BigInteger amount) {
    if (notificationCount == 1)
        nm.cancel(NOTIFICATION_ID_COINS_RECEIVED);

    notificationCount++;//from  ww w  .  jav  a2 s .c om
    notificationAccumulatedAmount = notificationAccumulatedAmount.add(amount);
    if (from != null && !notificationAddresses.contains(from))
        notificationAddresses.add(from);

    final int precision = Integer.parseInt(
            prefs.getString(Constants.PREFS_KEY_BTC_PRECISION, Constants.PREFS_DEFAULT_BTC_PRECISION));

    final String packageFlavor = application.applicationPackageFlavor();
    final String msgSuffix = packageFlavor != null ? " [" + packageFlavor + "]" : "";

    final String tickerMsg = getString(R.string.notification_coins_received_msg,
            GenericUtils.formatValue(amount, precision)) + msgSuffix;

    final String msg = getString(R.string.notification_coins_received_msg,
            GenericUtils.formatValue(notificationAccumulatedAmount, precision)) + msgSuffix;

    final StringBuilder text = new StringBuilder();
    for (final Address address : notificationAddresses) {
        if (text.length() > 0)
            text.append(", ");
        text.append(address.toString());
    }

    if (text.length() == 0)
        text.append("unknown");

    text.insert(0, "From ");

    final NotificationCompat.Builder notification = new NotificationCompat.Builder(this);
    notification.setSmallIcon(R.drawable.stat_notify_received);
    notification.setTicker(tickerMsg);
    notification.setContentTitle(msg);
    notification.setContentText(text);
    notification
            .setContentIntent(PendingIntent.getActivity(this, 0, new Intent(this, WalletActivity.class), 0));
    notification.setNumber(notificationCount == 1 ? 0 : notificationCount);
    notification.setWhen(System.currentTimeMillis());
    notification.setSound(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.coins_received));
    nm.notify(NOTIFICATION_ID_COINS_RECEIVED, notification.getNotification());
}

From source file:de.schildbach.wallet.elysium.service.BlockchainServiceImpl.java

private void notifyCoinsReceived(final Address from, final BigInteger amount) {
    if (notificationCount == 1)
        nm.cancel(NOTIFICATION_ID_COINS_RECEIVED);

    notificationCount++;/*from ww  w  .j a va2 s . c o m*/
    notificationAccumulatedAmount = notificationAccumulatedAmount.add(amount);
    if (from != null && !notificationAddresses.contains(from))
        notificationAddresses.add(from);

    final int precision = Integer.parseInt(
            prefs.getString(Constants.PREFS_KEY_ELSM_PRECISION, Integer.toString(Constants.ELSM_PRECISION)));

    final String tickerMsg = getString(R.string.notification_coins_received_msg,
            WalletUtils.formatValue(amount, precision)) + Constants.NETWORK_SUFFIX;

    final String msg = getString(R.string.notification_coins_received_msg,
            WalletUtils.formatValue(notificationAccumulatedAmount, precision)) + Constants.NETWORK_SUFFIX;

    final StringBuilder text = new StringBuilder();
    for (final Address address : notificationAddresses) {
        if (text.length() > 0)
            text.append(", ");
        text.append(address.toString());
    }

    if (text.length() == 0)
        text.append("unknown");

    text.insert(0, "From ");

    final NotificationCompat.Builder notification = new NotificationCompat.Builder(this);
    notification.setSmallIcon(R.drawable.stat_notify_received);
    notification.setTicker(tickerMsg);
    notification.setContentTitle(msg);
    notification.setContentText(text);
    notification
            .setContentIntent(PendingIntent.getActivity(this, 0, new Intent(this, WalletActivity.class), 0));
    notification.setNumber(notificationCount == 1 ? 0 : notificationCount);
    notification.setWhen(System.currentTimeMillis());
    notification.setSound(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.coins_received));
    nm.notify(NOTIFICATION_ID_COINS_RECEIVED, notification.getNotification());
}

From source file:loggerplusplus.LogEntry.java

public void processRequest(int tool, IHttpRequestResponse requestResponse, URL url,
        IRequestInfo tempAnalyzedReq, IInterceptedProxyMessage message) {
    IHttpService tempRequestResponseHttpService = requestResponse.getHttpService();
    String strFullRequest = new String(requestResponse.getRequest());
    List<String> lstFullRequestHeader = tempAnalyzedReq.getHeaders();
    requestHeaders = StringUtils.join(lstFullRequestHeader, ", ");
    LogTable logTable = LoggerPlusPlus.getInstance().getLogTable();

    this.tool = tool;
    this.requestResponse = requestResponse;

    this.url = url;
    if (logTable.getColumnModel().isColumnEnabled("path")) // This is good to increase the speed when it is time consuming
        this.relativeURL = url.getPath();
    this.host = tempRequestResponseHttpService.getHost();
    this.protocol = tempRequestResponseHttpService.getProtocol();
    this.isSSL = this.protocol.equals("https");

    if (logTable.getColumnModel().isColumnEnabled("targetPort")) // This is good to increase the speed when it is time consuming
        this.targetPort = tempRequestResponseHttpService.getPort();

    if (logTable.getColumnModel().isColumnEnabled("method")) // This is good to increase the speed when it is time consuming
        this.method = tempAnalyzedReq.getMethod();
    try {//from www  .  jav  a2s . co  m
        // I don't want to delete special characters such as ; or : from the extension as it may really be part of the extension! (burp proxy log ignores them)
        String tempPath = url.getPath().replaceAll("\\\\", "/");
        tempPath = tempPath.substring(tempPath.lastIndexOf("/"));
        int tempPathDotLocation = tempPath.lastIndexOf(".");
        if (tempPathDotLocation >= 0)
            this.urlExtension = tempPath.substring(tempPathDotLocation + 1);
    } catch (Exception e) {
        this.urlExtension = "";
    }

    if (message != null) {
        if (logTable.getColumnModel().isColumnEnabled("listenerInterface")) // This is good to increase the speed when it is time consuming
            this.listenerInterface = message.getListenerInterface();

        if (logTable.getColumnModel().isColumnEnabled("clientIP")) // This is good to increase the speed when it is time consuming
            this.clientIP = message.getClientIpAddress().toString();
    }
    requestBodyOffset = tempAnalyzedReq.getBodyOffset();
    this.requestLength = requestResponse.getRequest().length - requestBodyOffset;
    this.hasBodyParam = requestLength > 0;
    this.params = this.url.getQuery() != null || this.hasBodyParam;
    this.hasCookieParam = false;

    // reading request headers like a boss!
    if (logTable.getColumnModel().isColumnEnabled("sentCookies")
            || logTable.getColumnModel().isColumnEnabled("hasCookieParam")
            || logTable.getColumnModel().isColumnEnabled("usesCookieJar")
            || logTable.getColumnModel().isColumnEnabled("referrer")
            || logTable.getColumnModel().isColumnEnabled("requestContentType")) { // This is good to increase the speed when it is time consuming
        for (String item : lstFullRequestHeader) {
            if (item.indexOf(":") >= 0) {
                String[] headerItem = item.split(":\\s", 2);
                headerItem[0] = headerItem[0].toLowerCase();
                if (headerItem[0].equals("cookie")) {
                    this.sentCookies = headerItem[1];
                    if (!this.sentCookies.isEmpty()) {
                        this.hasCookieParam = true;
                        this.sentCookies += ";"; // we need to ad this to search it in cookie Jar!

                        // to ensure it is enabled as it is process consuming
                        if (logTable.getColumnModel().isColumnEnabled("usesCookieJar")) {
                            // Check to see if it uses cookie Jars!
                            List<ICookie> cookieJars = LoggerPlusPlus.getCallbacks().getCookieJarContents();
                            boolean oneNotMatched = false;
                            boolean anyParamMatched = false;

                            for (ICookie cookieItem : cookieJars) {
                                if (cookieItem.getDomain().equals(this.host)) {
                                    // now we want to see if any of these cookies have been set here!
                                    String currentCookieJarParam = cookieItem.getName() + "="
                                            + cookieItem.getValue() + ";";
                                    if (this.sentCookies.contains(currentCookieJarParam)) {
                                        anyParamMatched = true;
                                    } else {
                                        oneNotMatched = true;
                                    }
                                }
                                if (anyParamMatched && oneNotMatched) {
                                    break; // we do not need to analyse it more!
                                }
                            }
                            if (oneNotMatched && anyParamMatched) {
                                this.usesCookieJar = cookieJarStatus.PARTIALLY;
                            } else if (!oneNotMatched && anyParamMatched) {
                                this.usesCookieJar = cookieJarStatus.YES;
                            }
                        }
                    }
                } else if (headerItem[0].equals("referer")) {
                    this.referrerURL = headerItem[1];
                } else if (headerItem[0].equals("content-type")) {
                    this.requestContentType = headerItem[1];
                }
            }
        }
    }

    // RegEx processing for requests - should be available only when we have a RegEx rule!
    // There are 5 RegEx rule for requests
    for (int i = 1; i < 5; i++) {
        String regexVarName = "regex" + (i + 1) + "Req";
        if (logTable.getColumnModel().isColumnEnabled(regexVarName)) {
            // so this rule is enabled!
            // check to see if the RegEx is not empty
            LogTableColumn regexColumn = logTable.getColumnModel().getColumnByName(regexVarName);
            String regexString = regexColumn.getRegExData().getRegExString();
            if (!regexString.isEmpty()) {
                // now we can process it safely!
                Pattern p = null;
                try {
                    if (regexColumn.getRegExData().isRegExCaseSensitive())
                        p = Pattern.compile(regexString);
                    else
                        p = Pattern.compile(regexString, Pattern.CASE_INSENSITIVE);

                    Matcher m = p.matcher(strFullRequest);
                    StringBuilder allMatches = new StringBuilder();
                    int counter = 1;
                    while (m.find()) {
                        if (counter == 2) {
                            allMatches.insert(0, "");
                            allMatches.append("");
                        }
                        if (counter > 1) {
                            allMatches.append("" + m.group() + "");
                        } else {
                            allMatches.append(m.group());
                        }
                        counter++;

                    }

                    this.regexAllReq[i] = allMatches.toString();

                } catch (Exception e) {
                    LoggerPlusPlus.getCallbacks().printError("Error in regular expression: " + regexString);
                }

            }
        }
    }
}

From source file:play.modules.swagger.PlayReader.java

String getPathFromRoute(PathPattern pathPattern, String basePath) {

    StringBuilder sb = new StringBuilder();
    scala.collection.Iterator iter = pathPattern.parts().iterator();
    while (iter.hasNext()) {
        PathPart part = (PathPart) iter.next();
        if (part instanceof StaticPart) {
            sb.append(((StaticPart) part).value());
        } else if (part instanceof DynamicPart) {
            sb.append("{");
            sb.append(((DynamicPart) part).name());
            sb.append("}");
        } else {/*from   w  ww .j av  a2  s. c  o  m*/
            try {
                sb.append(((StaticPart) part).value());
            } catch (ClassCastException e) {
                Logger.warn(String.format("ClassCastException parsing path from route: %s", e.getMessage()));
            }
        }
    }
    StringBuilder operationPath = new StringBuilder();
    if (basePath.startsWith("/"))
        basePath = basePath.substring(1);
    operationPath.append(sb.toString().replaceFirst(basePath, ""));
    if (!operationPath.toString().startsWith("/"))
        operationPath.insert(0, "/");
    return operationPath.toString();
}

From source file:de.blizzy.documentr.page.PageStore.java

private String getParentPagePath(String path, Repository repo) {
    File workingDir = RepositoryUtil.getWorkingDir(repo);
    File pagesDir = new File(workingDir, DocumentrConstants.PAGES_DIR_NAME);
    File pageFile = Util.toFile(pagesDir, path + DocumentrConstants.PAGE_SUFFIX);
    File dir = pageFile.getParentFile();
    StringBuilder buf = new StringBuilder();
    while (!dir.equals(pagesDir)) {
        if (buf.length() > 0) {
            buf.insert(0, '/');
        }//from w w  w  . j a v a2s.c om
        buf.insert(0, dir.getName());
        dir = dir.getParentFile();
    }
    return (buf.length() > 0) ? buf.toString() : null;
}

From source file:edu.umn.msi.tropix.persistence.service.impl.TropixObjectServiceImpl.java

private String getVirtualFolderPath(final VirtualFolder inputVirtualFolder) {
    final StringBuilder pathBuilder = new StringBuilder();
    VirtualFolder virtualFolder = inputVirtualFolder;
    while (!virtualFolder.getRoot()) {
        pathBuilder.insert(0, " > " + virtualFolder.getName());
        final Iterator<VirtualFolder> iterator = virtualFolder.getParentVirtualFolders().iterator();
        if (!iterator.hasNext()) {
            // This shouldn't happen, but the logs make it look like it has.
            LOG.warn(String.format("Found non-root virtual folder without parent with id %s and name %s",
                    virtualFolder.getId(), virtualFolder.getName()));
            pathBuilder.insert(0, "<insconsistent tree> >");
            break;
        } else {/*  w w  w  . j  a  v a2 s.  c  o  m*/
            virtualFolder = iterator.next();
        }
    }
    pathBuilder.insert(0, virtualFolder.getName());
    return pathBuilder.toString();
}