/** * Construct a FastStr from a char array * @param ca the char array * @return a FastStr */ public static FastStr of(char[] ca) { if (ca.length == 0) return EMPTY_STR; char[] newArray = new char[ca.length]; System.arraycopy(ca, 0, newArray, 0, ca.length); return new FastStr(ca); }
/** * Construct a FastStr from a char array * @param ca the char array * @return a FastStr */ public static FastStr of(char[] ca) { if (ca.length == 0) return EMPTY_STR; char[] newArray = new char[ca.length]; System.arraycopy(ca, 0, newArray, 0, ca.length); return new FastStr(ca); }
/** * Construct a FastStr from a String * @param s the String * @return a FastStr */ public static FastStr of(String s) { int sz = s.length(); if (sz == 0) return EMPTY_STR; char[] buf = s.toCharArray(); return new FastStr(buf, 0, sz); }
/** * Construct a FastStr from a String * @param s the String * @return a FastStr */ public static FastStr of(String s) { int sz = s.length(); if (sz == 0) return EMPTY_STR; char[] buf = s.toCharArray(); return new FastStr(buf, 0, sz); }
/** * Construct a FastStr from a StringBuffer * @param sb the string buffer * @return the FastStr */ public static FastStr of(StringBuffer sb) { int sz = sb.length(); if (0 == sz) return EMPTY_STR; char[] buf = new char[sz]; for (int i = 0; i < sz; ++i) { buf[i] = sb.charAt(i); } return new FastStr(buf, 0, sz); }
/** * Construct a FastStr instance from char array without array copying * @param buf the char array * @return a FastStr instance from the char array */ @SuppressWarnings("unused") public static FastStr unsafeOf(char[] buf) { E.NPE(buf); return new FastStr(buf, 0, buf.length); }
/** * Construct a FastStr instance from char array without array copying * @param buf the char array * @return a FastStr instance from the char array */ @SuppressWarnings("unused") public static FastStr unsafeOf(char[] buf) { E.NPE(buf); return new FastStr(buf, 0, buf.length); }
/** * Construct a FastStr instance from a String instance. * The FastStr instance will share the char array buf with * the String instance * @param s the string instance * @return A FastStr instance */ public static FastStr unsafeOf(String s) { int sz = s.length(); if (sz == 0) return EMPTY_STR; char[] buf = bufOf(s); return new FastStr(buf, 0, sz); }
/** * Construct a FastStr instance from a String instance. * The FastStr instance will share the char array buf with * the String instance * @param s the string instance * @return A FastStr instance */ public static FastStr unsafeOf(String s) { int sz = s.length(); if (sz == 0) return EMPTY_STR; char[] buf = bufOf(s); return new FastStr(buf, 0, sz); }
@Override public FastStr append(Character character) { int sz = size(); char[] newBuf = new char[sz + 1]; copyTo(newBuf, 0); newBuf[sz] = character; return new FastStr(newBuf, 0, sz + 1); }
@Override public FastStr reverse() { int sz = size(); char[] newBuf = new char[sz]; for (int i = 0, j = sz - 1; i < sz; ) { newBuf[j--] = buf[toInternalId(i++)]; } return new FastStr(newBuf, 0, sz); }
@Override public FastStr reverse() { int sz = size(); char[] newBuf = new char[sz]; for (int i = 0, j = sz - 1; i < sz; ) { newBuf[j--] = buf[toInternalId(i++)]; } return new FastStr(newBuf, 0, sz); }
@Override public FastStr append(Character character) { int sz = size(); char[] newBuf = new char[sz + 1]; copyTo(newBuf, 0); newBuf[sz] = character; return new FastStr(newBuf, 0, sz + 1); }
@Override public FastStr append(char... array) { int sz = size(), sz2 = array.length; if (0 == sz2) return this; if (0 == sz) return of(array); char[] newBuf = new char[sz + sz2]; copyTo(newBuf, 0); for (int i = 0; i < sz2; ++i) { newBuf[sz + i] = array[i]; } return new FastStr(newBuf, 0, sz + sz2); }
public FastStr times(int n) { E.illegalArgumentIf(n < 0, "n cannot be negative"); if (0 == n) return EMPTY_STR; if (1 == n) return this; int sz = size(); if (0 == sz) return this; int newSz = sz * n; char[] newBuf = new char[newSz]; for (int i = 0; i < n; ++i) { copyTo(newBuf, i * sz); } return new FastStr(newBuf, 0, newSz); }
@Override public FastStr append(char... array) { int sz = size(), sz2 = array.length; if (0 == sz2) return this; if (0 == sz) return of(array); char[] newBuf = new char[sz + sz2]; copyTo(newBuf, 0); for (int i = 0; i < sz2; ++i) { newBuf[sz + i] = array[i]; } return new FastStr(newBuf, 0, sz + sz2); }
public FastStr append(FastStr s) { int sz = size(), sz2 = s.size(); if (sz == 0) return s; if (sz2 == 0) return this; int newSz = sz + sz2; char[] newBuf = new char[newSz]; copyTo(newBuf, 0); s.copyTo(newBuf, sz); return new FastStr(newBuf, 0, newSz); }
public FastStr append(FastStr s) { int sz = size(), sz2 = s.size(); if (sz == 0) return s; if (sz2 == 0) return this; int newSz = sz + sz2; char[] newBuf = new char[newSz]; copyTo(newBuf, 0); s.copyTo(newBuf, sz); return new FastStr(newBuf, 0, newSz); }
@Override public FastStr append(C.List<Character> list) { int sz = size(), sz2 = list.size(); if (0 == sz2) return this; if (0 == sz) return of(list); char[] newBuf = new char[sz + sz2]; copyTo(newBuf, 0); for (int i = 0; i < sz2; ++i) { newBuf[sz + i] = list.get(i); } return new FastStr(newBuf, 0, sz + sz2); }
@Override public FastStr append(C.List<Character> list) { int sz = size(), sz2 = list.size(); if (0 == sz2) return this; if (0 == sz) return of(list); char[] newBuf = new char[sz + sz2]; copyTo(newBuf, 0); for (int i = 0; i < sz2; ++i) { newBuf[sz + i] = list.get(i); } return new FastStr(newBuf, 0, sz + sz2); }