Java Code Examples for org.apache.commons.lang.StringUtils#splitByWholeSeparator()

The following examples show how to use org.apache.commons.lang.StringUtils#splitByWholeSeparator() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClientValidationUtils.java    From rice with Educational Community License v2.0 6 votes vote down vote up
/**
 * Determines which fields are being evaluated in a boolean statement, so handlers can be
 * attached to them if needed, returns these names in a list.
 * 
 * @param statement statement to parse
 * @return list of field names
 */
private static List<String> parseOutFields(String statement) {
    List<String> fieldNames = new ArrayList<String>();
    String[] splits = StringUtils.splitByWholeSeparator(statement, "coerceValue(");
    for (String s : splits) {
        //must be a coerceValue param and not preceding content from the split, always starts with "'"
        if (!s.startsWith("'")) {
            continue;
        }

        s = s.substring(1);
        String fieldName = StringUtils.substringBefore(s, "'");
        //Only add field name once for this condition check
        if (!fieldNames.contains(fieldName)) {
            fieldNames.add(fieldName);
        }

    }
    return fieldNames;
}
 
Example 2
Source File: PortBinding.java    From haven-platform with Apache License 2.0 6 votes vote down vote up
public static PortBinding parse(String serialized) throws IllegalArgumentException {
    try {
        String[] parts = StringUtils.splitByWholeSeparator(serialized, ":");
        switch (parts.length) {
            case 3:
                // 127.0.0.1:80:8080/tcp
                return createFromSubstrings(parts[0] + ":" + parts[1], parts[2]);
            case 2:
                // 80:8080 // 127.0.0.1::8080
                return createFromSubstrings(parts[0], parts[1]);
            case 1:
                // 8080
                return createFromSubstrings("", parts[0]);
            default:
                throw new IllegalArgumentException();
        }
    } catch (Exception e) {
        throw new IllegalArgumentException("Error parsing PortBinding '" + serialized + "'", e);
    }
}
 
Example 3
Source File: DateUtils.java    From yes-cart with Apache License 2.0 6 votes vote down vote up
private static Instant iParse(final String datetime, final DateTimeFormatter formatter) {

        if (StringUtils.isNotBlank(datetime)) {
            final String[] instant = StringUtils.splitByWholeSeparator(datetime, INSTANT_COMMENT);
            final long time = NumberUtils.toLong(instant[0]);
            if (time > 0L) {
                return Instant.ofEpochMilli(time);
            } else {
                LOG.warn("Using date time for Instant conversion");
                try {
                    TemporalAccessor temporalAccessor = formatter.parseBest(datetime, LocalDateTime::from, LocalDate::from);
                    if (temporalAccessor instanceof LocalDateTime) {
                        return ((LocalDateTime) temporalAccessor).atZone(zone()).toInstant();
                    }
                    return ((LocalDate) temporalAccessor).atStartOfDay(zone()).toInstant();
                } catch (Exception exp) {
                    LOG.error("Unable to parse date {} using formatter {}", datetime, formatter);
                    LOG.error(exp.getMessage(), exp);
                }
            }
        }
        return null;

    }
 
Example 4
Source File: CreateZkNodeHandler.java    From DBus with Apache License 2.0 5 votes vote down vote up
@Override
public void process() {
    //遍历检查或创建 所有在monitor里面的ZK 节点
    Set<MonitorNodeVo> nodes = HeartBeatConfigContainer.getInstance().getMonitorNodes();
    for (MonitorNodeVo node : nodes) {
        String[] dsPartitions = StringUtils.splitByWholeSeparator(node.getDsPartition(), ",");
        for (String partition : dsPartitions) {
            String path = HeartBeatConfigContainer.getInstance().getHbConf().getMonitorPath();
            path = StringUtils.join(new String[]{path, node.getDsName(), node.getSchema(), node.getTableName(), partition}, "/");
            CuratorContainer.getInstance().createZkNode(path);
        }
    }
}
 
Example 5
Source File: KimTypeAttributesHelper.java    From rice with Educational Community License v2.0 5 votes vote down vote up
public String getCommaDelimitedAttributesLabels(String commaDelimitedAttributesNamesList){
	String[] names = StringUtils.splitByWholeSeparator(commaDelimitedAttributesNamesList, KimConstants.KimUIConstants.COMMA_SEPARATOR);
	StringBuffer commaDelimitedAttributesLabels = new StringBuffer();
	for(String name: names){
		commaDelimitedAttributesLabels.append(getAttributeEntry().get(name.trim())+KimConstants.KimUIConstants.COMMA_SEPARATOR);
	}
       if(commaDelimitedAttributesLabels.toString().endsWith(KimConstants.KimUIConstants.COMMA_SEPARATOR))
       	commaDelimitedAttributesLabels.delete(commaDelimitedAttributesLabels.length()- KimConstants.KimUIConstants.COMMA_SEPARATOR.length(), commaDelimitedAttributesLabels.length());
       return commaDelimitedAttributesLabels.toString();
}
 
Example 6
Source File: IdentityManagementTypeAttributeTransactionalDocument.java    From rice with Educational Community License v2.0 5 votes vote down vote up
public String getCommaDelimitedAttributesLabels(String commaDelimitedAttributesNamesList){
	String[] names = StringUtils.splitByWholeSeparator(commaDelimitedAttributesNamesList, KimConstants.KimUIConstants.COMMA_SEPARATOR);
	List<String> commaDelimitedAttributesLabels = new ArrayList<String>(names.length);
	for(String name: names){
	    Object attributeEntry = getAttributeEntry().get(name.trim());
	    if ( attributeEntry != null ) {
	        commaDelimitedAttributesLabels.add( attributeEntry.toString() );
	    }
	}
       return StringUtils.join(commaDelimitedAttributesLabels, KimConstants.KimUIConstants.COMMA_SEPARATOR);
}
 
Example 7
Source File: LookupUtils.java    From rice with Educational Community License v2.0 5 votes vote down vote up
public static Set<String> convertStringOfObjectIdsToSet(String objectIdsString) {
    Set<String> set = new HashSet<String>();

    if (StringUtils.isNotBlank(objectIdsString)) {
        String[] objectIds = StringUtils.splitByWholeSeparator(objectIdsString, KRADConstants.MULTIPLE_VALUE_LOOKUP_OBJ_IDS_SEPARATOR);
        for (String objectId : objectIds) {
            set.add(objectId);
        }
    }
    return set;
}
 
Example 8
Source File: LaunchContainerRunnable.java    From attic-apex-core with Apache License 2.0 5 votes vote down vote up
public static void addFilesToLocalResources(LocalResourceType type, String commaSeparatedFileNames, Map<String, LocalResource> localResources, FileSystem fs) throws IOException
{
  String[] files = StringUtils.splitByWholeSeparator(commaSeparatedFileNames, StramClient.LIB_JARS_SEP);
  for (String file : files) {
    final Path dst = new Path(file);
    addFileToLocalResources(dst.getName(), fs.getFileStatus(dst), type, localResources);
  }
}
 
Example 9
Source File: VoIOSupportImpl.java    From yes-cart with Apache License 2.0 5 votes vote down vote up
static byte[] getByteArray(final String base64) {
    final String[] parts = StringUtils.splitByWholeSeparator(base64, ";base64,");
    if (parts != null) {
        if (parts.length == 1) {
            return Base64.decodeBase64(parts[0]);
        } else if (parts.length == 2) {
            return Base64.decodeBase64(parts[1]);
        }
    }
    return null;
}
 
Example 10
Source File: RedisCenterImpl.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
/**
 * 处理redis统计信息
 *
 * @param statResult 统计结果串
 */
private Map<RedisConstant, Map<String, Object>> processRedisStats(String statResult) {
    Map<RedisConstant, Map<String, Object>> redisStatMap = new HashMap<RedisConstant, Map<String, Object>>();
    String[] data = statResult.split("\r\n");
    String key;
    int i = 0;
    int length = data.length;
    while (i < length) {
        if (data[i].contains("#")) {
            int index = data[i].indexOf('#');
            key = data[i].substring(index + 1);
            ++i;
            RedisConstant redisConstant = RedisConstant.value(key.trim());
            if (redisConstant == null) {
                continue;
            }
            Map<String, Object> sectionMap = new LinkedHashMap<String, Object>();
            while (i < length && data[i].contains(":")) {
                String[] pair = StringUtils.splitByWholeSeparator(data[i], ":");
                sectionMap.put(pair[0], pair[1]);
                i++;
            }
            redisStatMap.put(redisConstant, sectionMap);
        } else {
            i++;
        }
    }
    return redisStatMap;
}
 
Example 11
Source File: DataTools.java    From util4j with Apache License 2.0 5 votes vote down vote up
/**
 * 根据字节数组拆分若干个字字节数组
 * @param data
 * @param separator
 * @return
 */
public byte[][] getsonArrays(byte[] data,byte[] separator)
{
	if(data==null||data.length<=0||separator==null||separator.length<=0)
	{
		System.out.println("data||separator数据无效!");
		return null;
	}
	String[] dataHexArray=byteArrayToHexArray(data);
	String dataHexStr=StringUtils.substringBetween(Arrays.toString(dataHexArray), "[", "]").replaceAll("\\s","");
	//System.out.println("待拆分字符串:"+dataHexStr);
	String[] separatorHexhArray=byteArrayToHexArray(separator);
	String separatorHexStr=StringUtils.substringBetween(Arrays.toString(separatorHexhArray), "[", "]").replaceAll("\\s","");
	//System.out.println("字符串拆分符:"+separatorHexStr);
	//得到拆分后的数组
	String[] arrays=StringUtils.splitByWholeSeparator(dataHexStr, separatorHexStr);
	//System.out.println("拆分后的数组:"+Arrays.toString(arrays));
	if(arrays==null||arrays.length<=0)
	{
		System.out.println("注意:数组拆分为0");
		return null;
	}
	byte[][] result=new byte[arrays.length][];
	//对子数组进行重组
	for(int i=0;i<arrays.length;i++)
	{
		String arrayStr=arrays[i];
		arrayStr=StringUtils.removeStart(arrayStr, ",");//去掉两端的逗号
		arrayStr=StringUtils.removeEnd(arrayStr, ",");//去掉两端的逗号
		String[] array=arrayStr.split(",");//根据子字符串中间剩余的逗号重组为hex字符串
		result[i]=hexArrayToBtyeArray(array);
	}
	return result;
}
 
Example 12
Source File: HexStrBytes.java    From util4j with Apache License 2.0 5 votes vote down vote up
/**
 * 根据字节数组拆分若干个字字节数组
 * @param data    待拆分数组
 * @param separator 分割数组
 * @return 
 */
public byte[][] getSonArrays(byte[] data,byte[] separator)
{
	if(data==null||data.length<=0||separator==null||separator.length<=0)
	{
		System.out.println("data||separator数据无效!");
		return null;
	}
	String[] dataHexArray=toHexArray(data);
	String dataHexStr=StringUtils.substringBetween(Arrays.toString(dataHexArray), "[", "]").replaceAll("\\s","");
	//System.out.println("待拆分字符串:"+dataHexStr);
	String[] separatorHexhArray=toHexArray(separator);
	String separatorHexStr=StringUtils.substringBetween(Arrays.toString(separatorHexhArray), "[", "]").replaceAll("\\s","");
	//System.out.println("字符串拆分符:"+separatorHexStr);
	//得到拆分后的数组
	String[] arrays=StringUtils.splitByWholeSeparator(dataHexStr, separatorHexStr);
	//System.out.println("拆分后的数组:"+Arrays.toString(arrays));
	if(arrays==null||arrays.length<=0)
	{
		System.out.println("注意:数组拆分为0");
		return null;
	}
	byte[][] result=new byte[arrays.length][];
	//对子数组进行重组
	for(int i=0;i<arrays.length;i++)
	{
		String arrayStr=arrays[i];
		arrayStr=StringUtils.removeStart(arrayStr, ",");//去掉两端的逗号
		arrayStr=StringUtils.removeEnd(arrayStr, ",");//去掉两端的逗号
		String[] array=arrayStr.split(",");//根据子字符串中间剩余的逗号重组为hex字符串
		result[i]=toBtyeArray(array);
	}
	return result;
}
 
Example 13
Source File: LaunchContainerRunnable.java    From Bats with Apache License 2.0 5 votes vote down vote up
public static void addFilesToLocalResources(LocalResourceType type, String commaSeparatedFileNames, Map<String, LocalResource> localResources, FileSystem fs) throws IOException
{
  String[] files = StringUtils.splitByWholeSeparator(commaSeparatedFileNames, StramClient.LIB_JARS_SEP);
  for (String file : files) {
    final Path dst = new Path(file);
    addFileToLocalResources(dst.getName(), fs.getFileStatus(dst), type, localResources);
  }
}
 
Example 14
Source File: StringUtil.java    From smart-framework with Apache License 2.0 4 votes vote down vote up
/**
 * 分割固定格式的字符串
 */
public static String[] splitString(String str, String separator) {
    return StringUtils.splitByWholeSeparator(str, separator);
}
 
Example 15
Source File: StringUtil.java    From springdream with Apache License 2.0 4 votes vote down vote up
/**
 * 分割固定格式的字符串
 */
public static String[] splitString(String str, String separator) {
    return StringUtils.splitByWholeSeparator(str, separator);
}
 
Example 16
Source File: StringUtil.java    From smart-framework with Apache License 2.0 4 votes vote down vote up
/**
 * 分割固定格式的字符串
 */
public static String[] splitString(String str, String separator) {
    return StringUtils.splitByWholeSeparator(str, separator);
}
 
Example 17
Source File: AbstractEvent.java    From DBus with Apache License 2.0 4 votes vote down vote up
@Override
public void run() {
    List<DsVo> dsVos = HeartBeatConfigContainer.getInstance().getDsVos();
    Set<MonitorNodeVo> nodes = HeartBeatConfigContainer.getInstance().getMonitorNodes();
    long txTime = 0l;
    while (isRun.get()) {
        try {
            if (isRun.get()) {
                if (this instanceof EmitHeartBeatEvent) {
                    heartBeatCnt++;
                    txTime = System.currentTimeMillis();
                    LOG.info("[control-event] {} 心跳次数:{}.", dsName, heartBeatCnt);
                }
                for (DsVo ds : dsVos) {
                    if (this instanceof EmitHeartBeatEvent) {
                        if (DbusDatasourceType.stringEqual(ds.getType(), DbusDatasourceType.LOG_LOGSTASH)
                                || DbusDatasourceType.stringEqual(ds.getType(), DbusDatasourceType.LOG_LOGSTASH_JSON)
                                || DbusDatasourceType.stringEqual(ds.getType(), DbusDatasourceType.LOG_UMS)
                                // || DbusDatasourceType.stringEqual(ds.getType(), DbusDatasourceType.MONGO)
                                || DbusDatasourceType.stringEqual(ds.getType(), DbusDatasourceType.LOG_FILEBEAT)
                                || DbusDatasourceType.stringEqual(ds.getType(), DbusDatasourceType.LOG_JSON)
                                || DbusDatasourceType.stringEqual(ds.getType(), DbusDatasourceType.LOG_FLUME)) {
                            LOG.info(ds.getType() + ",Ignored!");
                            countDown(ds.getKey());
                            continue;
                        }
                    }

                    // 用于实现一个数据源一个线程插入心跳
                    if (StringUtils.isNotBlank(dsName) &&
                            !StringUtils.equalsIgnoreCase(dsName, ds.getKey())) {
                        continue;
                    }

                    for (MonitorNodeVo node : nodes) {
                        //快速退出
                        if (!isRun.get())
                            break;

                        if (!StringUtils.equals(ds.getKey(), node.getDsName()))
                            continue;

                        String[] dsPartitions = StringUtils.splitByWholeSeparator(node.getDsPartition(), ",");
                        for (String partition : dsPartitions) {
                            String path = HeartBeatConfigContainer.getInstance().getHbConf().getMonitorPath();
                            path = StringUtils.join(new String[]{path, node.getDsName(), node.getSchema(), node.getTableName(), partition}, "/");
                            if (this instanceof EmitHeartBeatEvent) {
                                fire(ds, node, path, txTime);
                            } else if (this instanceof CheckHeartBeatEvent) {
                                cdl.await();
                                if (StringUtils.equalsIgnoreCase("dbus", node.getSchema())) {
                                    // 数据源增加别名后,dbus schema如果同时存在于两个数据源中,会导致启动一个数据源的dbus schema报警
                                    // eg. db8_sec.dbus和db8_rsc.dbus
                                    // 所以暂时忽略掉所有dbus schema的报警检查
                                    continue;
                                }
                                String key = StringUtils.join(new String[]{node.getDsName(), node.getSchema()}, "/");
                                if (StringUtils.isBlank(EventContainer.getInstances().getSkipSchema(key))) {
                                    fire(ds, node, path, txTime);
                                } else {
                                    LOG.warn("[control-event] schema:{},正在拉取全量,{}不进行监控.", key, node.getTableName());
                                }
                            }
                        }
                    }

                    countDown(ds.getKey());

                }
            }
            sleep(interval, TimeUnit.SECONDS);
        } catch (Exception e) {
            LOG.error("[control-event]", e);
        }
    }
}
 
Example 18
Source File: SearchExpressionUtils.java    From rice with Educational Community License v2.0 4 votes vote down vote up
public static String[] parseBinaryOperatorValues(SearchOperator operator, String expression) {
    return StringUtils.splitByWholeSeparator(expression.trim(), operator.op(), 2);
}