List of usage examples for com.google.common.base CharMatcher anyOf
public static CharMatcher anyOf(final CharSequence sequence)
From source file:com.dangdang.ddframe.rdb.sharding.util.SQLUtil.java
/** * SQL?./*from w w w . ja v a 2 s .c om*/ * * @param value SQL? * @return SQL? */ public static String getExactlyValue(final String value) { return null == value ? null : CharMatcher.anyOf("[]`'\"").removeFrom(value); }
From source file:com.edgar.jdbc.codegen.CodeGenUtil.java
public static boolean checkIfSourceCodeExists(String rootFolderPath, String packageName) throws Exception { boolean exists = false; String path = ""; if (!Strings.isNullOrEmpty(packageName)) { path = CharMatcher.anyOf(".").replaceFrom(packageName, "/"); if (!Strings.isNullOrEmpty(rootFolderPath)) { path = rootFolderPath + "/" + path; }/*from w w w .j ava2s .c om*/ logger.info("Checking if dir structure:{} exists", path); File file = new File(path); if (file.exists() && file.list().length > 0) { logger.debug("Found package structure:{} with {} files", path, file.list().length); exists = true; } else { logger.info("Package structure does not exist:" + path); exists = false; } } return exists; }
From source file:de.hpi.bp2013n1.anonymizer.util.SafeStringSplitter.java
/** * Splits a string at each occurrence of a split character but not within * quotes. Example: SafeStringSplitter.splitSafely("'a.b'.c'", '.') * returns a List ["'a.b'", "c"].// www . j a v a2 s . co m * @param input * @param splitChar * @return */ public static List<String> splitSafely(String input, char splitChar) { List<String> splitParts = Lists.newArrayList(input.split(Character.toString(splitChar))); CharMatcher quoteMatcher = CharMatcher.anyOf("'\""); for (int i = 0; i < splitParts.size(); i++) { StringBuilder currentPart = new StringBuilder(splitParts.get(i)); int start = 0; boolean sq = false, dq = false; while (true) { int position = quoteMatcher.indexIn(currentPart, start); if (position == -1) { if (sq || dq) { currentPart.append(splitChar).append(splitParts.remove(i + 1)); // TODO: catch IndexOutOfBoundsException => unbalanced continue; } else { splitParts.set(i, currentPart.toString()); break; } } switch (currentPart.charAt(position)) { case '\'': if (!dq) sq = !sq; break; case '"': if (!sq) dq = !dq; break; } start = position + 1; } } return splitParts; }
From source file:org.sonar.db.version.ColumnDefValidation.java
public static String validateColumnName(@Nullable String columnName) { String name = requireNonNull(columnName, "Column name cannot be null"); checkArgument(JAVA_LOWER_CASE.or(CharMatcher.anyOf("_")).or(CharMatcher.DIGIT).matchesAllOf(name), String.format("Column name should only contains lowercase and _ characters, got '%s'", columnName)); return name;// w w w. j a v a 2s . c om }
From source file:org.glowroot.storage.repo.helper.Gauges.java
public static String display(String mbeanObjectName) { // e.g. java.lang:name=PS Eden Space,type=MemoryPool List<String> parts = Splitter.on(CharMatcher.anyOf(":,")).splitToList(mbeanObjectName); StringBuilder name = new StringBuilder(); name.append(parts.get(0));//from w w w . ja v a2 s . c om for (int i = 1; i < parts.size(); i++) { name.append('/'); name.append(parts.get(i).split("=")[1]); } return name.toString(); }
From source file:org.jboss.metrics.agenda.address.Address.java
public static Address apply(String address) { List<String> tokens = address == null ? Collections.<String>emptyList() : Splitter.on(CharMatcher.anyOf("/=")).trimResults().omitEmptyStrings().splitToList(address); List<Tuple> tuples = new ArrayList<>(tokens.size() / 2 + 1); for (Iterator<String> iterator = tokens.iterator(); iterator.hasNext();) { String type = iterator.next(); String name = iterator.hasNext() ? iterator.next() : ""; tuples.add(new Tuple(type, name)); }//from w w w . j ava2 s . c o m return new Address(tuples); }
From source file:com.groupon.mesos.util.UPID.java
public static UPID create(final String master) { checkNotNull(master, "master is null"); final List<String> parts = ImmutableList .copyOf(Splitter.on(CharMatcher.anyOf(":@")).limit(3).split(master)); checkState(parts.size() == 3, "%s is not a valid master definition", master); Integer ip = null;/* www . jav a 2s .c o m*/ try { ip = resolveIp(parts.get(1)); } catch (final IOException e) { LOG.warn("Could not resolve %s: %s", parts.get(1), e.getMessage()); } return new UPID(parts.get(0), HostAndPort.fromParts(parts.get(1), Integer.parseInt(parts.get(2))), ip); }
From source file:org.siyuyan.utils.StringHelper.java
/** * ????//w w w . j a v a 2 s . c o m * @param s * @return */ public static String removeAB12(String s) { return CharMatcher .anyOf("abcdefghijklmnopqrstuvwxyz;&ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.~!@#$%^&*()-+= ><?") .removeFrom(s); }
From source file:org.sbs.util.StringHelper.java
/** * ????//from ww w. j av a 2s . c o m * @param s * @return */ public static String removeAB12Blank(String s) { return CharMatcher .anyOf("abcdefghijklmnopqrstuvwxyz;&ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.~!@#$%^&*()-+= ><?") .removeFrom(s); }
From source file:com.edgar.jdbc.codegen.CodeGenUtil.java
/** * Creates the package folder structure if already not present * * @param packageName String/* ww w .ja v a 2 s . co m*/ * @throws Exception */ public static void createPackage(String rootFolderPath, String packageName) throws Exception { String path = ""; if (!Strings.isNullOrEmpty(packageName)) { path = CharMatcher.anyOf(".").replaceFrom(packageName, "/"); if (!Strings.isNullOrEmpty(rootFolderPath)) { path = rootFolderPath + "/" + path; } logger.info("Generated code will be in folder:{}", path); File file = new File(path); if (!file.exists()) { file.mkdirs(); logger.info("Package structure created:" + path); } else { logger.info("Package structure:{} exists.", path); } } }