public static String[] arraySplit(String s, char separatorChar) { return arraySplit(s, separatorChar, true); }
public static int[] arraySplitAsInt(String s, char separatorChar) { String[] array = arraySplit(s, separatorChar, true); if (array == null) return null; int[] intArray = new int[array.length]; for (int i = 0; i < array.length; i++) { intArray[i] = Integer.parseInt(array[i]); } return intArray; }
public SimpleSeedProvider(Map<String, String> parameters) { // 允许包含端口号 String[] hosts = StringUtils.arraySplit(parameters.get("seeds"), ','); List<NetEndpoint> seeds = new ArrayList<>(hosts.length); for (String host : hosts) { try { seeds.add(NetEndpoint.createP2P(host)); } catch (Exception ex) { // not fatal... DD will bark if there end up being zero seeds. logger.warn("Seed provider couldn't lookup host {}", host); } } this.seeds = Collections.unmodifiableList(seeds); }
/** * Convert a String to a map. * * @param s the string * @return the map */ public static SortedProperties fromLines(String s) { SortedProperties p = new SortedProperties(); for (String line : StringUtils.arraySplit(s, '\n', true)) { int idx = line.indexOf('='); if (idx > 0) { p.put(line.substring(0, idx), line.substring(idx + 1)); } } return p; }
@Override public String[] getHostIds() { if (hostIds == null) { synchronized (this) { if (hostIds == null) { if (parameters != null && parameters.containsKey("hostIds")) { targetEndpoints = parameters.get("hostIds").trim(); hostIds = StringUtils.arraySplit(targetEndpoints, ','); } if (hostIds == null) { hostIds = new String[0]; endpoints = null; } else { endpoints = new HashSet<>(hostIds.length); for (String id : hostIds) { endpoints.add(NetEndpoint.createTCP(id)); } } if (endpoints != null && endpoints.isEmpty()) { endpoints = null; } if (targetEndpoints != null && targetEndpoints.isEmpty()) targetEndpoints = null; } } } return hostIds; }
String settings = url.substring(idx + 1); url = url.substring(0, idx); // 去掉后面的参数 String[] list = StringUtils.arraySplit(settings, splitChar, false); for (String setting : list) { if (setting.isEmpty()) {
String[] hostIds = StringUtils.arraySplit(configOptions.get("host_id_list"), ','); for (String hostId : hostIds) { NetEndpoint e = metaData.getEndpoint(hostId);
boolean allowAll = false; HashSet<String> classNames = new HashSet<>(); for (String p : StringUtils.arraySplit(s, ',', true)) { if (p.equals("*")) { allowAll = true;
private String getFunctions(String section) throws SQLException { try { checkClosed(); PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT TOPIC " + "FROM INFORMATION_SCHEMA.HELP WHERE SECTION = ?"); prep.setString(1, section); ResultSet rs = prep.executeQuery(); StatementBuilder buff = new StatementBuilder(); while (rs.next()) { String s = rs.getString(1).trim(); String[] array = StringUtils.arraySplit(s, ',', true); for (String a : array) { buff.appendExceptFirst(","); String f = a.trim(); if (f.indexOf(' ') >= 0) { // remove 'Function' from 'INSERT Function' f = f.substring(0, f.indexOf(' ')).trim(); } buff.append(f); } } rs.close(); prep.close(); return buff.toString(); } catch (Exception e) { throw logAndConvert(e); } }
private void rewriteSql(boolean toReplicationMode) { if (session.isRoot()) { oldHostIds = db.getHostIds(); if (parameters != null && parameters.containsKey("hostIds")) { newHostIds = StringUtils.arraySplit(parameters.get("hostIds"), ',', true); } else { if (toReplicationMode) newHostIds = NetEndpointManagerHolder.get().getReplicationEndpoints(db); else newHostIds = NetEndpointManagerHolder.get().getShardingEndpoints(db); } String hostIds = StringUtils.arrayCombine(oldHostIds, ',') + "," + StringUtils.arrayCombine(newHostIds, ','); db.getParameters().put("hostIds", hostIds); rewriteSql(); } else { if (super.isTargetEndpoint(db)) { oldHostIds = db.getHostIds(); HashSet<String> oldSet = new HashSet<>(Arrays.asList(oldHostIds)); if (parameters != null && parameters.containsKey("hostIds")) { String[] hostIds = StringUtils.arraySplit(parameters.get("hostIds"), ',', true); HashSet<String> newSet = new HashSet<>(Arrays.asList(hostIds)); newSet.removeAll(oldSet); newHostIds = newSet.toArray(new String[0]); } else { DbException.throwInternalError(); } } } }
Map<String, String> parameters = db.getParameters(); newHostIds = StringUtils.arraySplit(parameters.get("hostIds"), ',', true); HashSet<String> set; String localHostId = NetEndpoint.getLocalTcpEndpoint().getHostAndPort(); if (parameters != null && parameters.containsKey("removeHostIds")) { removeHostIds = StringUtils.arraySplit(parameters.get("removeHostIds"), ',', true); set = new HashSet<>(Arrays.asList(removeHostIds)); if (set.contains(localHostId)) {
DataUtils.checkArgument(initReplicationEndpoints != null, "The initReplicationEndpoints may not be null"); String[] replicationEndpoints = StringUtils.arraySplit(initReplicationEndpoints, '&'); if (containsLocalEndpoint(replicationEndpoints)) { root = BTreeLeafPage.createEmpty(this);
String[] keyValuePairs = StringUtils.arraySplit(options, ' ', false); for (String pair : keyValuePairs) { if (pair.length() == 0) {
Map<String, String> parameters = db.getParameters(); if (parameters != null && parameters.containsKey("removeHostIds")) { removeHostIds = StringUtils.arraySplit(parameters.get("removeHostIds"), ',', true); HashSet<String> set = new HashSet<>(Arrays.asList(removeHostIds)); NetEndpoint localEndpoint = NetEndpoint.getLocalTcpEndpoint();
InetSocketAddress inetSocketAddress = null; ClientSession clientSession = null; String[] servers = StringUtils.arraySplit(ci.getServers(), ',', true); Random random = new Random(System.currentTimeMillis()); try { if (getRunMode() == RunMode.REPLICATION) { ConnectionInfo ci = this.ci; servers = StringUtils.arraySplit(getTargetEndpoints(), ',', true); int size = servers.length; ClientSession[] sessions = new ClientSession[size];
String[] columns = StringUtils.arraySplit(columnList, fieldSeparator, true); ResultSet rs = null; ValueResultSet x;
String[] columns = StringUtils.arraySplit(columnList, fieldSeparator, true); try { ValueResultSet vr = ValueResultSet.get(csv.read(fileName, columns, charset));