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

The following examples show how to use org.apache.commons.lang3.StringUtils#splitByWholeSeparator() . These examples are extracted from open source projects. 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 Project: genie   File: H2Utils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Split the existing command executable on any whitespace characters and insert them into the
 * {@code command_executable_arguments} table in order.
 * <p>
 * See: {@code src/main/resources/db/migration/h2/V4_0_0__Genie_4.sql} for usage
 *
 * @param con The database connection to use
 * @throws Exception On Error
 */
public static void splitV3CommandExecutableForV4(final Connection con) throws Exception {
    try (
        PreparedStatement commandsQuery = con.prepareStatement(V3_COMMAND_EXECUTABLE_QUERY);
        PreparedStatement insertCommandArgument = con.prepareStatement(V4_COMMAND_ARGUMENT_SQL);
        ResultSet rs = commandsQuery.executeQuery()
    ) {
        while (rs.next()) {
            final long commandId = rs.getLong(V3_COMMAND_ID_INDEX);
            final String executable = rs.getString(V3_COMMAND_EXECUTABLE_INDEX);
            final String[] arguments = StringUtils.splitByWholeSeparator(executable, null);
            if (arguments.length > 0) {
                insertCommandArgument.setLong(V4_COMMAND_ID_INDEX, commandId);
                for (int i = 0; i < arguments.length; i++) {
                    insertCommandArgument.setString(V4_COMMAND_ARGUMENT_INDEX, arguments[i]);
                    insertCommandArgument.setInt(V4_COMMAND_ARGUMENT_ORDER_INDEX, i);
                    insertCommandArgument.executeUpdate();
                }
            }
        }
    }
}
 
Example 2
Source Project: joyqueue   File: AppName.java    License: Apache License 2.0 6 votes vote down vote up
public static AppName parse(String fullName) {
    if (fullName == null || fullName.isEmpty()) {
        return null;
    }

    AppName appName = APP_NAME_CACHE.get(fullName);
    if (appName == null) {
        if (APP_NAME_CACHE.size() > APP_NAME_CACHE_SIZE) {
            APP_NAME_CACHE.clear();
        }
        String[] splits = StringUtils.splitByWholeSeparator(fullName, APP_SEPARATOR_SPLIT);
        if (splits.length == 1) {
            appName = new AppName(splits[0]);
        } else {
            appName = new AppName(splits[0], splits[1]);
        }
        APP_NAME_CACHE.put(fullName, appName);
    }
    return appName;
}
 
Example 3
Source Project: PeonyFramwork   File: SplitUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static Integer[] splitToInt(String str, String spStr) {
    if (str == null || str.trim().length() == 0) {
        return new Integer[0];
    }

    try {
        String[] temps = StringUtils.splitByWholeSeparator(str, spStr);
        int len = temps.length;
        Integer[] results = new Integer[len];
        for (int i = 0; i < len; i++) {
            if (temps[i].trim().length() == 0) {
                continue;
            }
            results[i] = Integer.parseInt(temps[i].trim());
        }
        return results;
    } catch (Exception e) {
        return new Integer[0];
    }
}
 
Example 4
Source Project: datacollector   File: OffsetQueryUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * This is the inverse of {@link #getSourceKeyOffsetsRepresentation(Map)}.
 *
 * @param offsets the String representation of source key offsets
 * @return the {@link Map} of the offsets reconstructed from the supplied representation
 */
public static Map<String, String> getOffsetsFromSourceKeyRepresentation(String offsets) {
  final Map<String, String> offsetMap = new HashMap<>();
  if (StringUtils.isNotBlank(offsets)) {
    for (String col : StringUtils.splitByWholeSeparator(offsets, OFFSET_KEY_COLUMN_SEPARATOR)) {
      final String[] parts = StringUtils.splitByWholeSeparator(col, OFFSET_KEY_COLUMN_NAME_VALUE_SEPARATOR, 2);

      if (parts.length != 2) {
        throw new IllegalArgumentException(String.format(
            "Invalid column offset of \"%s\" seen.  Expected colName%svalue.  Full offsets representation: %s",
            col,
            OFFSET_KEY_COLUMN_NAME_VALUE_SEPARATOR,
            offsets
        ));
      }

      offsetMap.put(parts[0], parts[1]);
    }
  }
  return offsetMap;
}
 
Example 5
@Override
public void onMessage(String channel, String message) {
	super.onMessage(channel, message);
	if(StringUtils.isBlank(message)){
		return;
	}
	String[] parts = StringUtils.splitByWholeSeparator(message, SPLIT_STR);
	String lockName = parts[0];
	String nextEventId = parts[1];
	if(!nextEventId.startsWith(EVENT_NODE_ID)){
		return;
	}
	getGetLockEventIds(lockName).add(nextEventId);
}
 
Example 6
Source Project: vscrawler   File: SplitByWholeSeparator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected String[] split(String str, String separatorChars, int max, boolean preserveAllTokens) {
    if (preserveAllTokens) {
        return StringUtils.splitByWholeSeparatorPreserveAllTokens(str, separatorChars, max);
    } else {
        return StringUtils.splitByWholeSeparator(str, separatorChars, max);
    }
}
 
Example 7
Source Project: joyqueue   File: KafkaClientHelper.java    License: Apache License 2.0 5 votes vote down vote up
public static String parseClient(String clientId) {
    clientId = doParseClient(clientId);
    if (StringUtils.contains(clientId, AUTH_SEPARATOR)) {
        String[] strings = StringUtils.splitByWholeSeparator(clientId, AUTH_SEPARATOR);
        clientId = strings[0];
    }
    return clientId;
}
 
Example 8
Source Project: PeonyFramwork   File: SplitUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static <T> RangeValueList convertContentToRangeList(String content, String separator1, String separator2, String separator3, Class<T> tClass) {
    List<RangeValueEntry<T>> tempList = Lists.newArrayList();
    String[] rangeEntryStrArray = StringUtils.splitByWholeSeparator(content, separator1);
    for (String rangeEntryStr : rangeEntryStrArray) {
        String[] rangeEntryKeyValuleStrArray = StringUtils.splitByWholeSeparator(rangeEntryStr, separator2);
        String[] rangeEntryKeyStrArray = StringUtils.splitByWholeSeparator(rangeEntryKeyValuleStrArray[0], separator3);
        RangeValueEntry<T> rangeEntry = new RangeValueEntry<T>(Integer.parseInt(rangeEntryKeyStrArray[0]), Integer.parseInt(rangeEntryKeyStrArray[1]),
                convert(tClass, rangeEntryKeyValuleStrArray[1]));
        tempList.add(rangeEntry);
    }
    return new RangeValueList(tempList);
}
 
Example 9
Source Project: joyqueue   File: KafkaClientHelper.java    License: Apache License 2.0 5 votes vote down vote up
public static String parseToken(String clientId) {
    clientId = doParseClient(clientId);
    if (StringUtils.contains(clientId, AUTH_SEPARATOR)) {
        String[] strings = StringUtils.splitByWholeSeparator(clientId, AUTH_SEPARATOR);
        return strings[1];
    }
    return null;
}
 
Example 10
Source Project: Mario   File: RoleController.java    License: Apache License 2.0 5 votes vote down vote up
@RequestMapping(value = "update", method = RequestMethod.POST)
public String update(@Valid Role role, BindingResult result,
        @RequestParam(value = "menuIds", defaultValue = "") String menuIds, Model model,
        RedirectAttributes redirectAttributes) {
    if (result.hasErrors()) {
        role.setMenuList(accountService.getMenuByRoleID(role.getId()));

        List<Menu> menus = accountService.getAllMenu();

        model.addAttribute("role", role);
        model.addAttribute("action", "update");
        model.addAttribute("allMenus", menus);
        return "account/roleForm";
    }

    //add menu tree list
    role.getMenuList().clear();
    String[] ids = StringUtils.splitByWholeSeparator(menuIds, ",");
    for (String id : ids) {
        Menu menu = new Menu(Long.valueOf(id));
        role.getMenuList().add(menu);
    }

    accountService.saveRole(role);

    resetUserMenu();
    redirectAttributes.addFlashAttribute("message", "保存角色成功");
    return "redirect:/account/role";
}
 
Example 11
Source Project: gocd   File: P4OutputParser.java    License: Apache License 2.0 5 votes vote down vote up
Modification modificationFromDescription(String output, ConsoleResult result) throws P4OutputParseException {
    String[] parts = StringUtils.splitByWholeSeparator(output, SEPARATOR);
    Pattern pattern = Pattern.compile(DESCRIBE_OUTPUT_PATTERN, Pattern.MULTILINE);
    Matcher matcher = pattern.matcher(parts[0]);
    if (matcher.find()) {
        Modification modification = new Modification();
        parseFistline(modification, matcher.group(1), result);
        parseComment(matcher, modification);
        parseAffectedFiles(parts, modification);
        return modification;
    }
    throw new P4OutputParseException("Could not parse P4 description: " + output);
}
 
Example 12
Source Project: bean-query   File: StringSelector.java    License: Apache License 2.0 5 votes vote down vote up
private PropertySelector createPropertySelector(String propertyString) {
  String[] propertyTokens = StringUtils.splitByWholeSeparator(propertyString, " as ", 2);
  final PropertySelector propertySelector;
  String propertySelectorPropertyName = propertyTokens[0].trim();
  if (propertyTokens.length == 2) {
    String propertySelectorAlias = propertyTokens[1].trim();
    propertySelector = new PropertySelector(propertySelectorPropertyName, propertySelectorAlias);
  } else {
    propertySelector = new PropertySelector(propertySelectorPropertyName);
  }
  return propertySelector;
}
 
Example 13
Source Project: PeonyFramwork   File: SplitUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static <K, V> Map<K, V> convertContentToLinkedMap(String content, String separator1, String separator2, Class<K> kClass, Class<V> vClass) {
    Map<K, V> ret = new LinkedHashMap<>();
    if (StringUtils.isBlank(content)) {
        return ret;
    }
    String[] entryArray = StringUtils.splitByWholeSeparator(content, separator1);
    for (String entry : entryArray) {
        String[] keyValueArray = StringUtils.splitByWholeSeparator(entry, separator2);
        if (keyValueArray.length != 2) {
            throw new ConfigException("convertContentToMap err content=" + content);
        }
        ret.put(convert(kClass, keyValueArray[0]), convert(vClass, keyValueArray[1]));
    }
    return ret;
}
 
Example 14
Source Project: jeesuite-libs   File: NetworkUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static boolean telnet(String hostAndPort, int timeoutMilliseconds) {
	String[] parts = StringUtils.splitByWholeSeparator(StringUtils.splitByWholeSeparator(hostAndPort, ",")[0], ":");
	if (parts.length != 2 || !StringUtils.isNumeric(parts[1])) {
		throw new IllegalArgumentException("Argument error, format as [127.0.0.1:3306]");
	}
	return telnet(parts[0], Integer.parseInt(parts[1]), timeoutMilliseconds);
}
 
Example 15
private static String checkAndReturnOffsetTermValue(String term, String name, int position, String fullOffsetKey) {
  final String[] parts = StringUtils.splitByWholeSeparator(term, OFFSET_KEY_VALUE_SEPARATOR, 2);
  Utils.checkState(parts.length == 2, String.format(
      "Illegal offset term for %s (position %d separated by %s).  Should be in form %s%s<value>.  Full offset: %s",
      name,
      position,
      OFFSET_TERM_SEPARATOR,
      name,
      OFFSET_KEY_VALUE_SEPARATOR,
      fullOffsetKey
  ));
  return parts[1];
}
 
Example 16
Source Project: PeonyFramwork   File: SplitUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static <V1, V2, V3> List<Tuple3<V1, V2, V3>> convertContentToTuple3List(String content, String separator1, String separator2, Class<V1> classV1, Class<V2> classV2, Class<V3> classV3) {
    List<Tuple3<V1, V2, V3>> ret = new LinkedList<>();
    if (StringUtils.isBlank(content)) {
        return ImmutableList.copyOf(ret);
    }

    String[] entryArray = StringUtils.splitByWholeSeparator(content, separator1);
    for (String entry : entryArray) {
        Tuple3 e = convertContentToTuple3(entry, separator2, classV1, classV2, classV3);
        ret.add(e);
    }

    return ImmutableList.copyOf(ret);
}
 
Example 17
Source Project: onetwo   File: AESCaptchaChecker.java    License: Apache License 2.0 4 votes vote down vote up
private String[] splitContent(byte[] dencryptData) {
	String content = LangUtils.newString(dencryptData);
	return StringUtils.splitByWholeSeparator(content, ":");
}
 
Example 18
private Predicate<StorageAsset> getArtifactFileFilterFromSelector( final ItemSelector selector )
{
    Predicate<StorageAsset> p = StorageAsset::isLeaf;
    StringBuilder fileNamePattern = new StringBuilder( "^" );
    if ( selector.hasArtifactId( ) )
    {
        fileNamePattern.append( Pattern.quote( selector.getArtifactId( ) ) ).append( "-" );
    }
    else
    {
        fileNamePattern.append( "[A-Za-z0-9_\\-.]+-" );
    }
    if ( selector.hasArtifactVersion( ) )
    {
        if ( selector.getArtifactVersion( ).contains( "*" ) )
        {
            String[] tokens = StringUtils.splitByWholeSeparator( selector.getArtifactVersion( ), "*" );
            for ( String currentToken : tokens )
            {
                if ( !currentToken.equals( "" ) )
                {
                    fileNamePattern.append( Pattern.quote( currentToken ) );
                }
                fileNamePattern.append( "[A-Za-z0-9_\\-.]*" );
            }
        }
        else
        {
            fileNamePattern.append( Pattern.quote( selector.getArtifactVersion( ) ) );
        }
    }
    else
    {
        fileNamePattern.append( "[A-Za-z0-9_\\-.]+" );
    }
    String classifier = selector.hasClassifier( ) ? selector.getClassifier( ) :
        ( selector.hasType( ) ? MavenContentHelper.getClassifierFromType( selector.getType( ) ) : null );
    if ( classifier != null )
    {
        if ( "*".equals( classifier ) )
        {
            fileNamePattern.append( "(-[A-Za-z0-9]+)?\\." );
        }
        else
        {
            fileNamePattern.append( "-" ).append( Pattern.quote( classifier ) ).append( "\\." );
        }
    }
    else
    {
        fileNamePattern.append( "\\." );
    }
    String extension = selector.hasExtension( ) ? selector.getExtension( ) :
        ( selector.hasType( ) ? MavenContentHelper.getArtifactExtension( selector ) : null );
    if ( extension != null )
    {
        if ( selector.includeRelatedArtifacts( ) )
        {
            fileNamePattern.append( Pattern.quote( extension ) ).append( "(\\.[A-Za-z0-9]+)?" );
        }
        else
        {
            fileNamePattern.append( Pattern.quote( extension ) );
        }
    }
    else
    {
        fileNamePattern.append( "[A-Za-z0-9.]+" );
    }
    final Pattern pattern = Pattern.compile( fileNamePattern.toString( ) );
    return p.and( a -> pattern.matcher( a.getName( ) ).matches( ) );
}
 
Example 19
@RequestMapping(value = "grant_permissions", method = RequestMethod.POST)
public ResponseEntity<WrapperResponseEntity> gantPermission(@RequestBody GantPermRequest param){
	SecurityUtil.requireSuperAdmin();
	if(param.getPermissions() == null || param.getPermissions().isEmpty()){
		throw new JeesuiteBaseException(1001, "至少选择一个应用权限");
	}
	if(param.getUserId() == 0 || StringUtils.isBlank(param.getEnv())){
		throw new JeesuiteBaseException(1001, "参数[userId,env]必填");
	}
	List<UserPermissionEntity> oldPermissons = userPermissionMapper.findByUserIdAndEnv(param.getUserId(),param.getEnv());
	List<UserPermissionEntity> newPermissons = new ArrayList<>(param.getPermissions().size()); 
	Integer appId;String grantOper;
	for (String  perm : param.getPermissions()) {
		String[] tmpArrays = StringUtils.splitByWholeSeparator(perm, ":");
		appId = Integer.parseInt(tmpArrays[0]);
		grantOper = tmpArrays[1];
		newPermissons.add(new UserPermissionEntity(param.getUserId(),param.getEnv(), appId,grantOper));
	}
	List<UserPermissionEntity> addList;
	List<UserPermissionEntity> removeList = null;
	if(!oldPermissons.isEmpty()){
		addList = new ArrayList<>(newPermissons);
		addList.removeAll(oldPermissons);
		removeList = new ArrayList<>(oldPermissons);
		removeList.removeAll(newPermissons);
	}else{
		addList = newPermissons;
	}
	
	if(!addList.isEmpty()){
		userPermissionMapper.insertList(addList);
	}
	
       if(removeList != null && !removeList.isEmpty()){
           for (UserPermissionEntity entity : removeList) {
           	userPermissionMapper.deleteByPrimaryKey(entity.getId());
		}
	}
	
	return new ResponseEntity<WrapperResponseEntity>(new WrapperResponseEntity(true),HttpStatus.OK);
}
 
Example 20
/**
 * 将得到值与指定分割符号,分割,得到数组
 *  
 * @param value 值
 * @param type 值类型
 * 
 * @return Object
 */
public Object convertMatchValue(String value, Class<?> type) {
	Assert.notNull(value,"值不能为空");
	String[] result = StringUtils.splitByWholeSeparator(value, getAndValueSeparator());
	
	return  ConvertUtils.convertToObject(result,type);
}