List of usage examples for java.lang StringBuilder lastIndexOf
@Override public int lastIndexOf(String str)
From source file:txyd.util.StringUtils.java
/** * ?/*from w ww .j a v a 2 s . c o m*/ * * @param cs * @param separator * @return */ public static <T> String getStrByArrayAndSeparator(T[] cs, final String separator) { if (cs == null || cs.length == 0) { return ""; } StringBuilder stringBuilder = new StringBuilder(); for (Object item : cs) { stringBuilder.append(item.toString() + separator); } return stringBuilder.substring(0, stringBuilder.lastIndexOf(separator)).toString(); }
From source file:org.wso2.carbon.analytics.eventsink.template.deployer.internal.util.EventSinkTemplateDeployerHelper.java
private static void addArtifactIdToStreamIdsMap(Registry registry, String artifactId, List<String> streamIds) throws RegistryException { Resource artIdToStreamIdsMapResource = registry.newResource(); StringBuilder idListBuilder = new StringBuilder(); for (String streamId : streamIds) { idListBuilder.append(streamId).append(EventSinkTemplateDeployerConstants.SEPARATOR); }//from ww w . jav a 2 s.c om if (idListBuilder.length() - 1 == idListBuilder.lastIndexOf(EventSinkTemplateDeployerConstants.SEPARATOR)) { idListBuilder.deleteCharAt(idListBuilder.length() - 1); } artIdToStreamIdsMapResource.setMediaType("text/plain"); artIdToStreamIdsMapResource.setContent(idListBuilder.toString()); String artIdToStreamIdsMapResourcePath = EventSinkTemplateDeployerConstants.ARTIFACT_ID_TO_STREAM_IDS_COLLECTION_PATH + RegistryConstants.PATH_SEPARATOR + artifactId; registry.put(artIdToStreamIdsMapResourcePath, artIdToStreamIdsMapResource); }
From source file:com.filemanager.free.utils.MainActivityHelper.java
public static boolean validateFileName(HFile file, boolean isDir) { StringBuilder builder = new StringBuilder(file.getPath()); String newName = builder.substring(builder.lastIndexOf("/") + 1, builder.length()); if (newName.contains(CONSTANT_ASTERISK) || newName.contains(CONSTANT_BACKWARD_SLASH) || newName.contains(CONSTANT_COLON) || newName.contains(CONSTANT_FOREWARD_SLASH) || newName.contains(CONSTANT_GREATER_THAN) || newName.contains(CONSTANT_LESS_THAN) || newName.contains(CONSTANT_QUESTION_MARK) || newName.contains(CONSTANT_QUOTE)) { return false; } else if (isDir) { // new directory name shall not be equal to parent directory name StringBuilder parentPath = new StringBuilder( builder.substring(0, builder.length() - (newName.length() + 1))); String parentName = parentPath.substring(parentPath.lastIndexOf("/") + 1, parentPath.length()); if (newName.equals(parentName)) return false; }/* w w w .j a v a2 s.c om*/ return true; }
From source file:org.structr.rest.servlet.CsvServlet.java
/** * Write list of objects to output/*from w ww . j av a 2 s.c o m*/ * * @param result * @param out * @param propertyView * @throws IOException */ public static void writeCsv(final Result result, final Writer out, final String propertyView) throws IOException { List<GraphObject> list = result.getResults(); boolean headerWritten = false; for (GraphObject obj : list) { // Write column headers if (!headerWritten) { StringBuilder row = new StringBuilder(); for (PropertyKey key : obj.getPropertyKeys(propertyView)) { row.append("\"").append(key.dbName()).append("\"").append(DELIMITER); } // remove last , int pos = row.lastIndexOf(DELIMITER); if (pos >= 0) { row.deleteCharAt(pos); } // append DOS-style line feed as defined in RFC 4180 out.append(row).append("\r\n"); // flush each line out.flush(); headerWritten = true; } StringBuilder row = new StringBuilder(); for (PropertyKey key : obj.getPropertyKeys(propertyView)) { Object value = obj.getProperty(key); row.append("\"").append((value != null ? escapeForCsv(value) : "")).append("\"").append(DELIMITER); } // remove last , row.deleteCharAt(row.lastIndexOf(DELIMITER)); out.append(row).append("\r\n"); // flush each line out.flush(); } }
From source file:org.eclipse.smarthome.documentation.MarkdownProvider.java
/** * Takes channels and parses them to a string list. * * @param channels// w ww. ja v a2 s .c o m * @return */ private static StringBuilder channelsToString(Channels channels) { StringBuilder builder = new StringBuilder(); if (channels == null) { return builder; } for (Channel channel : channels.getChannel()) { builder.append(link(channel.getId(), "#channel-id-" + channel.getTypeId())).append(", "); } // Remove trailing "," builder.deleteCharAt(builder.lastIndexOf(",")); return builder; }
From source file:org.eclipse.smarthome.documentation.MarkdownProvider.java
/** * Takes the channel groups and parses them to a string list. * * @param groups/* ww w . jav a2 s . c o m*/ * @return */ private static StringBuilder channelGroupsToString(ChannelGroups groups) { StringBuilder builder = new StringBuilder(); if (groups == null) { return builder; } for (ChannelGroup group : groups.getChannelGroup()) { builder.append(link(group.getId(), "#channel-group-id-" + group.getTypeId())).append(", "); } // Remove trailing "," builder.deleteCharAt(builder.lastIndexOf(",")); return builder; }
From source file:com.ing.connector.util.WStringUtil.java
public static List<String> splitLine(String input, int splitPosition) { List<String> lines = new ArrayList<String>(); StringBuilder stringBuilder = new StringBuilder(input.trim()); boolean linesRemaining = true; while (linesRemaining) { if (stringBuilder.length() <= splitPosition || stringBuilder.lastIndexOf(" ") < splitPosition) { lines.add(stringBuilder.toString()); linesRemaining = false;//from ww w.j a va 2 s .c om } else { int indexOfSpace = stringBuilder.indexOf(" ", splitPosition); String nextLine = stringBuilder.substring(0, indexOfSpace + 1); lines.add(nextLine); stringBuilder.delete(0, indexOfSpace + 1); } } return lines; }
From source file:org.exoplatform.forum.ForumUtils.java
private static String buildForumLink(String url, String type, String id) { StringBuilder link = new StringBuilder(url); if (!isEmpty(type) && !isEmpty(id)) { if (link.lastIndexOf(SLASH) == (link.length() - 1)) link.append(type);//from w ww . j a va 2s .co m else link.append(SLASH).append(type); if (!id.equals(Utils.FORUM_SERVICE)) link.append(SLASH).append(id); } return link.toString(); }
From source file:be.jacobsvanroy.springsqlunit.util.ScriptUtils.java
private static void appendSeparatorToScriptIfNecessary(StringBuilder scriptBuilder, String separator) { if (separator == null) { return;/*from w w w . j av a 2 s .c om*/ } String trimmed = separator.trim(); if (trimmed.length() == separator.length()) { return; } // separator ends in whitespace, so we might want to see if the script is trying // to end the same way if (scriptBuilder.lastIndexOf(trimmed) == scriptBuilder.length() - trimmed.length()) { scriptBuilder.append(separator.substring(trimmed.length())); } }
From source file:org.jcommon.com.util.JsonUtils.java
public static String toParameter(String[] keys, String[] values) { if (keys == null || values == null) { logger.warn("json key or vlaue is null"); return null; }//from ww w . j a v a 2 s . c om if (keys.length != values.length) { logger.warn("key' length must be same with vlaue"); return null; } StringBuilder sb = new StringBuilder(); try { sb.append("?"); for (int i = 0; i < keys.length; i++) { if (values[i] == null || keys[i] == null) continue; sb.append(CoderUtils.encode(keys[i]) + "=" + CoderUtils.encode(values[i])); sb.append("&"); } if (sb.lastIndexOf("&") == sb.length() - 1) sb.deleteCharAt(sb.length() - 1); } catch (Exception e) { logger.error("", e); } return sb.toString(); }