Example usage for java.lang StringBuilder charAt

List of usage examples for java.lang StringBuilder charAt

Introduction

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

Prototype

char charAt(int index);

Source Link

Document

Returns the char value at the specified index.

Usage

From source file:ca.uhn.fhir.model.api.Bundle.java

/**
 * Creates a new entry using the given resource and populates it accordingly
 * /*  w  ww .  j  a  v  a 2s.  co  m*/
 * @param theResource
 *            The resource to add
 * @return Returns the newly created bundle entry that was added to the bundle
 */
public BundleEntry addResource(IResource theResource, FhirContext theContext, String theServerBase) {
    BundleEntry entry = addEntry();
    entry.setResource(theResource);

    RuntimeResourceDefinition def = theContext.getResourceDefinition(theResource);

    String title = ResourceMetadataKeyEnum.TITLE.get(theResource);
    if (title != null) {
        entry.getTitle().setValue(title);
    } else {
        entry.getTitle().setValue(
                def.getName() + " " + StringUtils.defaultString(theResource.getId().getValue(), "(no ID)"));
    }

    if (theResource.getId() != null) {
        if (theResource.getId().isAbsolute()) {

            entry.getLinkSelf().setValue(theResource.getId().getValue());
            entry.getId().setValue(theResource.getId().toVersionless().getValue());

        } else if (StringUtils.isNotBlank(theResource.getId().getValue())) {

            StringBuilder b = new StringBuilder();
            b.append(theServerBase);
            if (b.length() > 0 && b.charAt(b.length() - 1) != '/') {
                b.append('/');
            }
            b.append(def.getName());
            b.append('/');
            String resId = theResource.getId().getIdPart();
            b.append(resId);

            entry.getId().setValue(b.toString());

            if (isNotBlank(theResource.getId().getVersionIdPart())) {
                b.append('/');
                b.append(Constants.PARAM_HISTORY);
                b.append('/');
                b.append(theResource.getId().getVersionIdPart());
            } else {
                IdDt versionId = (IdDt) ResourceMetadataKeyEnum.VERSION_ID.get(theResource);
                if (versionId != null) {
                    b.append('/');
                    b.append(Constants.PARAM_HISTORY);
                    b.append('/');
                    b.append(versionId.getValue());
                }
            }

            String qualifiedId = b.toString();
            entry.getLinkSelf().setValue(qualifiedId);

            // String resourceType = theContext.getResourceDefinition(theResource).getName();

        }
    }

    InstantDt published = ResourceMetadataKeyEnum.PUBLISHED.get(theResource);
    if (published == null) {
        entry.getPublished().setToCurrentTimeInLocalTimeZone();
    } else {
        entry.setPublished(published);
    }

    InstantDt updated = ResourceMetadataKeyEnum.UPDATED.get(theResource);
    if (updated != null) {
        entry.setUpdated(updated);
    }

    InstantDt deleted = ResourceMetadataKeyEnum.DELETED_AT.get(theResource);
    if (deleted != null) {
        entry.setDeleted(deleted);
    }

    IdDt previous = ResourceMetadataKeyEnum.PREVIOUS_ID.get(theResource);
    if (previous != null) {
        entry.getLinkAlternate().setValue(previous.withServerBase(theServerBase, def.getName()).getValue());
    }

    TagList tagList = ResourceMetadataKeyEnum.TAG_LIST.get(theResource);
    if (tagList != null) {
        for (Tag nextTag : tagList) {
            entry.addCategory(nextTag);
        }
    }

    String linkSearch = ResourceMetadataKeyEnum.LINK_SEARCH.get(theResource);
    if (isNotBlank(linkSearch)) {
        if (!UrlUtil.isAbsolute(linkSearch)) {
            linkSearch = (theServerBase + "/" + linkSearch);
        }
        entry.getLinkSearch().setValue(linkSearch);
    }

    String linkAlternate = ResourceMetadataKeyEnum.LINK_ALTERNATE.get(theResource);
    if (isNotBlank(linkAlternate)) {
        if (!UrlUtil.isAbsolute(linkAlternate)) {
            linkSearch = (theServerBase + "/" + linkAlternate);
        }
        entry.getLinkAlternate().setValue(linkSearch);
    }

    BundleEntrySearchModeEnum entryStatus = ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.get(theResource);
    if (entryStatus != null) {
        entry.getSearchMode().setValueAsEnum(entryStatus);
    }

    BundleEntryTransactionMethodEnum entryTransactionOperation = ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD
            .get(theResource);
    if (entryTransactionOperation != null) {
        entry.getTransactionMethod().setValueAsEnum(entryTransactionOperation);
    }

    DecimalDt entryScore = ResourceMetadataKeyEnum.ENTRY_SCORE.get(theResource);
    if (entryScore != null) {
        entry.setScore(entryScore);
    }

    return entry;
}

From source file:com.venkatesan.das.cardmanager.OCRCaptureActivity.java

private String toTitleCase(String str) {

    if (str == null) {
        return null;
    }/*from   w  w  w  .  j av  a  2s .  c o  m*/

    boolean space = true;
    StringBuilder builder = new StringBuilder(str);
    final int len = builder.length();

    for (int i = 0; i < len; ++i) {
        char c = builder.charAt(i);
        if (space) {
            if (!Character.isWhitespace(c)) {
                // Convert to title case and switch out of whitespace mode.
                builder.setCharAt(i, Character.toTitleCase(c));
                space = false;
            }
        } else if (Character.isWhitespace(c)) {
            space = true;
        } else {
            builder.setCharAt(i, Character.toLowerCase(c));
        }
    }

    return builder.toString();
}

From source file:de.codesourcery.jasm16.utils.Misc.java

public static String toBinaryString(int value, int padToLength, int... separatorsAtBits) {

    final StringBuilder result = new StringBuilder();
    final Set<Integer> separators = new HashSet<Integer>();
    if (!ArrayUtils.isEmpty(separatorsAtBits)) {
        for (int bitPos : separatorsAtBits) {
            separators.add(bitPos);/*  ww w  .j a v a  2s . c om*/
        }
    }

    for (int i = 15; i >= 0; i--) {
        if ((value & (1 << i)) != 0) {
            result.append("1");
        } else {
            result.append("0");
        }
    }

    final String s = result.toString();
    if (s.length() < padToLength) {
        final int delta = padToLength - s.length();
        return StringUtils.repeat("0", delta) + s;
    }
    if (!separators.isEmpty()) {
        final StringBuilder finalResult = new StringBuilder();
        for (int i = result.length() - 1; i >= 0; i--) {
            finalResult.append(result.charAt(i));
            final int bitOffset = result.length() - 2 - i;
            if (separators.contains(bitOffset)) {
                finalResult.append(" ");
            }
        }
        return finalResult.toString();
    }
    return s;
}

From source file:org.executequery.sql.SQLFormatter.java

private String lastCharAsString(StringBuilder sb) {

    return String.valueOf(sb.charAt(sb.length() - 1));
}

From source file:com.insprise.common.lang.StringUtilities.java

/**
  * Returns printable ASCII chars (total 126).
  * @return//from w w w  . j a va 2  s. c om
  */
 public static char[] getPrintableAsciiChars() {
     if (printableAsciiChars == null) {
         StringBuilder sb = new StringBuilder();
         sb.append("0123456789"); // 0-9: 10
         sb.append("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); // A-Z: 26
         sb.append("abcdefghijklmnopqrstuvwxyz"); // a-z: 26
         // Ref: http://en.wikipedia.org/wiki/ISO/IEC_8859-1
         for (int i = 0xC0; i <= 0xFF; i++) { //  - : 64
             sb.append((char) i);
         }
         printableAsciiChars = new char[sb.length()];
         for (int i = 0; i < sb.length(); i++) {
             printableAsciiChars[i] = sb.charAt(i);
         }
     }
     return printableAsciiChars;
 }

From source file:io.mandrel.data.filters.link.SanitizeParamsFilter.java

public boolean isValid(Link link) {
    Uri linkUri = link.getUri();/*from www . ja v  a 2s  . c  o m*/
    if (linkUri != null && StringUtils.isNotBlank(linkUri.toString())) {
        String uri = linkUri.toString();
        int pos = uri.indexOf('?');
        if (pos > -1) {
            String uriWithoutParams = uri.substring(0, pos);

            if (CollectionUtils.isNotEmpty(exclusions)) {
                String query = uri.substring(pos + 1, uri.length());

                if (StringUtils.isNotBlank(query)) {
                    String[] paramPairs = QUERY.split(query);

                    MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
                    if (paramPairs != null) {
                        for (String pair : paramPairs) {
                            String[] paramValue = PARAMS.split(pair);
                            if (exclusions.contains(paramValue[0])) {
                                params.add(paramValue[0], paramValue.length > 1 ? paramValue[1] : null);
                            }
                        }
                    }

                    StringBuilder builder = new StringBuilder();
                    params.entrySet().forEach(entry -> {
                        entry.getValue().forEach(value -> {
                            builder.append(entry.getKey());
                            if (StringUtils.isNotBlank(value)) {
                                builder.append("=").append(value);
                            }
                            builder.append("&");
                        });
                    });
                    if (builder.length() > 0 && builder.charAt(builder.length() - 1) == '&') {
                        builder.deleteCharAt(builder.length() - 1);
                    }
                    if (builder.length() > 0) {
                        link.setUri(Uri.create(uriWithoutParams + "?" + builder.toString()));
                    } else {
                        link.setUri(Uri.create(uriWithoutParams));
                    }
                } else {
                    link.setUri(Uri.create(uriWithoutParams));
                }
            } else {
                link.setUri(Uri.create(uriWithoutParams));
            }
        }
    }
    return true;
}

From source file:net.sourceforge.seqware.pipeline.plugins.WorkflowStatusChecker.java

private static String sgeConcat(SortedMap<Integer, File> idFiles) {
    StringBuilder sb = new StringBuilder();
    for (Map.Entry<Integer, File> e : idFiles.entrySet()) {
        File f = e.getValue();/*w ww.  j  av a  2  s  . c om*/

        Matcher m = SGE_FILE.matcher(f.getName());
        m.find();
        String jobName = m.group(1);

        sb.append("-----------------------------------------------------------------------");
        sb.append("\nJob Name: ");
        sb.append(jobName);
        sb.append("\nJob ID:   ");
        sb.append(e.getKey());
        sb.append("\nFile:     ");
        sb.append(f.getAbsolutePath());
        sb.append("\nUpdated:  ");
        sb.append(new Date(f.lastModified()));
        sb.append("\nContents:\n");
        try {
            sb.append(stripInvalidXmlCharacters(FileUtils.readFileToString(f)));
        } catch (IOException ex) {
            sb.append(" *** ERROR READING FILE: ");
            sb.append(ex.getMessage());
            sb.append(" ***");
        }
        if (sb.charAt(sb.length() - 1) != '\n') {
            sb.append("\n");
        }
        sb.append("-----------------------------------------------------------------------\n\n");
    }
    return sb.toString();
}

From source file:org.dhatim.archive.Archive.java

private String trimLeadingSlash(String path) {
    StringBuilder builder = new StringBuilder(path);
    while (builder.length() > 0) {
        if (builder.charAt(0) == '/') {
            builder.deleteCharAt(0);//from www  .  ja  v  a  2 s .c  o  m
        } else {
            break;
        }
    }
    return builder.toString();
}

From source file:com.gargoylesoftware.htmlunit.WebConsole.java

/**
 * This method is used by all the public method to process the passed
 * parameters./*from   w w  w.  ja  v a2 s.c  o  m*/
 *
 * If the last parameter implements the Formatter interface, it will be
 * used to format the parameters and print the object.
 * @param objs the logging parameters
 * @return a String to be printed using the logger
 */
private String process(final Object[] objs) {
    if (objs == null) {
        return "null";
    }

    final StringBuffer sb = new StringBuffer();
    final LinkedList<Object> args = new LinkedList<>(Arrays.asList(objs));

    final Formatter formatter = getFormatter();

    if (args.size() > 1 && args.get(0) instanceof String) {
        final StringBuilder msg = new StringBuilder((String) args.remove(0));
        int startPos = msg.indexOf("%");

        while (startPos > -1 && startPos < msg.length() - 1 && args.size() > 0) {
            if (startPos != 0 && msg.charAt(startPos - 1) == '%') {
                // double %
                msg.replace(startPos, startPos + 1, "");
            } else {
                final char type = msg.charAt(startPos + 1);
                String replacement = null;
                switch (type) {
                case 'o':
                case 's':
                    replacement = formatter.parameterAsString(pop(args));
                    break;
                case 'd':
                case 'i':
                    replacement = formatter.parameterAsInteger(pop(args));
                    break;
                case 'f':
                    replacement = formatter.parameterAsFloat(pop(args));
                    break;
                default:
                    break;
                }
                if (replacement != null) {
                    msg.replace(startPos, startPos + 2, replacement);
                    startPos = startPos + replacement.length();
                } else {
                    startPos++;
                }
            }
            startPos = msg.indexOf("%", startPos);
        }
        sb.append(msg);
    }

    for (final Object o : args) {
        if (sb.length() != 0) {
            sb.append(' ');
        }
        sb.append(formatter.printObject(o));
    }
    return sb.toString();
}

From source file:org.syncope.core.persistence.dao.impl.UserSearchDAOImpl.java

private List<SyncopeUser> doSearch(final Set<Long> adminRoles, final NodeCond nodeCond, final int page,
        final int itemsPerPage) {

    List<Object> parameters = Collections.synchronizedList(new ArrayList<Object>());

    // 1. get the query string from the search condition
    final StringBuilder queryString = getQuery(nodeCond, parameters);

    // 2. take into account administrative roles
    if (queryString.charAt(0) == '(') {
        queryString.insert(0, "SELECT u.user_id FROM ");
        queryString.append(" u WHERE user_id NOT IN (");
    } else {/* www. ja va2  s.c o m*/
        queryString.insert(0, "SELECT u.user_id FROM (");
        queryString.append(") u WHERE user_id NOT IN (");
    }
    queryString.append(getAdminRolesFilter(adminRoles)).append(")");

    // 3. prepare the search query
    final Query query = entityManager.createNativeQuery(queryString.toString());

    // page starts from 1, while setFirtResult() starts from 0
    query.setFirstResult(itemsPerPage * (page <= 0 ? 0 : page - 1));

    if (itemsPerPage >= 0) {
        query.setMaxResults(itemsPerPage);
    }

    // 4. populate the search query with parameter values
    fillWithParameters(query, parameters);

    LOG.debug("Native query\n{}\nwith parameters\n{}", queryString.toString(), parameters);

    // 5. Prepare the result (avoiding duplicates - set)
    final Set<Number> userIds = new HashSet<Number>();
    final List resultList = query.getResultList();

    //fix for HHH-5902 - bug hibernate
    if (resultList != null) {
        for (Object userId : resultList) {
            if (userId instanceof Object[]) {
                userIds.add((Number) ((Object[]) userId)[0]);
            } else {
                userIds.add((Number) userId);
            }
        }
    }

    final List<SyncopeUser> result = new ArrayList<SyncopeUser>(userIds.size());

    SyncopeUser user;
    for (Object userId : userIds) {
        user = userDAO.find(((Number) userId).longValue());
        if (user == null) {
            LOG.error("Could not find user with id {}, " + "even though returned by the native query", userId);
        } else {
            result.add(user);
        }
    }

    return result;
}