/** * Construct a FastStr from a CharSequence * @param cs the CharSequence instance * @return a FastStr */ public static FastStr of(CharSequence cs) { if (cs instanceof FastStr) { return (FastStr)cs; } return of(cs.toString()); }
/** * Construct a FastStr instance from an iterable of characters * @param itr the character iterable * @return the FastStr */ public static FastStr of(Iterable<Character> itr) { StringBuilder sb = new StringBuilder(); for (Character c : itr) { sb.append(c); } return of(sb); }
/** * Construct a FastStr instance from an iterator of characters * @param itr the character iterator * @return a FastStr instance consists of all chars in the iterator */ public static FastStr of(Iterator<Character> itr) { StringBuilder sb = new StringBuilder(); while (itr.hasNext()) { sb.append(itr.next()); } return of(sb); }
public static FastStr of(byte[] bytes, String encoding) { ByteBuffer byteBuffer = ByteBuffer.wrap(bytes); CharBuffer charBuffer = Charset.forName(encoding).decode(byteBuffer); char[] chars = Arrays.copyOfRange(charBuffer.array(), charBuffer.position(), charBuffer.limit()); Arrays.fill(charBuffer.array(), '\u0000'); // clear sensitive data Arrays.fill(byteBuffer.array(), (byte) 0); // clear sensitive data return FastStr.of(chars); }
/** * Returns the index within this str of the first occurrence of the * specified character list * @param list the list of chars to search for * @return the index of the first occurrence of the specified char list */ public int indexOf(java.util.List<Character> list) { return indexOf((CharSequence) FastStr.of(list)); }
/** * Return the char array that backed the char sequence specified * @param chars the char sequence * @return an array of chars of the char sequence */ @SuppressWarnings("unused") public static char[] bufOf(CharSequence chars) { return FastStr.of(chars).charArray(); }
/** * Returns char array that backed the char sequence specified * @param chars the char sequence * @return the char array of the char sequence */ public static char[] bufOf(CharSequence chars) { if (null == chars) return EMPTY_CHAR_ARRAY; return FastStr.of(chars).unsafeChars(); }
/** * Returns the index within this str of the last occurrence of the * specified character list * @param list the list of chars to search for * @return the index of the last occurrence of the specified char list */ public int lastIndexOf(java.util.List<Character> list) { return lastIndexOf((CharSequence) FastStr.of(list)); }
private String val(Map<String, String> conf, String key, String prefix) { String val = conf.get(key); if (S.blank(val)) { if (key.startsWith("storage.")) { key = FastStr.of(key).insert(8, prefix).toString(); } val = conf.get(key); } return val; }
public static File sourceFile(List<File> sourceRoots, String className) { FastStr s = FastStr.of(className).beforeFirst('$'); s = s.replace('.', File.separatorChar).append(".java"); for (File sourceRoot : sourceRoots) { File file = new File(sourceRoot, s.toString()); if (file.canRead()) { return file; } } return null; }
public static File sourceFile(List<File> sourceRoots, String className) { FastStr s = FastStr.of(className).beforeFirst('$'); s = s.replace('.', File.separatorChar).append(".java"); for (File sourceRoot : sourceRoots) { File file = new File(sourceRoot, s.toString()); if (file.canRead()) { return file; } } return null; }
@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 static String classNameToClassFileName(String className, boolean keepInnerClass) { FastStr fs = FastStr.of(className); if (!keepInnerClass && className.contains("$")) { fs = fs.beforeFirst('$'); } fs = fs.replace('.', '/').append(".class").prepend('/'); return fs.toString(); }
public static String classNameToClassFileName(String className, boolean keepInnerClass) { FastStr fs = FastStr.of(className); if (!keepInnerClass && className.contains("$")) { fs = fs.beforeFirst('$'); } fs = fs.replace('.', '/').append(".class").prepend('/'); return fs.toString(); }
static void hashCodeMethodEnd(MethodVisitor mv, int fieldCnt) { FastStr signature; if (fieldCnt < 6) { signature = FastStr.of("Ljava/lang/Object;").times(fieldCnt); } else { signature = FastStr.of("Ljava/lang/Object;").times(5).append("[Ljava/lang/Object;"); } signature = signature.prepend("(").append(")I"); mv.visitMethodInsn(INVOKESTATIC, "org/osgl/Osgl", "hc", signature.toString(), false); mv.visitInsn(IRETURN); mv.visitMaxs(0, 0); // just pass any number and have ASM to calculate mv.visitEnd(); }
protected T sourceVersion(JavaVersion version) { sourceVersion = FastStr.of(version.name()).substr(1).replace('_', '.').toString(); return me(); }
@Override public boolean apply(JSONSerializer serializer, Object source, String name) { if (source == null) { return true; } // if context path is "$.bar.zee" or "$[0].bar.zee" and name is "foo" // then path should be "bar.zee.foo" String path; FastStr fs = FastStr.of(serializer.getContext().toString()).append('.').append(name); path = fs.substring(fs.indexOf('.') + 1); // skip the first "." return matches(path); }
@Override public boolean apply(JSONSerializer serializer, Object source, String name) { if (source == null) { return true; } // if context path is "$.bar.zee" or "$[0].bar.zee" and name is "foo" // then path should be "bar.zee.foo" String path; FastStr fs = FastStr.of(serializer.getContext().toString()).append('.').append(name); path = fs.substring(fs.indexOf('.') + 1); // skip the first "." return matches(path); }
private $.T2<String, String> splitActionStr(String action) { FastStr fs = FastStr.of(action); FastStr fs1 = fs.beforeFirst(':'); FastStr fs2 = fs1.isEmpty() ? fs : fs.substr(fs1.length() + 1); return $.T2(fs1.trim().toString(), fs2.trim().toString()); }
private $.T2<String, String> splitActionStr(String action) { FastStr fs = FastStr.of(action); FastStr fs1 = fs.beforeFirst(':'); FastStr fs2 = fs1.isEmpty() ? fs : fs.substr(fs1.length() + 1); return $.T2(fs1.trim().toString(), fs2.trim().toString()); }