List of usage examples for java.lang CharSequence length
int length();
From source file:com.cyberway.issue.extractor.RegexpHTMLLinkExtractor.java
/** * @param value//from w ww. j a v a 2 s. c o m * @param context */ protected void processLink(CharSequence value, CharSequence context) { String link = TextUtils.replaceAll(ESCAPED_AMP, value, "&"); if (TextUtils.matches(JAVASCRIPT, link)) { processScriptCode(value.subSequence(11, value.length())); } else { addLinkFromString(link, context, Link.NAVLINK_HOP); } }
From source file:edu.cornell.med.icb.goby.util.SimulateBisulfiteReads.java
protected void process(CharSequence segmentBases, int from, Writer writer) throws IOException { int segmentLength = segmentBases.length(); for (int repeatCount = 0; repeatCount < numRepeats; repeatCount++) { int startReadPosition = choose(0, Math.max(0, segmentBases.length() - 1 - readLength)); boolean matchedReverseStrand = doReverseStrand && doForwardStrand ? random.nextBoolean() : doReverseStrand;//from w w w. ja va 2s . com if (matchedReverseStrand && !doReverseStrand) continue; if (!matchedReverseStrand && !doForwardStrand) continue; final CharSequence selectedReadRegion = segmentBases.subSequence(startReadPosition, startReadPosition + readLength); CharSequence readBases = matchedReverseStrand ? reverseComplement(selectedReadRegion) : selectedReadRegion; MutableString sequenceInitial = new MutableString(); MutableString sequenceTreated = new MutableString(); MutableString log = new MutableString(); IntArrayList mutatedPositions = new IntArrayList(); for (int i = 0; i < readLength; i++) { char base = readBases.charAt(i); // genomic position is zero-based int genomicPosition = matchedReverseStrand ? readLength - (i + 1) + from + startReadPosition : i + startReadPosition + from; sequenceInitial.append(base); if (base == 'C') { boolean isBaseMethylated = random .nextDouble() <= getMethylationRateAtPosition(matchedReverseStrand, genomicPosition); if (isBaseMethylated) { // base is methylated, stays a C on forward or reverse strand if (!bisulfiteTreatment) { // mutate base to G // introduce mutation C -> G base = 'G'; } // bases that are methylated are protected and stay C on the forward strand. They would also // be seen as G on the opposite strand if the sequencing protocol did not respect strandness log.append(bisulfiteTreatment ? "met: " : "mut: "); log.append(genomicPosition + 1); // write 1-based position log.append(' '); log.append("read-index: "); log.append(i + 1); log.append(' '); mutatedPositions.add(genomicPosition); } else { // bases that are not methylated are changed to T through the bisulfite and PCR conversion steps if (bisulfiteTreatment) { base = 'T'; } } } sequenceTreated.append(base); } MutableString coveredPositions = new MutableString(); MutableString qualityScores = new MutableString(); for (int i = 0; i < readLength; i++) { final char c = QualityEncoding.ILLUMINA.phredQualityScoreToAsciiEncoding((byte) 40); qualityScores.append(c); } // zero-based positions covered by the read: IntArrayList readCoveredPositions = new IntArrayList(); for (int i = startReadPosition + from; i < startReadPosition + from + readLength; i++) { // positions are written 1-based coveredPositions.append(i + 1); coveredPositions.append(" "); readCoveredPositions.add(i); } readCoveredPositions.retainAll(mutatedPositions); assert readCoveredPositions.size() == mutatedPositions .size() : "positions mutated or changed must be covered by read."; // System.out.printf("initial: %s%nbis: %s%n", sequenceInitial, sequenceTreated); writer.write(String.format("@%d reference: %s startPosition: %d strand: %s %s %s%n%s%n+%n%s%n", repeatCount, refChoice, startReadPosition, matchedReverseStrand ? "-1" : "+1", log, coveredPositions, complement(sequenceTreated), qualityScores)); } writer.flush(); }
From source file:org.cleverbus.common.Strings.java
/** * Replace all occurrences of one string replaceWith another string. * * @param s//from w ww.j av a 2 s.c o m * The string to process * @param searchFor * The value to search for * @param replaceWith * The value to searchFor replaceWith * @return The resulting string with searchFor replaced with replaceWith */ public static CharSequence replaceAll(CharSequence s, CharSequence searchFor, CharSequence replaceWith) { if (s == null) { return null; } // If searchFor is null or the empty string, then there is nothing to // replace, so returning s is the only option here. if ((searchFor == null) || EMPTY.equals(searchFor)) { return s; } // If replaceWith is null, then the searchFor should be replaced with // nothing, which can be seen as the empty string. if (replaceWith == null) { replaceWith = EMPTY; } String searchString = searchFor.toString(); // Look for first occurrence of searchFor int matchIndex = search(s, searchString, 0); if (matchIndex == -1) { // No replace operation needs to happen return s; } else { // Allocate a AppendingStringBuffer that will hold one replacement // with a // little extra room. int size = s.length(); final int replaceWithLength = replaceWith.length(); final int searchForLength = searchFor.length(); if (replaceWithLength > searchForLength) { size += (replaceWithLength - searchForLength); } final StringBuilder sb = new StringBuilder(size + 16); int pos = 0; do { // Append text up to the match` append(sb, s, pos, matchIndex); // Add replaceWith text sb.append(replaceWith); // Find next occurrence, if any pos = matchIndex + searchForLength; matchIndex = search(s, searchString, pos); } while (matchIndex != -1); // Add tail of s sb.append(s.subSequence(pos, s.length())); // Return processed buffer return sb; } }
From source file:fr.smile.liferay.LiferayUrlRewriter.java
/** * Fix all resources urls and return the result. * * @param input The original charSequence to be processed. * @param requestUrl The request URL./*from w w w . ja v a 2s.co m*/ * @param baseUrlParam The base URL selected for this request. * @return the result of this renderer. */ public CharSequence rewriteHtml(CharSequence input, String requestUrl, Pattern pattern, String baseUrlParam, String visibleBaseUrl) { if (LOG.isDebugEnabled()) { LOG.debug("input=" + input); LOG.debug("rewriteHtml (requestUrl=" + requestUrl + ", pattern=" + pattern + ",baseUrlParam)" + baseUrlParam + ",strVisibleBaseUrl=" + visibleBaseUrl + ")"); } StringBuffer result = new StringBuffer(input.length()); Matcher m = pattern.matcher(input); while (m.find()) { if (LOG.isTraceEnabled()) { LOG.trace("found match: " + m); } String url = input.subSequence(m.start(3) + 1, m.end(3) - 1).toString(); url = rewriteUrl(url, requestUrl, baseUrlParam, visibleBaseUrl); url = url.replaceAll("\\$", "\\\\\\$"); // replace '$' -> '\$' as it // denotes group StringBuffer tagReplacement = new StringBuffer("<$1$2=\"").append(url).append("\""); if (m.groupCount() > 3) { tagReplacement.append("$4"); } tagReplacement.append('>'); if (LOG.isTraceEnabled()) { LOG.trace("replacement: " + tagReplacement); } m.appendReplacement(result, tagReplacement.toString()); } m.appendTail(result); return result; }
From source file:com.asakusafw.runtime.io.text.driver.InputDriver.java
private int countRest() throws IOException { int count = 0; while (reader.nextField()) { if (skipExtraEmptyInput) { CharSequence cs = reader.getContent(); if (cs != null) { if (trimExtraInput) { cs = trimmer.wrap(cs); }//from w ww . j av a 2s . c o m if (cs.length() == 0) { continue; } } } count++; } return count; }
From source file:com.asakusafw.runtime.io.text.driver.InputDriver.java
private <P> boolean processField(T model, FieldDriver<T, P> field) throws IOException { P property = field.extractor.apply(model); FieldAdapter<? super P> adapter = field.adapter; while (reader.nextField()) { CharSequence value = reader.getContent(); if (value != null) { if (field.trimInput) { value = trimmer.wrap(value); }/*w w w . j a va2 s .c om*/ if (value.length() == 0 && field.skipEmptyInput) { if (LOG.isTraceEnabled()) { LOG.trace(String.format("skip empty field: path=%s, line=%,d, row=%,d, column=%,d", path, getLineNumberMessage(), getRecordIndexMessage(), getFieldIndexMessage())); } continue; } } try { adapter.parse(value, property); } catch (MalformedFieldException e) { adapter.clear(property); handleMalformed(field, value, e); } return true; } adapter.clear(property); return false; }
From source file:com.oasis.sdk.activity.OasisSdkPayEpinActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(BaseUtils.getResourceValue("layout", "oasisgames_sdk_pay_epin")); initHead(true, null, true,//from ww w . jav a 2 s . c om getString(BaseUtils.getResourceValue("string", "oasisgames_sdk_pcenter_notice_12"))); et_code = (EditText) findViewById(BaseUtils.getResourceValue("id", "oasisgames_sdk_epin_edittext")); et_code.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { if (s.length() > 0) ll_clean.setVisibility(View.VISIBLE); else ll_clean.setVisibility(View.GONE); } }); ll_clean = (LinearLayout) findViewById(BaseUtils.getResourceValue("id", "oasisgames_sdk_epin_clean")); ll_clean.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { onClickToClean(v); } }); ll_images = (LinearLayout) findViewById(BaseUtils.getResourceValue("id", "oasisgames_sdk_epin_img")); mHandler = new MyHandler(this); mHandler.sendEmptyMessageDelayed(100, 2000); }
From source file:edu.cornell.med.icb.goby.util.SimulateBisulfiteReads.java
private MutableString context(int i, CharSequence segmentBases) { MutableString context = new MutableString(); int contextLength = 10; int start = Math.max(0, i - contextLength); int end = Math.min(segmentBases.length(), i + contextLength); final String bases = segmentBases.toString(); context.append(bases.subSequence(start, i)); context.append('>'); context.append(bases.charAt(i));// w w w .jav a 2s . c o m context.append('<'); final int a = i + 1; if (a < end) { final CharSequence sequence = bases.subSequence(a, end); context.append(sequence); } return context; }
From source file:au.org.ala.delta.translation.PrintFile.java
/** * Returns the number of leading spaces in the supplied text. * /*www .jav a 2 s .co m*/ * @param text * the text to count leading spaces of. * @return the number of leading spaces in the supplied text or zero if the * parameter is null. */ private int numLeadingSpaces(CharSequence text) { if ((text == null) || (text.length() == 0)) { return 0; } int numSpaces = 0; while (text.charAt(numSpaces) == ' ') { numSpaces++; } return numSpaces; }
From source file:br.msf.commons.util.CharSequenceUtils.java
public static String subStringAfterFirst(final CharSequence toSearch, final CharSequence sequence, final Boolean caseSensitive) { final int idx = indexOf(toSearch, sequence, caseSensitive); return (idx < 0) ? null : CharSequenceUtils.castToString(sequence.subSequence(idx + toSearch.length(), length(sequence))); }