List of usage examples for org.apache.commons.lang3 StringUtils left
public static String left(final String str, final int len)
Gets the leftmost len characters of a String.
If len characters are not available, or the String is null , the String will be returned without an exception.
From source file:com.sonicle.webtop.core.bol.OSysLog.java
@Override public void setUserAgent(String userAgent) { super.setUserAgent(StringUtils.left(userAgent, 512)); }
From source file:com.sonicle.webtop.core.bol.OSysLog.java
@Override public void setData(String data) { super.setData(StringUtils.left(data, 255)); }
From source file:com.bellman.bible.service.common.TitleSplitter.java
/** * Shorten camel case words uniformly e.g. StrongsRealGreek -> StReGr * Used to create short action bar text for document names * /* w w w .j a va2 s . c o m*/ * @param text Text to shorten * @param maxLength Max length of final string * @return Shortened text */ public String shorten(String text, int maxLength) { if (text == null) { return ""; } if (text.length() <= maxLength) { return text; } // take characters from the end of each part until required length obtained String[] parts = text.split("(?<=[a-z])(?=[A-Z0-9 ])"); int numParts = parts.length; if (numParts == 1) { return text.substring(0, maxLength); } // basicLength will be a bit short if the length of all parts is not going to be the same int basicSplitLength = maxLength / numParts; int remaining = maxLength % numParts; // add remaining to end parts because they are more specific int startToAddRemainingFrom = numParts - remaining; StringBuilder result = new StringBuilder(); for (int i = 0; i < parts.length; i++) { int partLen = basicSplitLength; if (i >= startToAddRemainingFrom) { partLen++; } result.append(StringUtils.left(parts[i], partLen)); } return result.toString(); }
From source file:com.bellman.bible.service.device.ProgressNotificationManager.java
public void initialise() { Log.i(TAG, "Initializing"); workListener = new WorkListener() { @Override/*from w w w . j a va 2s .c o m*/ public void workProgressed(WorkEvent ev) { final Progress prog = ev.getJob(); final int done = prog.getWork(); // updating notifications is really slow so we only update the notification manager every 5% if (prog.isFinished() || done % 5 == 0) { // compose a descriptive string showing job name and current section if relevant String status = StringUtils.left(prog.getJobName(), 50) + SharedConstants.LINE_SEPARATOR; if (!StringUtils.isEmpty(prog.getSectionName()) && !prog.getSectionName().equalsIgnoreCase(prog.getJobName())) { status += prog.getSectionName(); } // update notification view final Notification notification = findOrCreateNotification(prog); notification.contentView.setProgressBar(R.id.status_progress, 100, done, false); notification.contentView.setTextViewText(R.id.status_text, status); // this next line is REALLY slow and is the reason we only update the notification manager every 5% // inform the progress bar of updates in progress androidNotificationManager.notify(prog.hashCode(), notification); if (prog.isFinished()) { finished(prog); } } } @Override public void workStateChanged(WorkEvent ev) { Log.d(TAG, "WorkState changed"); // we don't care about these events } }; JobManager.addWorkListener(workListener); Log.d(TAG, "Finished Initializing"); }
From source file:com.hypersocket.client.NetworkResource.java
@Override public String getServiceDescription() { return String.format("%-17s %5d", StringUtils.left(hostname, 17), port); }
From source file:com.bellman.bible.service.common.TitleSplitter.java
private String[] checkMaximumPartLength(String[] parts, int maximumLength) { for (int i = 0; i < parts.length; i++) { if (parts[i].length() > maximumLength) { parts[i] = StringUtils.left(parts[i], maximumLength); }//from w ww. j a v a 2 s . com } return parts; }
From source file:com.adobe.acs.commons.wcm.comparisons.impl.PageCompareDataLineImpl.java
@Override public String getValueStringShort() { return StringUtils.left(value, LEN); }
From source file:com.sonicle.webtop.tasks.bol.js.JsPletTasks.java
public JsPletTasks(ShareRootCategory root, ShareFolderCategory folder, CategoryPropSet pset, TaskLookup task, DateTimeZone profileTz) {/*from w ww . ja v a 2 s.c o m*/ final Category category = folder.getCategory(); taskId = task.getTaskId(); categoryId = task.getCategoryId(); categoryName = category.getName(); categoryColor = category.getColor(); subject = task.getSubject(); description = StringUtils.left(task.getDescription(), 250); dueDate = DateTimeUtils.printYmdHmsWithZone(task.getDueDate(), profileTz); _owner = (root instanceof MyShareRootCategory) ? "" : root.getDescription(); _frights = folder.getPerms().toString(); _erights = folder.getElementsPerms().toString(); }
From source file:com.zergiu.tvman.init.SQLFileImporter.java
/** * @param line//from ww w . j a va 2s .c om * @return */ private String trimLine(String line) { line = line.trim(); int index = StringUtils.indexOfAny(line, "--", "//"); if (index >= 0) { line = StringUtils.left(line, index); } return line; }
From source file:com.sonicle.webtop.core.versioning.SqlScript.java
private void readFile(InputStreamReader readable) throws IOException { this.statements = new ArrayList<>(); String lines[] = null;// w w w . j ava 2 s . c om StringBuilder sbsql = null; Scanner s = new Scanner(readable); s.useDelimiter("(;( )?(\r)?\n)"); while (s.hasNext()) { String block = s.next(); block = StringUtils.replace(block, "\r", ""); if (!StringUtils.isEmpty(block)) { // Remove remaining ; at the end of the block (only if this block is the last one) if (!s.hasNext() && StringUtils.endsWith(block, ";")) block = StringUtils.left(block, block.length() - 1); sbsql = new StringBuilder(); lines = StringUtils.split(block, "\n"); for (String line : lines) { if (CommentLine.matches(line)) continue; sbsql.append(StringUtils.trim(line)); sbsql.append(" "); } if (sbsql.length() > 0) statements.add(sbsql.toString()); } } }