Example usage for java.lang StringBuilder lastIndexOf

List of usage examples for java.lang StringBuilder lastIndexOf

Introduction

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

Prototype

@Override
    public int lastIndexOf(String str) 

Source Link

Usage

From source file:org.jlibrary.core.search.extraction.html.HTMLParser.java

private static String changeLocation(String location, Directory directory, List resources) {

    String locationName = FileUtils.getFileName(location);

    Iterator it = resources.iterator();
    while (it.hasNext()) {
        ResourceNode resource = (ResourceNode) it.next();
        if (resource.getPath().endsWith(locationName)) {
            StringBuilder buffer = new StringBuilder();

            StringBuilder docPath = new StringBuilder(directory.getPath());
            StringBuilder resPath = new StringBuilder(resource.getPath());

            int k2 = resPath.lastIndexOf("/");
            resPath.delete(k2 + 1, resPath.length());

            // Remove common path
            while ((docPath.length() > 0) && (resPath.length() > 0)
                    && (docPath.charAt(0) == resPath.charAt(0))) {
                docPath.deleteCharAt(0);
                resPath.deleteCharAt(0);
            }/*from  w  w  w . j  a  va2 s.c o  m*/
            // Now check cases
            if (docPath.length() == 0) {
                // Two options
                // 1: Both, document and resource are at the same level
                // 2: Resource is at a higher level than the document
                //
                // Anyways, references would be ./resource_path
                buffer.append("./");
                buffer.append(resPath.toString());
            } else {
                // Resource is at a lower level than the document
                //
                // The path would be something like ../../resource_path 
                buffer.append("../");
                for (int i = 0; i < docPath.length(); i++) {
                    if (docPath.charAt(i) == '/') {
                        buffer.append("../");
                    }
                }
                if (buffer.charAt(buffer.length() - 1) == '/') {
                    buffer.deleteCharAt(buffer.length() - 1);
                }
                buffer.append(resPath.toString());
            }
            buffer.append(locationName);
            return buffer.toString();

        }
    }
    // No changes
    return location;
}

From source file:org.omegat.gui.dialogs.AboutDialog.java

private static String wrap(String text, int length) {
    StringBuilder sb = new StringBuilder();
    for (String line : text.split("\\n")) {
        if (sb.length() > 0) {
            sb.append(',');
        }// www  .  ja  va  2s.  c om
        for (String token : line.split("\\s")) {
            if (sb.length() + 1 + token.length() - sb.lastIndexOf("\n") > length) {
                sb.append('\n');
            }
            if (sb.length() > 0 && sb.charAt(sb.length() - 1) != '\n') {
                sb.append(' ');
            }
            sb.append(token);
        }
    }
    return sb.toString();
}

From source file:edu.kit.dama.util.ZipUtils.java

/**
 * Compress all files of one directory with given extensions to a single zip
 * file./*from  w w  w .  jav a  2 s.com*/
 *
 * @param pZipFile resulting zip File. Existing file will be overwritten!
 * @param pDirectory directory to explore.
 * @param pExtension allowed file name extensions of files to compress
 * @return success or not.
 */
public static boolean zipDirectory(final File pZipFile, final File pDirectory, final String... pExtension) {
    boolean success = false;
    File[] files = pDirectory.listFiles(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            boolean accept = false;
            String lowerCase = name.toLowerCase();
            if (pExtension != null) {
                for (String extension : pExtension) {
                    if (lowerCase.endsWith(extension.toLowerCase())) {
                        accept = true;
                        break;
                    }
                }
            } else {
                accept = true;
            }
            return accept;
        }
    });
    if (LOGGER.isDebugEnabled()) {
        String fileSeparator = ", ";
        LOGGER.debug("Zip files to " + pZipFile.getName());
        StringBuilder sb = new StringBuilder("Selected files: ");
        for (File file : files) {
            sb.append(file.getName()).append(fileSeparator);
        }
        int lastIndex = sb.lastIndexOf(fileSeparator);
        sb.delete(lastIndex, lastIndex + fileSeparator.length());
        LOGGER.debug(sb.toString());
    }
    try {
        zip(files, pDirectory.getPath(), pZipFile);
        success = true;
    } catch (IOException ex) {
        LOGGER.error("Error while zipping files!", ex);
    }
    return success;
}

From source file:com.shenit.commons.utils.CollectionUtils.java

/**
 * /*from   w w w  .  jav a 2s.  c  o  m*/
 * @param targets
 * @param string
 * @return
 */
public static <T> String join(T[] targets, String delimiter) {
    if (ValidationUtils.isEmpty(targets))
        return StringUtils.EMPTY;
    StringBuilder builder = new StringBuilder();
    for (T target : targets) {
        builder.append(target).append(delimiter);
    }
    //?
    if (builder.indexOf(delimiter) > 0)
        builder.deleteCharAt(builder.lastIndexOf(delimiter));
    return builder.toString();
}

From source file:com.autentia.wuija.trace.persistence.OperationalTraceBuilder.java

private static OperationalTraceParams generateParamForSimpleExpressionCheckingIfIsDate(SimpleExpression exp,
        String classOfProperty) {
    final StringBuilder builder = new StringBuilder(exp.getValues().toString());

    if (!exp.getValues().isEmpty() && exp.getValues().get(0) instanceof Date) {
        builder.delete(0, builder.length());
        for (Object date : exp.getValues()) {
            builder.append(DateFormater.format((Date) date, FORMAT.DEFAULT_DATE));
            builder.append(", ");
        }/*from ww w.  j  a va2s.  c om*/
        builder.delete(builder.lastIndexOf(", "), builder.length());
    }

    return new OperationalTraceParams(
            classOfProperty == "" ? exp.getProperty() : classOfProperty + "." + exp.getProperty(),
            exp.getOperator(), builder.toString());
}

From source file:com.impetus.client.cassandra.common.CassandraUtilities.java

/**
 * Append columns.//from ww w.  j  av a  2  s . co m
 * 
 * @param builder
 *            the builder
 * @param columns
 *            the columns
 * @param selectQuery
 *            the select query
 * @param translator
 *            the translator
 */
public static StringBuilder appendColumns(StringBuilder builder, List<String> columns, String selectQuery,
        CQLTranslator translator) {
    if (columns != null) {
        for (String column : columns) {
            translator.appendColumnName(builder, column);
            builder.append(",");
        }
    }
    if (builder.lastIndexOf(",") != -1) {
        builder.deleteCharAt(builder.length() - 1);
        selectQuery = StringUtils.replace(selectQuery, CQLTranslator.COLUMNS, builder.toString());
    }

    builder = new StringBuilder(selectQuery);
    return builder;
}

From source file:sonicScream.utilities.ScriptParser.java

public static String parseScriptTreeToString(TreeItem<String> currentScriptTree) {
    TreeItem<String> root = currentScriptTree;
    StringBuilder scriptString = new StringBuilder();
    recursiveBuildScript(scriptString, root, 0);

    //Remove first, final braces, starting newline. We don't need that first layer of nesting the braces would cause
    scriptString.deleteCharAt(0);/*from  ww w .j  a v a  2s.c  om*/
    scriptString.deleteCharAt(0);

    //Remove final brace
    scriptString.deleteCharAt(scriptString.lastIndexOf("}"));
    return scriptString.toString();
}

From source file:org.eclipse.smarthome.documentation.MarkdownProvider.java

/**
 * Takes the options and parses them to a string list.
 *
 * @param options//from   w w w.  jav a2  s. c om
 * @return
 */
private static StringBuilder optionsToString(Options options) {
    StringBuilder builder = new StringBuilder();
    if (options == null) {
        return builder;
    }
    for (Option opt : options.getOption()) {
        builder.append(opt.getValue()).append(", ");
    }
    // Remove trailing ","
    builder.deleteCharAt(builder.lastIndexOf(","));
    return builder;
}

From source file:org.limy.common.util.UrlUtils.java

/**
 * ?????????//w  w  w.  j  ava 2s.  com
 * @param basePath 
 * @param url 
 * @return 
 */
public static String concatUrl(String basePath, String url) {
    StringTokenizer tokenizer = new StringTokenizer(url, "/");
    StringBuilder result = new StringBuilder(basePath);
    try {
        while (tokenizer.hasMoreTokens()) {
            String token = tokenizer.nextToken();
            if (".".equals(token)) {
                continue;
            }
            if ("..".equals(token)) {
                if (result.charAt(result.length() - 1) == '/') {
                    result.setLength(result.length() - 1);
                }
                if (result.lastIndexOf("/") >= 0) {
                    result.setLength(result.lastIndexOf("/"));
                } else {
                    result.setLength(0);
                }
                continue;
            }
            if (result.length() > 0 && result.charAt(result.length() - 1) != '/') {
                result.append('/');
            }
            result.append(token);
        }
    } catch (StringIndexOutOfBoundsException e) {
        LOG.warn(e.getMessage(), e);
        return url;
    }
    return result.toString();
}

From source file:txyd.util.StringUtils.java

/**
 * ?/*  w  w w  . j  a  v a  2 s. c  o  m*/
 *
 * @param cs
 * @param separator
 * @return
 */
public static String getStrByCollectionAndSeparator(final Collection<?> cs, final String separator) {
    if (cs == null || cs.size() == 0) {
        return "";
    }
    StringBuilder stringBuilder = new StringBuilder();
    for (Object item : cs) {
        stringBuilder.append(item.toString() + separator);
    }
    return stringBuilder.substring(0, stringBuilder.lastIndexOf(separator)).toString();
}