List of usage examples for java.lang StringBuffer reverse
@Override public synchronized StringBuffer reverse()
From source file:edu.buffalo.fusim.ExtractSeq.java
public static StringBuffer reverseComplement(StringBuffer seq) { StringBuffer revc = new StringBuffer(); seq.reverse(); for (int i = 0; i < seq.length(); i++) { revc.append(symbolMap.get(seq.charAt(i))); }//from w w w . j a v a2 s . com return revc; }
From source file:Main.java
private static String byte2bitsReverse(byte ch) { //Log.e(TAG, "byte2bitsReverse() ch = " + ch); int z = ch;//from w w w.j a v a 2s.c o m z |= 256; String str = Integer.toBinaryString(z); int len = str.length(); String result = str.substring(len - 8, len); StringBuffer sb = new StringBuffer(result); //Log.e(TAG, "byte2bitsReverse() return = " + sb.reverse().toString()); return sb.reverse().toString(); }
From source file:Main.java
static String toBinary(int num) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < 32; i++) { sb.append(((num & 1) == 1) ? '1' : '0'); num >>= 1;/*from ww w .ja v a 2 s . c o m*/ } return sb.reverse().toString(); }
From source file:Main.java
/** * Convert a column number to letters./*from w w w . j a va 2s .co m*/ * @param colNo * @return */ public static String getColumnName(int colNo) { StringBuffer sb = new StringBuffer(); do { int last = colNo % 26; colNo = colNo / 26 - 1; sb.append((char) ((int) 'A' + last)); } while (colNo >= 0); return sb.reverse().toString(); }
From source file:Main.java
public static byte[] getBitData(byte[] src, int start, int end, boolean isLH) { byte[] result = null; StringBuffer sb = new StringBuffer(); for (byte b : src) { sb.append(getBinaryString(b));/* ww w . j a v a2 s. c o m*/ } String bitString = (isLH ? sb : sb.reverse()).substring(start, end); result = new byte[bitString.length()]; for (int i = 0; i < bitString.length(); i++) { result[i] = Byte.valueOf(String.valueOf(bitString.charAt(i))); } return result; }
From source file:Main.java
/** * Convert a single unicode scalar value to an XML numeric character * reference. If in the BMP, four digits are used, otherwise 6 digits are used. * * @param c// w ww . ja v a2 s .com * a unicode scalar value * @return a string representing a numeric character reference */ public static String charToNCRef(int c) { StringBuffer sb = new StringBuffer(); for (int i = 0, nDigits = (c > 0xFFFF) ? 6 : 4; i < nDigits; i++, c >>= 4) { int d = c & 0xF; char hd; if (d < 10) { hd = (char) ((int) '0' + d); } else { hd = (char) ((int) 'A' + (d - 10)); } sb.append(hd); } return "&#x" + sb.reverse() + ";"; }
From source file:Main.java
public static String toBase58(byte[] b) { if (b.length == 0) { return ""; }/* w ww . j ava2s .c o m*/ int lz = 0; while (lz < b.length && b[lz] == 0) { ++lz; } StringBuffer s = new StringBuffer(); BigInteger n = new BigInteger(1, b); while (n.compareTo(BigInteger.ZERO) > 0) { BigInteger[] r = n.divideAndRemainder(BigInteger.valueOf(58)); n = r[0]; char digit = b58[r[1].intValue()]; s.append(digit); } while (lz > 0) { --lz; s.append("1"); } return s.reverse().toString(); }
From source file:TextUtilities.java
/** * <P>Returns a substring of the given StringBuffer's string which consists of * the characters from the beginning of it until the first occurrence of the * given delimiter string or if the delimiter doesn't occur, until the end * of the string. The StringBuffer is modified so it no longer contains those * characters or the delimiter.//from ww w . j ava 2s . c o m * <P>Examples: * <UL> * <LI>nextToken(new StringBuffer("abcdefgh"), "de") returns "abc" and * the StringBuffer is modified to represent the string "fgh". * <LI>nextToken(new StringBuffer("abcdefgh"), "a") returns an empty string * and the StringBuffer is modified to represent the string "bcdefgh". * <LI>nextToken(new StringBuffer("abcdefgh"), "k") returns "abcdefgh" and * the StringBuffer is modified to represent an empty string. * </UL> */ public static String nextToken(StringBuffer buf, String delimiter) { String bufStr = buf.toString(); int delimIndex = bufStr.indexOf(delimiter); if (delimIndex == -1) { buf.setLength(0); return bufStr; } String str = bufStr.substring(0, delimIndex); buf.reverse(); buf.setLength(buf.length() - delimIndex - delimiter.length()); buf.reverse(); return str; }
From source file:org.apache.metron.common.dsl.functions.NetworkFunctions.java
/** * Extract the TLD. If the domain is a normal domain, then we can handle the TLD via the InternetDomainName object. * If it is not, then we default to returning the last segment after the final '.' * @param idn//from w w w . java 2 s . c o m * @param dn * @return The TLD of the domain */ private static String extractTld(InternetDomainName idn, String dn) { if (idn != null && idn.hasPublicSuffix()) { return idn.publicSuffix().toString(); } else if (dn != null) { StringBuffer tld = new StringBuffer(""); for (int idx = dn.length() - 1; idx >= 0; idx--) { char c = dn.charAt(idx); if (c == '.') { break; } else { tld.append(dn.charAt(idx)); } } return tld.reverse().toString(); } else { return null; } }
From source file:org.apache.metron.stellar.dsl.functions.NetworkFunctions.java
/** * Extract the TLD. If the domain is a normal domain, then we can handle the TLD via the InternetDomainName object. * If it is not, then we default to returning the last segment after the final '.' * @param idn/* w w w . j av a 2s.c om*/ * @param dn * @return The TLD of the domain */ private static String extractTld(InternetDomainName idn, String dn) { if (idn != null && idn.hasPublicSuffix()) { String ret = idn.publicSuffix().toString(); if (ret.startsWith("InternetDomainName")) { return Joiner.on(".").join(idn.publicSuffix().parts()); } else { return ret; } } else if (dn != null) { StringBuffer tld = new StringBuffer(""); for (int idx = dn.length() - 1; idx >= 0; idx--) { char c = dn.charAt(idx); if (c == '.') { break; } else { tld.append(dn.charAt(idx)); } } return tld.reverse().toString(); } else { return null; } }