List of usage examples for java.lang StringBuilder deleteCharAt
@Override public StringBuilder deleteCharAt(int index)
From source file:fastcall.FastCallSNP.java
public String getGenotype(int[] cnt) { int n = cnt.length * (cnt.length + 1) / 2; int[] likelihood = new int[n]; int sum = 0;/* www. j a va 2 s .co m*/ for (int i = 0; i < cnt.length; i++) sum += cnt[i]; if (sum == 0) return "./."; else if (sum > this.maxFactorial) { double portion = (double) this.maxFactorial / sum; for (int i = 0; i < cnt.length; i++) { cnt[i] = (int) (cnt[i] * portion); } sum = this.maxFactorial; } double coe = this.factorialMap.get(sum); for (int i = 0; i < cnt.length; i++) coe = coe / this.factorialMap.get(cnt[i]); double max = Double.MAX_VALUE; int a1 = 0; int a2 = 0; for (int i = 0; i < cnt.length; i++) { for (int j = i; j < cnt.length; j++) { int index = (j * (j + 1) / 2) + i; double value = Double.MAX_VALUE; if (i == j) { value = -Math.log10(coe * Math.pow((1 - 0.75 * this.sequencingErrorRate), cnt[i]) * Math.pow(this.sequencingErrorRate / 4, (sum - cnt[i]))); } else { value = -Math.log10(coe * Math.pow((0.5 - this.sequencingErrorRate / 4), cnt[i] + cnt[j]) * Math.pow(this.sequencingErrorRate / 4, (sum - cnt[i] - cnt[j]))); } if (value < max) { max = value; a1 = i; a2 = j; } likelihood[index] = (int) Math.round(value); } } StringBuilder sb = new StringBuilder(); sb.append(a1).append("/").append(a2).append(":"); for (int i = 0; i < cnt.length; i++) sb.append(cnt[i]).append(","); sb.deleteCharAt(sb.length() - 1); sb.append(":"); for (int i = 0; i < likelihood.length; i++) sb.append(likelihood[i]).append(","); sb.deleteCharAt(sb.length() - 1); return sb.toString(); }
From source file:org.jasig.portlet.emailpreview.dao.exchange.ExchangeAccountDaoImpl.java
private String getRecipients(ArrayOfRecipientsType addrs) { StringBuilder str = new StringBuilder(); if (addrs != null) { for (EmailAddressType addr : addrs.getMailboxes()) { str.append(formatEmailAddress(addr)); str.append("; "); }/*from ww w. ja v a2s . c o m*/ // Delete the trailing ; space str.deleteCharAt(str.length() - 1); str.deleteCharAt(str.length() - 1); } return str.toString(); }
From source file:com.cloudera.oryx.common.math.OpenMapRealVector.java
@Override public String toString() { StringBuilder sb = new StringBuilder(); Iterator<Entry> inOrderIter = sparseInOrderIterator(); while (inOrderIter.hasNext()) { Entry e = inOrderIter.next();/*from w ww .java2s . c o m*/ sb.append(e.getIndex()).append(':').append(e.getValue()).append(' '); } sb.deleteCharAt(sb.length() - 1); return sb.toString(); }
From source file:istata.service.StataService.java
/** * produce a list with possible sidebar suggestions for the current context * /*from ww w . j ava2 s .c om*/ * @param filter * @param pos * @param from * @param to * @return */ public List<ContentLine> suggest(String filter, int pos, int from, int to) { LinkedHashSet<ContentLine> res = new LinkedHashSet<ContentLine>(); ArrayList<ContentLine> rescmd = new ArrayList<ContentLine>(); { int i = 0; for (ContentLine cl : cmdRepository.findAll()) { if (cl.getContent().startsWith(filter)) { ContentLine srl = new ContentLine(); Map<String, Object> model = new HashMap<String, Object>(); model.put("cmd", cl); model.put("from", from); model.put("to", to); String text = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "items/cmd.vm", "UTF-8", model); srl.setContent(text); srl.setLine(i++); rescmd.add(srl); } } } Collections.reverse(rescmd); res.addAll(rescmd.subList(0, Math.min(10, rescmd.size()))); List<ContentLine> out = new ArrayList<ContentLine>(); try { IStata stata = stataFactory.getInstance(); /* * get files */ Collection<ContentLine> filesNames = filteredFiles(filter, pos, from, to); res.addAll(filesNames); /* * get VARS, should be a mothod call probably */ // current token StringBuilder token = new StringBuilder(""); StringBuilder rest = new StringBuilder(filter); int p = (pos == -1 || pos > filter.length()) ? filter.length() : pos; char ch = 'x'; while (p > 0 && (CharUtils.isAsciiAlphanumeric(ch = filter.charAt(p - 1)) || ch == '_')) { token.insert(0, ch); rest.deleteCharAt(p - 1); p--; } // remove rest of potential token while (rest.length() > 0 && p > 0 && p < rest.length() && (CharUtils.isAsciiAlphanumeric(rest.charAt(p)) || rest.charAt(p) == '_')) { rest.deleteCharAt(p); } String t = token.toString(); List<StataVar> list = new ArrayList<StataVar>(); List<StataVar> listfull = stata.getVars("", false); if (t.length() > 0) { for (StataVar sv : listfull) { if (sv.getName().startsWith(t)) { list.add(sv); } } } else { list = listfull; } for (int i = 0; i < list.size(); i++) { ContentLine srl = new ContentLine(); srl.setLine(i + 100); String vname = list.get(i).getName(); String cl = new StringBuilder(rest).insert(p, " ").insert(p, vname).toString(); try { String cc = URLEncoder.encode(cl, "UTF-8"); Map<String, Object> model = new HashMap<String, Object>(); model.put("var", vname); model.put("repl", cc); model.put("focuspos", p + 1 + vname.length()); model.put("from", from); model.put("to", to); String text = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "items/var.vm", "UTF-8", model); srl.setContent(text); res.add(srl); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } catch (StataNotRunningException e) { ContentLine srl = new ContentLine(); srl.setLine(1); srl.setContent( "<div class='list-group-item sidebaritem error' >" + "Stata not running, you can try to start " + "an instance by clicking " + "<a target='_blank' href='/start'>here</a>" + "</div>"); out.add(srl); } catch (StataBusyException e1) { ContentLine srl = new ContentLine(); srl.setLine(1); srl.setContent("<div class='list-group-item sidebaritem error' >" + "Stata appears to by busy or not running, you can try to " + "start a new instance by clicking " + "<a target='_blank' href='/start'>here</a> " + "or wait for the current job to complete</div>"); out.add(srl); } out.addAll(res); return out; }
From source file:io.wcm.caravan.io.http.request.RequestTemplate.java
public String queryLine() { if (queries.isEmpty()) { return ""; }/*from ww w . j av a 2 s .c o m*/ StringBuilder queryBuilder = new StringBuilder(); for (String field : queries.keySet()) { for (String value : ObjectUtils.defaultIfNull(queries.get(field), Collections.<String>emptyList())) { queryBuilder.append('&'); queryBuilder.append(field); if (value != null) { queryBuilder.append('='); if (!value.isEmpty()) { queryBuilder.append(value); } } } } queryBuilder.deleteCharAt(0); return queryBuilder.insert(0, '?').toString(); }
From source file:org.wso2.carbon.apimgt.keymgt.service.APIKeyMgtSubscriberService.java
/** * Register an OAuth application for the given user * * @param userId//from ww w.j a v a 2 s. com * @param applicationName * @param callbackUrl * @return * @throws APIKeyMgtException * @throws APIManagementException * @throws IdentityException */ public OAuthApplicationInfo updateOAuthApplication(String userId, String applicationName, String callbackUrl, String consumerKey, String[] grantTypes) throws APIKeyMgtException, APIManagementException, IdentityException { if (userId == null || userId.isEmpty()) { return null; } String tenantDomain = MultitenantUtils.getTenantDomain(userId); String baseUser = CarbonContext.getThreadLocalCarbonContext().getUsername(); String userName = MultitenantUtils.getTenantAwareUsername(userId); String userNameForSP = userName; if (log.isDebugEnabled()) { StringBuilder message = new StringBuilder(); message.append("Updating OAuthApplication for ").append(userId).append(" with details : "); if (consumerKey != null) { message.append(" consumerKey = ").append(consumerKey); } if (callbackUrl != null) { message.append(", callbackUrl = ").append(callbackUrl); } if (applicationName != null) { message.append(", applicationName = ").append(applicationName); } if (grantTypes != null && grantTypes.length > 0) { message.append(", grant Types = "); for (String grantType : grantTypes) { message.append(grantType).append(" "); } } log.debug(message.toString()); } PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true); // Acting as the provided user. When creating Service Provider/OAuth App, // username is fetched from CarbonContext PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(userName); try { // Replace domain separator by "_" if user is coming from a secondary userstore. String domain = UserCoreUtil.extractDomainFromName(userNameForSP); if (domain != null && !domain.isEmpty() && !UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME.equals(domain)) { userNameForSP = userNameForSP.replace(UserCoreConstants.DOMAIN_SEPARATOR, "_"); } if (applicationName != null && !applicationName.isEmpty()) { // Append the username before Application name to make application name unique across two users. applicationName = APIUtil.replaceEmailDomain(userNameForSP) + "_" + applicationName; log.debug("Application Name has changed, hence updating Service Provider Name.."); // Get ServiceProvider Name by consumer Key. ApplicationManagementService appMgtService = ApplicationManagementService.getInstance(); String appName = appMgtService.getServiceProviderNameByClientId(consumerKey, "oauth2", tenantDomain); ServiceProvider serviceProvider = appMgtService.getApplicationExcludingFileBasedSPs(appName, tenantDomain); if (serviceProvider != null && !appName.equals(applicationName)) { serviceProvider.setApplicationName(applicationName); serviceProvider.setDescription("Service Provider for application " + applicationName); appMgtService.updateApplication(serviceProvider, tenantDomain, userName); log.debug("Service Provider Name Updated to : " + applicationName); } } OAuthAdminService oAuthAdminService = new OAuthAdminService(); OAuthConsumerAppDTO oAuthConsumerAppDTO = oAuthAdminService.getOAuthApplicationData(consumerKey); if (oAuthConsumerAppDTO != null) { // TODO: Make sure that App is only updated by the user who created it. //if(userName.equals(oAuthConsumerAppDTO.getUsername())) if (callbackUrl != null && !callbackUrl.isEmpty()) { oAuthConsumerAppDTO.setCallbackUrl(callbackUrl); log.debug("CallbackURL is set to : " + callbackUrl); } oAuthConsumerAppDTO.setOauthConsumerKey(consumerKey); if (applicationName != null && !applicationName.isEmpty()) { oAuthConsumerAppDTO.setApplicationName(applicationName); log.debug("Name of the OAuthApplication is set to : " + applicationName); } if (grantTypes != null && grantTypes.length > 0) { StringBuilder builder = new StringBuilder(); for (String grantType : grantTypes) { builder.append(grantType + " "); } builder.deleteCharAt(builder.length() - 1); oAuthConsumerAppDTO.setGrantTypes(builder.toString()); } else { //update the grant type with respect to callback url String[] allowedGrantTypes = oAuthAdminService.getAllowedGrantTypes(); StringBuilder grantTypeString = new StringBuilder(); for (String grantType : allowedGrantTypes) { if (callbackUrl == null || callbackUrl.isEmpty()) { if ("authorization_code".equals(grantType) || "implicit".equals(grantType)) { continue; } } grantTypeString.append(grantType).append(" "); } oAuthConsumerAppDTO.setGrantTypes(grantTypeString.toString().trim()); } oAuthAdminService.updateConsumerApplication(oAuthConsumerAppDTO); log.debug("Updated the OAuthApplication..."); oAuthConsumerAppDTO = oAuthAdminService.getOAuthApplicationData(consumerKey); OAuthApplicationInfo oAuthApplicationInfo = createOAuthAppInfoFromDTO(oAuthConsumerAppDTO); return oAuthApplicationInfo; } } catch (IdentityApplicationManagementException e) { APIUtil.handleException("Error occurred while creating ServiceProvider for app " + applicationName, e); } catch (Exception e) { APIUtil.handleException("Error occurred while creating OAuthApp " + applicationName, e); } finally { PrivilegedCarbonContext.getThreadLocalCarbonContext().endTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(baseUser); } return null; }
From source file:com.ace.console.service.sys.impl.ResourceServiceImpl.java
/** * ? ? :?//w ww.j a v a 2 s .c om * * @param resource * @return */ public String findActualResourceIdentity(Resources resource) { if (resource == null) { return null; } StringBuilder s = new StringBuilder(resource.getIdentity()); boolean hasResourceIdentity = !StringUtils.isEmpty(resource.getIdentity()); Resources parent = selectById(resource.getParentId()); while (parent != null) { if (!StringUtils.isEmpty(parent.getIdentity())) { s.insert(0, parent.getIdentity() + ":"); hasResourceIdentity = true; } parent = selectById(parent.getParentId()); } // ? if (!hasResourceIdentity) { return ""; } //?: ?? int length = s.length(); if (length > 0 && s.lastIndexOf(":") == length - 1) { s.deleteCharAt(length - 1); } //? ?* /** boolean hasChildren = false; for (Resources r : resourcesMapper.getList()) { if (resource.getId().equals(r.getParentId())) { hasChildren = true; break; } } **/ if (resource.isHasChildren()) { s.append(":*"); } return s.toString(); }
From source file:com.haulmont.cuba.web.app.folders.CubaFoldersPane.java
protected String idsToStr(List<UUID> uuids) { if (uuids == null) return ""; StringBuilder sb = new StringBuilder(); for (UUID uuid : uuids) { sb.append(":").append(uuid.toString()); }/*w ww . j ava 2s . c om*/ if (sb.length() != 0) { sb.deleteCharAt(0); } return sb.toString(); }
From source file:com.ace.erp.service.sys.impl.ResourceServiceImpl.java
/** * ? ? :?/*w w w. j av a 2 s . c o m*/ * * @param resource * @return */ public String findActualResourceIdentity(Resource resource) { if (resource == null) { return null; } StringBuilder s = new StringBuilder(resource.getIdentity()); boolean hasResourceIdentity = !StringUtils.isEmpty(resource.getIdentity()); Resource parent = resourceMapper.getOne(resource.getParentId()); while (parent != null) { if (!StringUtils.isEmpty(parent.getIdentity())) { s.insert(0, parent.getIdentity() + ":"); hasResourceIdentity = true; } parent = resourceMapper.getOne(parent.getParentId()); } // ? if (!hasResourceIdentity) { return ""; } //?: ?? int length = s.length(); if (length > 0 && s.lastIndexOf(":") == length - 1) { s.deleteCharAt(length - 1); } //? ?* /** boolean hasChildren = false; for (Resource r : resourceMapper.getList()) { if (resource.getId().equals(r.getParentId())) { hasChildren = true; break; } } **/ if (resource.isHasChildren()) { s.append(":*"); } return s.toString(); }