List of usage examples for java.lang CharSequence charAt
char charAt(int index);
From source file:com.strathclyde.highlightingkeyboard.SoftKeyboardService.java
/** * Find out the position of a word in the text being input * @param cursor starting position in the text from which to begin the search (backwards) * @param text the text having been input so far * @return a WordDetails object with the start and end position of a given word *//* w w w.j a va 2s .c o m*/ public WordDetails findWord(int cursor, CharSequence text) { WordDetails word = new WordDetails(); //loop backwards to find start of current word for (int x = cursor - 1; x >= 0; x--) { if (x == 0) { word.wordStart = x; break; } else if (isWordSeparator(text.charAt(x))) { word.wordStart = x + 1; break; } } //loop forwards to find end of current word for (int x = cursor - 1; x < text.length(); x++) { if (x < 0) break; if (isWordSeparator(text.charAt(x)) || x == text.length() - 1) { word.wordEnd = x; break; } } return word; }
From source file:HSqlPrimerDesign.java
@SuppressWarnings("Duplicates") //calculates melting temperature of a oligonucleotide //based off Primer3 code source code public static double primerTm(CharSequence primer, double salt_conc, double dna_conc, double divalent, double dntp) { /**// w ww. j a v a2s.co m *Tables of nearest-neighbor thermodynamics for DNA bases, from the * paper [SantaLucia JR (1998) "A unified view of polymer, dumbbell * and oligonucleotide DNA nearest-neighbor thermodynamics", Proc Natl * Acad Sci 95:1460-65 http://dx.doi.org/10.1073/pnas.95.4.1460] */ final double T_KELVIN = 273.15; //delta S for nucleotide pairs int DS_A_A = 222; int DS_A_C = 224; int DS_A_G = 210; int DS_A_T = 204; int DS_A_N = 224; int DS_C_A = 227; int DS_C_C = 199; int DS_C_G = 272; int DS_C_T = 210; int DS_C_N = 272; int DS_G_A = 222; int DS_G_C = 244; int DS_G_G = 199; int DS_G_T = 224; int DS_G_N = 244; int DS_T_A = 213; int DS_T_C = 222; int DS_T_G = 227; int DS_T_T = 222; int DS_T_N = 227; int DS_N_A = 168; int DS_N_C = 210; int DS_N_G = 220; int DS_N_T = 215; int DS_N_N = 220; //delta H for nucleotide pairs int DH_A_A = 79; int DH_A_C = 84; int DH_A_G = 78; int DH_A_T = 72; int DH_A_N = 72; int DH_C_A = 85; int DH_C_C = 80; int DH_C_G = 106; int DH_C_T = 78; int DH_C_N = 78; int DH_G_A = 82; int DH_G_C = 98; int DH_G_G = 80; int DH_G_T = 84; int DH_G_N = 80; int DH_T_A = 72; int DH_T_C = 82; int DH_T_G = 85; int DH_T_T = 79; int DH_T_N = 72; int DH_N_A = 72; int DH_N_C = 80; int DH_N_G = 78; int DH_N_T = 72; int DH_N_N = 72; // Delta G's of disruption * 1000. int DG_A_A = 1000; int DG_A_C = 1440; int DG_A_G = 1280; int DG_A_T = 880; int DG_A_N = 880; int DG_C_A = 1450; int DG_C_C = 1840; int DG_C_G = 2170; int DG_C_T = 1280; int DG_C_N = 1450; int DG_G_A = 1300; int DG_G_C = 2240; int DG_G_G = 1840; int DG_G_T = 1440; int DG_G_N = 1300; int DG_T_A = 580; int DG_T_C = 1300; int DG_T_G = 1450; int DG_T_T = 1000; int DG_T_N = 580; int DG_N_A = 580; int DG_N_C = 1300; int DG_N_G = 1280; int DG_N_T = 880; int DG_N_N = 580; //loops through primer to determine dh and ds int dh = 0; int ds = 0; int dg = 0; for (int i = 0; i < (primer.length() - 1); i++) { char first = primer.charAt(i); char sec = primer.charAt(i + 1); if (first == 'g' || first == 'G') { if (sec == 'g' || sec == 'G') { dh += DH_G_G; dg += DG_G_G; ds += DS_G_G; } else if (sec == 'c' || sec == 'C') { dh += DH_G_C; dg += DG_G_C; ds += DS_G_C; } else if (sec == 't' || sec == 'T') { dh += DH_G_T; dg += DG_G_T; ds += DS_G_T; } else if (sec == 'a' || sec == 'A') { dh += DH_G_A; dg += DG_G_A; ds += DS_G_A; } } else if (first == 'c' || first == 'C') { if (sec == 'g' || sec == 'G') { dh += DH_C_G; dg += DG_C_G; ds += DS_C_G; } else if (sec == 'c' || sec == 'C') { dh += DH_C_C; dg += DG_C_C; ds += DS_C_C; } else if (sec == 't' || sec == 'T') { dh += DH_C_T; dg += DG_C_T; ds += DS_C_T; } else if (sec == 'a' || sec == 'A') { dh += DH_C_A; dg += DG_C_A; ds += DS_C_A; } } else if (first == 't' || first == 'T') { if (sec == 'g' || sec == 'G') { dh += DH_T_G; dg += DG_T_G; ds += DS_T_G; } else if (sec == 'c' || sec == 'C') { dh += DH_T_C; dg += DG_T_C; ds += DS_T_C; } else if (sec == 't' || sec == 'T') { dh += DH_T_T; dg += DG_T_T; ds += DS_T_T; } else if (sec == 'a' || sec == 'A') { dh += DH_T_A; dg += DG_T_A; ds += DS_T_A; } } else if (first == 'a' || first == 'A') { if (sec == 'g' || sec == 'G') { dh += DH_A_G; dg += DG_A_G; ds += DS_A_G; } else if (sec == 'c' || sec == 'C') { dh += DH_A_C; dg += DG_A_C; ds += DS_A_C; } else if (sec == 't' || sec == 'T') { dh += DH_A_T; dg += DG_A_T; ds += DS_A_T; } else if (sec == 'a' || sec == 'A') { dh += DH_A_A; dg += DG_A_A; ds += DS_A_A; } } } //checks for symmetry int sym = -1; if (primer.length() % 2 == 1) { sym = 0; } else { for (int i = 0; i < (primer.length() / 2); i++) { if ((primer.charAt(i) == 'A' && primer.charAt(primer.length() - i - 1) != 'T') || (primer.charAt(i) == 'T' && primer.charAt(primer.length() - i - 1) != 'A') || (primer.charAt(i) == 'C' && primer.charAt(primer.length() - i - 1) != 'G') || (primer.charAt(i) == 'G' && primer.charAt(primer.length() - i - 1) != 'C')) { sym = 0; break; } i++; } if (sym == -1) { sym = 1; } } //Assigns AT end penalty if (primer.charAt(0) == 'A' || primer.charAt(0) == 'T') { ds += -41; dh += -23; } else if (primer.charAt(0) == 'G' || primer.charAt(0) == 'C') { ds += 28; dh += -1; } if (primer.charAt(primer.length() - 1) == 'A' || primer.charAt(primer.length() - 1) == 'T') { ds += -41; dh += -23; } else if (primer.charAt(primer.length() - 1) == 'G' || primer.charAt(primer.length() - 1) == 'C') { ds += 28; dh += -1; } if (divalent == 0) dntp = 0; if (divalent < dntp) divalent = dntp; salt_conc = salt_conc + 120 * (Math.sqrt(divalent - dntp)); double delta_H = dh * -100.0; double delta_S = ds * -0.1; delta_S = delta_S + 0.368 * (primer.length() - 1) * Math.log(salt_conc / 1000.0); double tm; if (sym == 1) { tm = delta_H / (delta_S + 1.987 * Math.log(dna_conc / 1000000000.0)) - T_KELVIN; } else { tm = delta_H / (delta_S + 1.987 * Math.log(dna_conc / 4000000000.0)) - T_KELVIN; } return tm; }
From source file:com.anysoftkeyboard.AnySoftKeyboard.java
private void removeTrailingSpace() { final InputConnection ic = getCurrentInputConnection(); if (ic == null) return;//from www . jav a 2 s .c om CharSequence lastOne = ic.getTextBeforeCursor(1, 0); if (lastOne != null && lastOne.length() == 1 && lastOne.charAt(0) == KeyCodes.SPACE) { ic.deleteSurroundingText(1, 0); } }
From source file:com.ringdroid.RingdroidEditActivity.java
private String makeRingtoneFilename(CharSequence title, String extension) { String parentdir;//from www. j ava2 s. c o m switch (mNewFileKind) { default: case FileSaveDialog.FILE_KIND_MUSIC: parentdir = "/sdcard/media/audio/music"; break; case FileSaveDialog.FILE_KIND_ALARM: parentdir = "/sdcard/media/audio/alarms"; break; case FileSaveDialog.FILE_KIND_NOTIFICATION: parentdir = "/sdcard/media/audio/notifications"; break; case FileSaveDialog.FILE_KIND_RINGTONE: parentdir = "/sdcard/media/audio/ringtones"; break; } // Create the parent directory File parentDirFile = new File(parentdir); parentDirFile.mkdirs(); // If we can't write to that special path, try just writing // directly to the sdcard if (!parentDirFile.isDirectory()) { parentdir = "/sdcard"; } // Turn the title into a filename String filename = ""; for (int i = 0; i < title.length(); i++) { if (Character.isLetterOrDigit(title.charAt(i))) { filename += title.charAt(i); } } // Try to make the filename unique String path = null; for (int i = 0; i < 100; i++) { String testPath; if (i > 0) testPath = parentdir + "/" + filename + i + extension; else testPath = parentdir + "/" + filename + extension; try { RandomAccessFile f = new RandomAccessFile(new File(testPath), "r"); } catch (Exception e) { // Good, the file didn't exist path = testPath; break; } } return path; }
From source file:org.apache.fop.layoutmgr.inline.TextLayoutManager.java
private AreaInfo processWordMapping(int lastIndex, final Font font, AreaInfo prevAreaInfo, final char breakOpportunityChar, final boolean endsWithHyphen, int level) { int s = this.thisStart; // start index of word in FOText character buffer int e = lastIndex; // end index of word in FOText character buffer int nLS = 0; // # of letter spaces String script = foText.getScript(); String language = foText.getLanguage(); if (LOG.isDebugEnabled()) { LOG.debug("PW: [" + thisStart + "," + lastIndex + "]: {" + " +M" + ", level = " + level + " }"); }//from ww w .j a va2s . com // 1. extract unmapped character sequence CharSequence ics = foText.subSequence(s, e); // 2. if script is not specified (by FO property) or it is specified as 'auto', // then compute dominant script if ((script == null) || "auto".equals(script)) { script = CharScript.scriptTagFromCode(CharScript.dominantScript(ics)); } if ((language == null) || "none".equals(language)) { language = "dflt"; } // 3. perform mapping of chars to glyphs ... to glyphs ... to chars CharSequence mcs = font.performSubstitution(ics, script, language); // 4. compute glyph position adjustments on (substituted) characters int[][] gpa; if (font.performsPositioning()) { // handle GPOS adjustments gpa = font.performPositioning(mcs, script, language); } else if (font.hasKerning()) { // handle standard (non-GPOS) kerning adjustments gpa = getKerningAdjustments(mcs, font); } else { gpa = null; } // 5. reorder combining marks so that they precede (within the mapped char sequence) the // base to which they are applied; N.B. position adjustments (gpa) are reordered in place mcs = font.reorderCombiningMarks(mcs, gpa, script, language); // 6. if mapped sequence differs from input sequence, then memoize mapped sequence if (!CharUtilities.isSameSequence(mcs, ics)) { foText.addMapping(s, e, mcs); } // 7. compute word ipd based on final position adjustments MinOptMax ipd = MinOptMax.ZERO; for (int i = 0, n = mcs.length(); i < n; i++) { int c = mcs.charAt(i); // TODO !BMP int w = font.getCharWidth(c); if (w < 0) { w = 0; } if (gpa != null) { w += gpa[i][GlyphPositioningTable.Value.IDX_X_ADVANCE]; } ipd = ipd.plus(w); } // [TBD] - handle letter spacing return new AreaInfo(s, e, 0, nLS, ipd, endsWithHyphen, false, breakOpportunityChar != 0, font, level, gpa); }
From source file:com.android.ex.chips.RecipientEditTextView.java
public boolean lastCharacterIsCommitCharacter(final CharSequence s) { char last;/* www.j av a 2s . c o m*/ final int end = getSelectionEnd() == 0 ? 0 : getSelectionEnd() - 1; final int len = length() - 1; if (end != len) last = s.charAt(end); else last = s.charAt(len); return last == COMMIT_CHAR_COMMA || last == COMMIT_CHAR_SEMICOLON || last == COMMIT_CHAR_SPACE; // added by shreyash }
From source file:com.android.mms.ui.MessageUtils.java
public static final String findSpanishChar(CharSequence s) { int sLength = s.length(); StringBuilder sPs = new StringBuilder(); for (int i = 0; i < sLength; i++) { char tmpC = s.charAt(i); int tmpi = (int) tmpC; // Log.e("chenshu","MessageUtils->>findSpanishChar->>tmpi->>"+Integer.toHexString(tmpi)); // Log.d("chenshu","MessageUtils->>findSpanishChar->>calculateLength->>"+s.subSequence(i,i+1)); int[] params = SmsMessage.calculateLength(s.subSequence(i, i + 1), false); // /* SmsMessage.calculateLength returns an int[4] with: // * int[0] being the number of SMS's required, // * int[1] the number of code units used, // * int[2] is the number of code units remaining until the next message. // * int[3] is the encoding type that should be used for the message. // *//*from w w w . jav a2 s.c o m*/ int remainingInCurrentMessage = params[2]; // Log.d("chenshu","MessageUtils->>findSpanishChar->>remainingInCurrentMessage->>"+remainingInCurrentMessage); if (remainingInCurrentMessage > 70) { // Log.d("chenshu","MessageUtils->>findSpanishChar->>Default 7-bit char"); sPs.append(tmpC); continue; } switch (tmpi) { case 0x00C0: case 0x00C1: case 0x00C2: case 0x00C3: // Log.d("chenshu","MessageUtils->>findSpanishChar->>convert to A"); sPs.append('A'); break; case 0x00C8: case 0x00CA: case 0x00CB: // Log.d("chenshu","MessageUtils->>findSpanishChar->>convert to E"); sPs.append('E'); break; case 0x00CC: case 0x00CD: case 0x00CE: case 0x00CF: case 0x0130: // Log.d("chenshu","MessageUtils->>findSpanishChar->>convert to I"); sPs.append('I'); break; case 0x00D2: case 0x00D3: case 0x00D4: case 0x00D5: // Log.d("chenshu","MessageUtils->>findSpanishChar->>convert to O"); sPs.append('O'); break; case 0x00D9: case 0x00DA: case 0x00DB: // Log.d("chenshu","MessageUtils->>findSpanishChar->>convert to U"); sPs.append('U'); break; case 0x00E1: case 0x00E2: case 0x00E3: // Log.d("chenshu","MessageUtils->>findSpanishChar->>convert to a"); sPs.append('a'); break; //case 0x00C7: case 0x00E7: // Log.d("chenshu","MessageUtils->>findSpanishChar->>convert to c"); sPs.append('c'); break; case 0x00EA: case 0x00EB: // Log.d("chenshu","MessageUtils->>findSpanishChar->>convert to e"); sPs.append('e'); break; case 0x00ED: case 0x00EE: case 0x00EF: case 0x0131: // Log.d("chenshu","MessageUtils->>findSpanishChar->>convert to i"); sPs.append('i'); break; case 0x00F3: case 0x00F4: case 0x00F5: // Log.d("chenshu","MessageUtils->>findSpanishChar->>convert to o"); sPs.append('o'); break; case 0x00FA: case 0x00FB: // Log.d("chenshu","MessageUtils->>findSpanishChar->>convert to u"); sPs.append('u'); break; case 0x011E: sPs.append('G'); break; case 0x011F: sPs.append('g'); break; case 0x015E: sPs.append('S'); break; case 0x015F: sPs.append('s'); break; default: if (tmpC > 127 || tmpC < 0) { // Log.e("chenshu","MessageUtil->>findSpanishChar->>becaus it was not ascii char->>tmpC->>"+tmpC); return null; } else { sPs.append(tmpC); } break; } // Log.e("chenshu","MessageUtil->>findSpanishChar->>tmpC->>"+tmpC); } if (sPs.toString().endsWith(s.toString())) { return null; } else { // Log.e("chenshu","MessageUtil->>findSpanishChar->>mRepliceText->>"+sPs.toString()); return sPs.toString(); } }
From source file:com.healthmarketscience.jackcess.impl.ColumnImpl.java
/** * Encodes a text value, possibly compressing. *//*from ww w . java2 s. com*/ ByteBuffer encodeTextValue(Object obj, int minChars, int maxChars, boolean forceUncompressed) throws IOException { CharSequence text = toCharSequence(obj); if ((text.length() > maxChars) || (text.length() < minChars)) { throw new IOException("Text is wrong length for " + getType() + " column, max " + maxChars + ", min " + minChars + ", got " + text.length()); } // may only compress if column type allows it if (!forceUncompressed && isCompressedUnicode() && (text.length() <= getFormat().MAX_COMPRESSED_UNICODE_SIZE)) { // for now, only do very simple compression (only compress text which is // all ascii text) if (isAsciiCompressible(text)) { byte[] encodedChars = new byte[TEXT_COMPRESSION_HEADER.length + text.length()]; encodedChars[0] = TEXT_COMPRESSION_HEADER[0]; encodedChars[1] = TEXT_COMPRESSION_HEADER[1]; for (int i = 0; i < text.length(); ++i) { encodedChars[i + TEXT_COMPRESSION_HEADER.length] = (byte) text.charAt(i); } return ByteBuffer.wrap(encodedChars); } } return encodeUncompressedText(text, getCharset()); }
From source file:com.silentcircle.silenttext.application.SilentTextApplication.java
public CharSequence getFullJIDForUsername(CharSequence username) { CharArrayWriter out = new CharArrayWriter(); boolean shouldAppend = true; for (int i = 0; i < username.length(); i++) { char c = username.charAt(i); out.append(username.charAt(i));//w w w . jav a2 s. c o m if (c == '@') { shouldAppend = false; } } if (shouldAppend) { out.append('@'); out.append(getDomain()); } return CharBuffer.wrap(out.toCharArray()); }
From source file:com.anysoftkeyboard.AnySoftKeyboard.java
public void performRestartWordSuggestion(final InputConnection ic) { // I assume ASK DOES NOT predict at this moment! // 2) predicting and moved outside the word - abort predicting, update // shift state // 2.1) to a new word - restart predicting on the new word // 2.2) to no word land - nothing else // this means that the new cursor position is outside the candidates // underline// w w w. j a v a 2s. co m // this can be either because the cursor is really outside the // previously underlined (suggested) // or nothing was suggested. // in this case, we would like to reset the prediction and restart // if the user clicked inside a different word // restart required? if (canRestartWordSuggestion()) {// 2.1 ic.beginBatchEdit();// don't want any events till I finish handling // this touch abortCorrectionAndResetPredictionState(false); // locating the word CharSequence toLeft = ""; CharSequence toRight = ""; while (true) { CharSequence newToLeft = ic.getTextBeforeCursor(toLeft.length() + 1, 0); if (TextUtils.isEmpty(newToLeft) || isWordSeparator(newToLeft.charAt(0)) || newToLeft.length() == toLeft.length()) { break; } toLeft = newToLeft; } while (true) { CharSequence newToRight = ic.getTextAfterCursor(toRight.length() + 1, 0); if (TextUtils.isEmpty(newToRight) || isWordSeparator(newToRight.charAt(newToRight.length() - 1)) || newToRight.length() == toRight.length()) { break; } toRight = newToRight; } CharSequence word = toLeft.toString() + toRight.toString(); Logger.d(TAG, "Starting new prediction on word '%s'.", word); mUndoCommitCursorPosition = UNDO_COMMIT_NONE; mWord.reset(); final int[] tempNearByKeys = new int[1]; for (int index = 0; index < word.length(); index++) { final char c = word.charAt(index); if (index == 0) mWord.setFirstCharCapitalized(Character.isUpperCase(c)); tempNearByKeys[0] = c; mWord.add(c, tempNearByKeys); TextEntryState.typedCharacter(c, false); } ic.deleteSurroundingText(toLeft.length(), toRight.length()); ic.setComposingText(word, 1); // repositioning the cursor if (toRight.length() > 0) { final int cursorPosition = getCursorPosition(ic) - toRight.length(); Logger.d(TAG, "Repositioning the cursor inside the word to position %d", cursorPosition); ic.setSelection(cursorPosition, cursorPosition); } mWord.setCursorPosition(toLeft.length()); ic.endBatchEdit(); postUpdateSuggestions(); } else { Logger.d(TAG, "performRestartWordSuggestion canRestartWordSuggestion == false"); } }