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:net.freechoice.dao.impl.DaoTemplate.java

public final <E extends FC_Model> String bracketPostnTags(final FC_Post post, final List<E> ls) {

    StringBuilder builder = new StringBuilder(64);
    final String id1 = String.valueOf(post.getId());
    for (E v : ls) {
        builder.append("(" + v.getId() + "," + id1 + "),");
    }//w w  w . j a v a2 s.c o m
    builder.deleteCharAt(builder.lastIndexOf(","));
    return builder.toString();
}

From source file:com.counter.counter.api.MainController.java

@RequestMapping(value = "/search", method = { RequestMethod.POST })
public ResponseEntity<String> searchText(@RequestParam List<String> searchText)
        throws JsonProcessingException, JSONException {
    final HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.add("Content-Type", "application/json;charset=utf-8");

    String rVal = "";
    //System.out.println("searchText-> " + searchText.size());
    List<String> tempList = new ArrayList();
    Map<String, Integer> map;
    JSONObject jsonMap = new JSONObject();
    for (String st : searchText) {
        Integer occurence = 0;// w w  w  .  j av  a  2 s. c  o  m
        map = new HashMap();
        for (int i = sourceText.indexOf(st); i >= 0; i = sourceText.indexOf(st, i + 1))
            occurence++;
        map.put(st, occurence);
        jsonMap.put(st, occurence);
        String json = new ObjectMapper().writeValueAsString(map);
        System.out.println(json);
        tempList.add(json);
    }

    StringBuilder sb = new StringBuilder();
    JSONArray jsonArray = new JSONArray();
    jsonArray.put(jsonMap);

    System.out.println(jsonArray.toString());
    for (String s : tempList) {
        sb.append(s);
        sb.append(",");
    }
    sb.deleteCharAt(sb.lastIndexOf(","));

    //String json = new ObjectMapper().writeValueAsString(map);
    //System.out.println(json);
    return new ResponseEntity<>("[" + sb.toString() + "]", httpHeaders, HttpStatus.OK);
}

From source file:test.other.T_DaoTest.java

public void test() throws NoSuchFieldException, SecurityException, IllegalArgumentException,
        IllegalAccessException, InstantiationException {
    FC_Tag tag = new FC_Tag();
    tag.content = "content";
    //      mapper.mapToTable(get, tag);

    String namString = (String) FC_User.class.getField("TABLE_NAME").get(FC_User.class.newInstance());

    System.out.println(namString + '\n' + (String) FC_User.class.getField("TABLE_NAME").toString());

    //      /*  w  ww  .  j  av  a 2s.  c o m*/
    List<Integer> taIds = new ArrayList<Integer>();

    taIds.add(1);
    taIds.add(34);
    taIds.add(45);

    taIds.add(11);
    taIds.add(15);
    taIds.add(1556756867);
    taIds.add(25476991);

    //      StringBuilder sBuilder = new StringBuilder("(");

    //      
    //      for (Integer v_Tag : taIds) {
    //         sBuilder.append(v_Tag).append(',');
    //      }
    //      sBuilder.setCharAt(sBuilder.lastIndexOf(","), ')');
    //      System.out.println(sBuilder.toString());

    StringBuilder sBuilder = new StringBuilder();
    final String postId = String.valueOf(999);

    for (Integer v_Tag : taIds) {
        sBuilder.append("( " + postId + ", " + v_Tag + "),");
    }
    sBuilder.deleteCharAt(sBuilder.lastIndexOf(","));
    System.out.println("insert into r_tag_post(id_post_, id_tag_)values" + sBuilder.toString());
}

From source file:org.ado.googleapis.books.AbstractBookInfoLoader.java

private BookInfo getBookInfo(Item item) {
    BookInfo bookInfo = new BookInfo();
    VolumeInfo volumeInfo = item.getVolumeInfo();

    if (volumeInfo != null) {
        StringBuilder authors = new StringBuilder();
        if (volumeInfo.getAuthors() != null && !volumeInfo.getAuthors().isEmpty()) {
            for (String author : volumeInfo.getAuthors()) {
                authors.append(author).append(", ");
            }/*from w  w w  . ja  v a 2s  .  co m*/
        }
        bookInfo.setAuthor(authors.substring(0, authors.lastIndexOf(",")));

        bookInfo.setTitle(volumeInfo.getTitle());

        ImageLinks imageLinks = volumeInfo.getImageLinks();
        if (imageLinks != null) {
            bookInfo.setThumbnail(getThumbnail(imageLinks.getThumbnail()));
            bookInfo.setSmallThumbnail(getThumbnail(imageLinks.getSmallThumbnail()));
        }

        List<IndustryIdentifier> industryIdentifiers = volumeInfo.getIndustryIdentifiers();
        for (IndustryIdentifier industryIdentifier : industryIdentifiers) {
            if (IndustryIdentifierTypeEnum.ISBN_13 == industryIdentifier.getType()) {
                bookInfo.setIsbn(industryIdentifier.getIdentifier());
            }
        }
    }

    return bookInfo;
}

From source file:org.egov.egf.web.actions.masters.BankAction.java

public String getFundsJSON() {
    final List<Object[]> funds = persistenceService.findAllBy("SELECT id, name FROM Fund WHERE isactive=?",
            true);/*from w ww  .  ja va2  s  .  c  o  m*/
    final StringBuilder fundJson = new StringBuilder(":;");
    for (final Object[] fund : funds)
        fundJson.append(fund[0]).append(":").append(fund[1]).append(";");
    fundJson.deleteCharAt(fundJson.lastIndexOf(";"));
    return fundJson.toString();
}

From source file:org.exolab.castor.xml.util.resolvers.ByDescriptorClass.java

/**
 * Tries to load an XMLClassDescriptor directly from an existing .class file. <br>
 * The file that is searched for must be located in the classpath, have the name
 * <code>className</code> + "Descriptor", and contain a valid XMLClassDescriptor. <br>
 * If a descriptor is found it is added to the internal descriptor cache. <br>
 * {@inheritDoc}//from w w w. ja  v  a  2  s  .c  o  m
 */
protected Map internalResolve(final String className, final ClassLoader classLoader, final Map properties)
        throws ResolverException {

    HashMap results = new HashMap();
    if (classLoader == null) {
        LOG.debug("No class loader available.");
        return results;
    }

    StringBuilder descriptorClassName = new StringBuilder(className);
    descriptorClassName.append(XMLConstants.DESCRIPTOR_SUFFIX);
    Class descriptorClass = ResolveHelpers.loadClass(classLoader, descriptorClassName.toString());

    // If we didn't find the descriptor, look in descriptor package
    if (descriptorClass == null) {
        int offset = descriptorClassName.lastIndexOf(".");
        if (offset != -1) {
            descriptorClassName.insert(offset, ".");
            descriptorClassName.insert(offset + 1, XMLConstants.DESCRIPTOR_PACKAGE);
            descriptorClass = ResolveHelpers.loadClass(classLoader, descriptorClassName.toString());
        }
    }

    if (descriptorClass != null) {
        try {
            LOG.debug("Found descriptor: " + descriptorClass);
            results.put(className, descriptorClass.newInstance());
        } catch (InstantiationException e) {
            LOG.debug("Ignored exception: " + e + "at loading descriptor class for: " + className);
        } catch (IllegalAccessException e) {
            LOG.debug("Ignored exception: " + e + "at loading descriptor class for: " + className);
        }
    }
    return results;
}

From source file:com.ca.mas.cordova.storage.MASStoragePlugin.java

private JSONObject getResultJson(Object result) throws Exception {
    JSONObject response = new JSONObject();
    if (result == null) {
        response.put("mime", "text/plain");
        response.put("value", "");
        return response;
    }/*  w  w  w .j a va  2s. c  o m*/
    DataMarshaller marshaller = StorageDataMarshaller.findMarshaller(result);
    String mime = marshaller.getTypeAsString();

    byte[] bytes = null;
    try {
        response.put("mime", mime);
        bytes = marshaller.marshall(result);
        String b64 = new String(Base64.encode(bytes, 0), "UTF-8");
        StringBuilder base64String = new StringBuilder();
        base64String.append(b64);
        if (base64String.lastIndexOf(System.getProperty("line.separator")) != -1) {
            base64String.deleteCharAt(base64String.lastIndexOf(System.getProperty("line.separator")));
        }
        if (base64String.lastIndexOf("\r") != -1) {
            base64String.deleteCharAt(base64String.lastIndexOf("\r"));
        }
        response.put("value", base64String.toString());
        return response;
    } catch (Exception ex) {
        throw ex;
    }
}

From source file:net.sourceforge.vulcan.core.support.ProjectImporterImpl.java

protected PathInfo computeProjectBasedirUrl(String url, String relativePath, boolean computeBuildSpecPath) {
    final PathInfo pathInfo = new PathInfo();

    final int pathIndex = url.lastIndexOf(':') + 1;

    final StringBuilder sb = new StringBuilder(url.substring(pathIndex));
    sb.delete(sb.lastIndexOf("/") + 1, sb.length());
    if (relativePath != null) {
        sb.append(relativePath);//from  www  .  j  a  v  a2 s  . c o m
    }

    try {
        String normalized = new URI(sb.toString()).normalize().toString();

        if (url.startsWith("file:///") && !normalized.startsWith("///")) {
            /* Special case for file protocol.
             * URI.normalize eats the extra slashes at the begining.
             * This behavior does not seem to be documented in the JavaDoc for URI.
             */
            normalized = "//" + normalized;
        }

        final String baseUrl = url.substring(0, pathIndex) + normalized;
        pathInfo.setProjectBasedirUrl(baseUrl);

        if (computeBuildSpecPath) {
            pathInfo.setBuildSpecPath(url.substring(baseUrl.length()));
        }

        return pathInfo;
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.jasig.ssp.dao.external.ExternalCourseDao.java

public void flushAndLoadCache() {
    ExternalCourseDao.courseCache.clear();
    List<ExternalCourse> all = getAll();
    for (ExternalCourse externalCourse : all) {
        List<String> tags = getTagsForCourse(externalCourse.getCode());
        StringBuilder tagBuilder = new StringBuilder();
        for (String tagg : tags) {
            tagBuilder.append(tagg + ",");
        }/*w  w w. j  a  va 2 s  .c om*/
        if (tagBuilder.length() > 0) {
            tagBuilder.deleteCharAt(tagBuilder.lastIndexOf(","));
        }
        externalCourse.setPivotedTags(tagBuilder.toString());
    }
    ExternalCourseDao.courseCache.addAll(all);
    lastCacheFlush = Calendar.getInstance();
}

From source file:net.duckling.ddl.service.resource.dao.TagItemDAOImpl.java

@Override
public int deleteByTagIds(int[] tgids) {
    if (null == tgids || tgids.length <= 0) {
        return -1;
    }/*from   w  w w. ja v  a2s .co m*/
    StringBuilder sb = new StringBuilder();
    sb.append(" where tgid in(");
    for (int i = 0; i < tgids.length; i++) {
        sb.append(tgids[i] + ",");
    }
    sb.replace(sb.lastIndexOf(","), sb.length(), ")");
    return this.getJdbcTemplate().update(SQL_DELETE + sb.toString());
}