List of usage examples for java.lang CharSequence length
int length();
From source file:com.sindicetech.siren.search.spans.TermSpanQuery.java
@Override public String toString(final String field) { final StringBuilder builder = new StringBuilder(); final CharSequence text = term.text(); if (text.length() != 0) { builder.append("'").append(text).append("'"); }//from w w w . j ava 2 s . c om builder.append(ToStringUtils.boost(this.getBoost())); return this.wrapToStringWithDatatype(builder).toString(); }
From source file:com.pidoco.juri.JURI.java
/** * <pre>//from w w w . java2 s.c om * "".addRawPath("") -> "" * "/".addRawPath("") -> "/" * "".addRawPath("/") -> "/" * "a".addRawPath("") -> "a/" * "a".addRawPath("b") -> "a/b" * "/".addRawPath("/") -> "/" * </pre> */ public static String concatRawPaths(CharSequence left, CharSequence right) { boolean needsSeparator = false; boolean rightStartsWithSlash = StringUtils.startsWith(right, "/"); int rightStart = 0; if (left.length() > 0) { if (StringUtils.endsWith(left, "/")) { if (rightStartsWithSlash) { rightStart = 1; } } else { if (!rightStartsWithSlash) { needsSeparator = true; } } } return left + (needsSeparator ? "/" : "") + right.subSequence(rightStart, right.length()); }
From source file:net.sf.jabb.util.text.KeywordMatcher.java
/** * Do the matching test, find out which keywords can be matched, and how many occurrences of each * keyword can be found.<br>//from www. j a v a 2s .co m * ????? * * @param text the text string to be tested<br>? * @return For all the keywords that can be found in the text, return their attachments (as the Key * in the Map) and occurrences count (as the Value in the Map).<br> * ??attachmentMapKey?MapValue */ public Map<Object, MutableInt> match(CharSequence text) { Map<Object, MutableInt> result = null; if (text != null && text.length() > 0) { int i = 0; while (i < text.length()) { Object o = matcher.match(text, i); if (o == null) { i++; } else { KeywordDefinition keyword = (KeywordDefinition) o; String word = keyword.getKeyword(); Object attachment = keyword.getAttachement(); i += word.length(); if (result == null) { result = new HashMap<Object, MutableInt>(); } if (result.containsKey(attachment)) { result.get(attachment).increment(); } else { result.put(attachment, new MutableInt(1)); } } } } return result; }
From source file:cn.remex.core.util.StringUtils.java
/** * ?????//from ww w . j av a 2s . c om * Check whether the given CharSequence contains any whitespace characters. * @param str the CharSequence to check (may be <code>null</code>) ? * @return <code>true</code> if the CharSequence is not empty and * contains at least 1 whitespace character * @see java.lang.Character#isWhitespace */ public static boolean containsWhitespace(final CharSequence str) { if (!hasLength(str)) { return false; } int strLen = str.length(); for (int i = 0; i < strLen; i++) { if (Character.isWhitespace(str.charAt(i))) { return true; } } return false; }
From source file:mitm.common.util.SizeLimitedWriter.java
@Override public Writer append(CharSequence csq) throws IOException { if (!isLimitReached(csq != null ? csq.length() : 0)) { delegate.append(csq);//from ww w .ja v a 2s. c om } return this; }
From source file:com.sindicetech.siren.search.node.NodeTermQuery.java
/** * Prints a user-readable version of this query. * <p>/* w w w. ja v a2 s . c o m*/ * The term is wrapped in simple quotes, so that any special characters it * may contains are disabled. See ProtectedQueryNode in siren-qparser. */ @Override public String toString(final String field) { final StringBuilder builder = new StringBuilder(); final CharSequence text = term.text(); if (text.length() != 0) { builder.append("'").append(text).append("'"); } builder.append(ToStringUtils.boost(this.getBoost())); return this.wrapToStringWithDatatype(builder).toString(); }
From source file:com.cloudera.oryx.kmeans.serving.web.AssignServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { CharSequence pathInfo = request.getPathInfo(); if (pathInfo == null) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No path"); return;//from w ww .j ava2 s . c om } String line = pathInfo.subSequence(1, pathInfo.length()).toString(); Generation generation = getGenerationManager().getCurrentGeneration(); if (generation == null) { response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "API method unavailable until model has been built and loaded"); return; } RealVector vec = generation.toVector(DelimitedDataUtils.decode(line)); if (vec == null) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Wrong column count"); return; } int assignment = DistanceToNearestServlet.findClosest(generation, vec).getClosestCenterId(); response.getWriter().write(Integer.toString(assignment)); }
From source file:com.acceleratedio.pac_n_zoom.FindTagsActivity.java
public void onClick(View vw) { if (vw.getId() == R.id.ed_tgs) dsply_tags();/*from w w w . ja v a2 s . c o m*/ else { Button btn_vw = (Button) vw; CharSequence btn_sqn = btn_vw.getText(); final StringBuilder strBldr = new StringBuilder(btn_sqn.length()); strBldr.append(btn_sqn); req_str += strBldr.toString(); Intent intent = new Intent(FindTagsActivity.this, PickAnmActivity.class); intent.putExtra("requestString", req_str); startActivity(intent); } }
From source file:com.cyberway.issue.extractor.RegexpJSLinkExtractor.java
protected boolean findNextLink() { if (strings == null) { strings = JAVASCRIPT_STRING_EXTRACTOR.matcher(sourceContent); }/* w ww . j av a2s . c o m*/ while (strings != null) { while (strings.find()) { CharSequence subsequence = sourceContent.subSequence(strings.start(2), strings.end(2)); Matcher uri = STRING_URI_DETECTOR.matcher(subsequence); if ((subsequence.length() <= UURI.MAX_URL_LENGTH) && uri.matches()) { String string = uri.group(); string = TextUtils.replaceAll(ESCAPED_AMP, string, AMP); try { Link link = new Link(source, UURIFactory.getInstance(source, string), Link.JS_MISC, Link.SPECULATIVE_HOP); next.add(link); return true; } catch (URIException e) { extractErrorListener.noteExtractError(e, source, string); } } else { // push current range matcherStack.addFirst(strings); // start looking inside string strings = JAVASCRIPT_STRING_EXTRACTOR.matcher(subsequence); } } // continue at enclosing range, if available strings = (Matcher) (matcherStack.isEmpty() ? null : matcherStack.removeFirst()); } return false; }
From source file:com.cloudera.oryx.kmeans.serving.web.DistanceToNearestServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { CharSequence pathInfo = request.getPathInfo(); if (pathInfo == null) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No path"); return;//from w w w . ja v a 2 s . c o m } String line = pathInfo.subSequence(1, pathInfo.length()).toString(); Generation generation = getGenerationManager().getCurrentGeneration(); if (generation == null) { response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "API method unavailable until model has been built and loaded"); return; } String[] tokens = DelimitedDataUtils.decode(line); RealVector vector = generation.toVector(tokens); if (vector == null) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Wrong column count"); return; } double distance = findClosest(generation, vector).getSquaredDistance(); response.getWriter().write(Double.toString(distance)); }