List of usage examples for java.lang StringBuilder lastIndexOf
@Override public int lastIndexOf(String str)
From source file:com.forerunnergames.tools.common.Strings.java
/** * Converts a collection of list elements to a string list, separated by separator, in case letterCase. * * @param <T>// w w w . jav a 2 s.c om * The type of the list elements. * @param listElements * The collection of list elements to convert, must not be null, must not contain any null elements. * @param separator * The separator that should be added between list elements, must not be null. * @param letterCase * The desired letter case of the list elements, must not be null, choose LetterCase.NONE to leave the list * elements as-is. * @param hasAnd * Whether or not to insert the word 'and ' between the last two elements in the list, one space after the * last separator. * * @return A string list of listElements, separated by separator, in case letterCase, with an optional 'and ' * occurring between the last two elements of the list. */ public static <T> String toStringList(final Collection<T> listElements, final String separator, final LetterCase letterCase, final boolean hasAnd) { Arguments.checkIsNotNull(listElements, "listElements"); Arguments.checkHasNoNullElements(listElements, "listElements"); Arguments.checkIsNotNull(separator, "separator"); Arguments.checkIsNotNull(letterCase, "letterCase"); final ImmutableList.Builder<T> printableListElementsBuilder = ImmutableList.builder(); for (final T element : listElements) { if (isPrintable(element.toString())) printableListElementsBuilder.add(element); } final ImmutableList<T> printableListElements = printableListElementsBuilder.build(); // Handle the first three special cases if (printableListElements.isEmpty()) { return ""; } else if (printableListElements.size() == 1) { return toCase(Iterables.getOnlyElement(printableListElements).toString(), letterCase); } else if (printableListElements.size() == 2) { final Iterator<T> iterator = printableListElements.iterator(); // Here, if the separator is a comma, for example, it's either: // "item1 and item2" or "item1,item2" (if no "and" is desired) // because "item1, and item2" doesn't make sense grammatically, which is // what would happen if we didn't treat this as a special case return toCase(iterator.next().toString() + (hasAnd ? " and " : separator) + iterator.next().toString(), letterCase); } final StringBuilder s = new StringBuilder(); for (final T element : printableListElements) { final String elementString = toCase(element.toString(), letterCase); s.append(elementString).append(separator); } try { // Delete the extra comma at the end of the last element in the list. s.delete(s.length() - separator.length(), s.length()); if (hasAnd && s.lastIndexOf(separator) >= 0) { // Insert the word 'and' between the last two elements in the list, // after the last comma. s.insert(s.lastIndexOf(separator) + 1, "and "); } } catch (final StringIndexOutOfBoundsException ignored) { } return s.toString(); }
From source file:com.rockagen.commons.util.CommUtil.java
/** * Array to a comma-delimited string// w w w . jav a2 s.c om * * @param src value * @return string */ public static String toCommaDelimitedString(String[] src) { StringBuilder sb = new StringBuilder(); for (String str : src) { sb.append(str); sb.append(","); } sb.deleteCharAt(sb.lastIndexOf(",")); return sb.toString(); }
From source file:org.jasig.ssp.dao.external.ExternalCourseDao.java
@SuppressWarnings("unchecked") public List<ExternalCourse> search(SearchExternalCourseTO form) { //Performance kludge, we are going to cache the unbounded search result if (form.isUnbounded()) { if (ExternalCourseDao.courseCache.isEmpty() || isCacheExpired()) { flushAndLoadCache();// www .j a v a 2s . c o m } return ExternalCourseDao.courseCache; } //End kludge Query hqlQuery = createHqlQuery(buildCourseSearchQuery(form)); buildCourseSearchParamList(form, hqlQuery); List<ExternalCourse> result = hqlQuery.list(); for (ExternalCourse externalCourse : result) { List<String> tags = getTagsForCourse(externalCourse.getCode()); StringBuilder tagBuilder = new StringBuilder(); for (String tagg : tags) { tagBuilder.append(tagg + ","); } if (tagBuilder.length() > 0) { tagBuilder.deleteCharAt(tagBuilder.lastIndexOf(",")); } externalCourse.setPivotedTags(tagBuilder.toString()); } return result; }
From source file:org.codice.alliance.transformer.nitf.gmti.NitfGmtiTransformer.java
private String formatTargetLocation(Metacard metacard) { Attribute locationAttribute = metacard .getAttribute(IndexedMtirpbAttribute.INDEXED_TARGET_LOCATION.getAttributeDescriptor().getName()); if (locationAttribute != null) { StringBuilder stringBuilder = new StringBuilder("MULTIPOINT ("); locationAttribute.getValues().stream().forEach(value -> { parseLocation(stringBuilder, value.toString()); stringBuilder.append(","); });//from www . j av a2 s . c o m stringBuilder.deleteCharAt(stringBuilder.lastIndexOf(",")); stringBuilder.append(")"); return stringBuilder.toString(); } return null; }
From source file:org.egov.ptis.web.controller.transactions.notice.RecoveryNoticesController.java
@RequestMapping(value = "/form", method = RequestMethod.POST) public String generateNotices(@Valid @ModelAttribute final NoticeRequest noticeRequest, final Model model, final BindingResult errors) { validate(noticeRequest, errors);/* w w w . j a v a 2s . co m*/ if (errors.hasErrors()) { model.addAttribute(NOTICE_REQUEST, noticeRequest); populateDropdowns(model, noticeRequest); return RECOVERY_FORM; } else { Long jobNumber = recoveryNoticeService.getLatestJobNumber(); jobNumber = jobNumber == null ? 0l : jobNumber + 1; final List<String> assessmentNumbers = recoveryNoticeService.generateRecoveryNotices(noticeRequest); if (assessmentNumbers.isEmpty()) { model.addAttribute(NOTICE_REQUEST, noticeRequest); populateDropdowns(model, noticeRequest); errors.reject("record.not.found", "record.not.found"); return RECOVERY_FORM; } final JobDetailImpl jobDetail = (JobDetailImpl) beanProvider.getBean("recoveryNoticeJobDetail"); final Scheduler scheduler = (Scheduler) beanProvider.getBean("recoveryNoticeScheduler"); try { jobDetail.setName(ApplicationThreadLocals.getTenantID().concat("_") .concat(PTIS_RECOVERY_NOTICES_JOB.concat(jobNumber.toString()))); final StringBuilder assessmentNoStr = new StringBuilder(); for (final String assessmentNo : assessmentNumbers) assessmentNoStr.append(assessmentNo).append(", "); assessmentNoStr.deleteCharAt(assessmentNoStr.lastIndexOf(", ")); jobDetail.getJobDataMap().remove(ASSESSMENT_NUMBERS); jobDetail.getJobDataMap().remove(NOTICE_TYPE); jobDetail.getJobDataMap().put(ASSESSMENT_NUMBERS, assessmentNoStr.toString()); jobDetail.getJobDataMap().put(NOTICE_TYPE, noticeRequest.getNoticeType()); final SimpleTriggerImpl trigger = new SimpleTriggerImpl(); trigger.setName(ApplicationThreadLocals.getTenantID().concat("_") .concat(RECOVERY_NOTICES_TRIGGER.concat(jobNumber.toString()))); trigger.setStartTime(new Date(System.currentTimeMillis() + 100000)); trigger.setMisfireInstruction(SimpleTrigger.MISFIRE_INSTRUCTION_FIRE_NOW); scheduler.start(); scheduler.scheduleJob(jobDetail, trigger); } catch (final SchedulerException e) { throw new ApplicationRuntimeException(e.getMessage(), e); } } return RECOVERY_ACK; }
From source file:hydrograph.ui.engine.ui.converter.impl.JoinComponentUiConverter.java
private String getKeyNames(TypeKeyFields typeKeyFields) { StringBuilder joinKey = new StringBuilder(); if (typeKeyFields != null && !typeKeyFields.getField().isEmpty()) { for (TypeFieldName typeFieldName : typeKeyFields.getField()) { joinKey.append(typeFieldName.getName()).append(","); }//ww w . j ava2s . co m } if (joinKey.lastIndexOf(",") != -1) joinKey = joinKey.deleteCharAt(joinKey.lastIndexOf(",")); return joinKey.toString(); }
From source file:net.duckling.ddl.service.resource.dao.TagItemDAOImpl.java
@Override public int removeItems(int tid, int tgid, List<Integer> rids) { if (null == rids || rids.isEmpty()) { return 0; }//from w ww . j ava 2s . c o m StringBuilder sb = new StringBuilder(); sb.append(" where tid=" + tid + " and tgid=" + tgid + " and rid in("); for (int rid : rids) { sb.append(rid + ","); } sb.replace(sb.lastIndexOf(","), sb.length(), ")"); return this.getJdbcTemplate().update(SQL_DELETE + sb.toString()); }
From source file:hydrograph.ui.engine.ui.converter.impl.LookupUiConverter.java
private String getKeyNames(TypeKeyFields typeKeyFields) { StringBuilder lookupKey = new StringBuilder(""); if (typeKeyFields != null && !typeKeyFields.getField().isEmpty()) { for (TypeFieldName typeFieldName : typeKeyFields.getField()) { lookupKey.append(typeFieldName.getName()).append(","); }// ww w .j av a 2 s . c o m } if (lookupKey.lastIndexOf(",") != -1) lookupKey = lookupKey.deleteCharAt(lookupKey.lastIndexOf(",")); return lookupKey.toString(); }
From source file:com.raja.knowme.FragmentProfile.java
private void setUIData(int count) { mHeaderSwitcher.setText(mProfileDetails.get(count).getHeader()); StringBuilder sb = new StringBuilder(); for (int counter = 0; counter < mProfileDetails.get(count).getDetailsData().size(); counter++) sb.insert(sb.lastIndexOf(sb.toString()), mProfileDetails.get(count).getDetailsData().get(counter) + "\n\n"); mBodySwitcher.setText(sb.toString()); }
From source file:com.raja.knowme.FragmentTestimonials.java
private void setUIData(int count) { mHeaderSwitcher.setText(mTestimonialsDetails.get(count).getHeader()); StringBuilder sb = new StringBuilder(); for (int counter = 0; counter < mTestimonialsDetails.get(count).getDetailsData().size(); counter++) sb.insert(sb.lastIndexOf(sb.toString()), mTestimonialsDetails.get(count).getDetailsData().get(counter) + "\n\n"); mBodySwitcher.setText(sb.toString()); }