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

The following examples show how to use org.apache.commons.lang.StringUtils#splitByWholeSeparatorPreserveAllTokens() . 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: AttributeIndexKey.java    From accumulo-recipes with Apache License 2.0 6 votes vote down vote up
public AttributeIndexKey(Key key) {

        String row = key.getRow().toString();
        String parts[] = StringUtils.splitByWholeSeparatorPreserveAllTokens(row, INDEX_SEP);
        int firstNBIdx = parts[3].indexOf(NULL_BYTE);

        if (row.startsWith(INDEX_V)) {
            int lastNBIdx = parts[3].lastIndexOf(NULL_BYTE);
            this.alias = parts[2];
            this.key = parts[3].substring(0, firstNBIdx);
            this.normalizedValue = parts[3].substring(firstNBIdx + 1, lastNBIdx);
            this.shard = parts[3].substring(lastNBIdx + 1, parts[3].length());
        } else if (row.startsWith(INDEX_K)) {
            this.key = parts[2];
            this.alias = parts[3].substring(0, firstNBIdx);
            this.shard = parts[3].substring(firstNBIdx + 1, parts[3].length());
        }
    }
 
Example 2
Source File: SplitPart.java    From incubator-tajo with Apache License 2.0 6 votes vote down vote up
@Override
public Datum eval(Tuple params) {
  Datum text = params.get(0);
  Datum part = params.get(2);

  if (text.isNull() || part.isNull()) {
    return NullDatum.get();
  }

  String [] split = StringUtils.splitByWholeSeparatorPreserveAllTokens(text.asChars(), params.get(1).asChars(), -1);
  int idx = params.get(2).asInt4() - 1;
  if (split.length > idx) {
    return DatumFactory.createText(split[idx]);
  } else {
    // If part is larger than the number of string portions, it will returns NULL.
    return NullDatum.get();
  }
}
 
Example 3
Source File: StringI18NModel.java    From yes-cart with Apache License 2.0 6 votes vote down vote up
public StringI18NModel(final String raw) {
    if (raw != null && raw.length() > 0) {
        if (raw.contains(SEPARATOR)) {
            final String[] valuePairs = StringUtils.splitByWholeSeparatorPreserveAllTokens(raw, SEPARATOR);
            for (int i = 0; i < valuePairs.length - 1; i += 2) {
                final String key = valuePairs[i];
                final String value = valuePairs[i + 1];
                if (value != null && value.length() > 0) {
                    values.put(key, value);
                }
            }
        } else { // fallback if we have plain value
            values.put(DEFAULT, raw);
        }
    }
}
 
Example 4
Source File: CustomerOrderDetAttributesImpl.java    From yes-cart with Apache License 2.0 6 votes vote down vote up
public CustomerOrderDetAttributesImpl(final String raw) {
    if (raw != null && raw.length() > 0) {
        final String[] valueTriplets = StringUtils.splitByWholeSeparatorPreserveAllTokens(raw, SEPARATOR);
        for (int i = 0; i < valueTriplets.length - 2; i+=3)  {
            final String key = valueTriplets[i];
            final String value = valueTriplets[i + 1];
            final String displayValue = valueTriplets[i + 2];
            if (value != null && value.length() > 0) {
                if (displayValue != null && displayValue.length() > 0) {
                    values.put(key, new Pair<>(value, new StringI18NModel(displayValue)));
                    continue;
                }
                values.put(key, new Pair<>(value, null));
            }
        }
    }
}
 
Example 5
Source File: StoredAttributesDTOImpl.java    From yes-cart with Apache License 2.0 6 votes vote down vote up
public void setStringData(final String raw) {
    if (raw != null && raw.length() > 0) {
        final String[] valueTriplets = StringUtils.splitByWholeSeparatorPreserveAllTokens(raw, SEPARATOR);
        for (int i = 0; i < valueTriplets.length - 2; i+=3)  {
            final String key = valueTriplets[i];
            final String value = valueTriplets[i + 1];
            final String displayValue = valueTriplets[i + 2];
            if (value != null && value.length() > 0) {
                if (displayValue != null && displayValue.length() > 0) {
                    final I18NModel model = new StringI18NModel(displayValue);
                    if (!model.getAllValues().isEmpty()) {
                        values.put(key, new Pair<>(value, model));
                        continue;
                    }
                }
                values.put(key, new Pair<>(value, null));
            }
        }
    }
}
 
Example 6
Source File: RulePojo.java    From fraud-detection-tutorial with Apache License 2.0 5 votes vote down vote up
public RulePojo(String ruleId, String value) {
  this.ruleId = ruleId;

  String[] parts = StringUtils.splitByWholeSeparatorPreserveAllTokens(value, ",");
  sourcePort = parts[0];
  if (sourcePort.isEmpty() || sourcePort.equals("null")) {sourcePort = "";}

  destinationPort = parts[1];
  if (destinationPort.isEmpty() || destinationPort.equals("null")) {destinationPort = "";}

  destinationIp = parts[2];
  if (destinationIp.isEmpty() || destinationIp.equals("null")) {destinationIp = "";}
}
 
Example 7
Source File: SearchableAttributeNumericBase.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
 * Tests that (if the given binaryOperator is present in the valueEntered) the operands are valid.
 *
 * <p>The operand test is done by calling isPassesDefaultValidation.  If the binaryOperator is not present,
 * true is returned.</p>
 *
 * @param valueEntered the string being validated
 * @param binaryOperator the operator to test
 * @return whether the operands are valid for the given binaryOperator
 */
private boolean isOperandsValid(String valueEntered, SearchOperator binaryOperator) {
    if (StringUtils.contains(valueEntered, binaryOperator.op())) {
        // using this split method to make sure we test both sides of the operator.  Using String.split would
        // throw away empty strings, so e.g. "&&100".split("&&") would return an array with one element, ["100"].
        String [] l = StringUtils.splitByWholeSeparatorPreserveAllTokens(valueEntered, binaryOperator.op());
        for(String value : l) {
            if (!isPassesDefaultValidation(value)) {
                return false;
            }
        }
    }

    return true;
}
 
Example 8
Source File: CsvReader.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
private String[] processFirstLine(final String line, final String CSVsep) {
	if (CSVsep != null && !CSVsep.isEmpty()) {
		delimiter = CSVsep.charAt(0);
	} else {
		String[] s = StringUtils.splitByWholeSeparatorPreserveAllTokens(line, ",");
		if (s.length == 1) {
			if (s[0].indexOf(' ') == -1 && s[0].indexOf(';') == -1 && s[0].indexOf(Letters.TAB) == -1) {
				// We are likely dealing with a unicolum file
				delimiter = Letters.COMMA;
			} else {
				// there should be another delimiter
				s = StringUtils.splitByWholeSeparatorPreserveAllTokens(line, ";");
				if (s.length == 1) {
					// Try with tab
					s = StringUtils.splitByWholeSeparatorPreserveAllTokens(line, "" + Letters.TAB);
					if (s.length == 1) {
						s = StringUtils.splitByWholeSeparatorPreserveAllTokens(line, "" + Letters.SPACE);
						if (s.length == 1) {
							delimiter = Letters.PIPE;
						} else {
							delimiter = Letters.SPACE;
						}
					} else {
						delimiter = Letters.TAB;
					}
				} else {
					delimiter = ';';
				}
			}
		} else {
			delimiter = Letters.COMMA;
		}
	}
	final String[] s2 = StringUtils.splitByWholeSeparatorPreserveAllTokens(line, delimiter.toString());
	firstLineType = processRecord(s2);
	return s2;
}
 
Example 9
Source File: ValidateCodeFilter.java    From codeway_service with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 将系统中配置的需要校验验证码的URL根据校验的类型放入map
 * @param urlString
 * @param type
 */
protected void addUrlToMap(String urlString, ValidateCodeType type) {
	if (StringUtils.isNotBlank(urlString)) {
		String[] urls = StringUtils.splitByWholeSeparatorPreserveAllTokens(urlString, ",");
		for (String url : urls) {
			urlMap.put(url, type);
		}
	}
}
 
Example 10
Source File: ConstructAnalysisFileParser.java    From act with GNU General Public License v3.0 5 votes vote down vote up
public void parse(File inFile) throws IOException {
  try (BufferedReader reader = new BufferedReader(new FileReader(inFile))) {

    String line;
    String constructId = null;
    List<ConstructAssociatedChemical> products = null;
    while ((line = reader.readLine()) != null) {
      Matcher matcher = CONSTRUCT_DESIGNATOR_PATTERN.matcher(line);
      if (matcher.matches()) {
        if (constructId != null) {
          handleConstructProductsList(constructId, products);
        }
        constructId = matcher.group(1).trim();
        products = new ArrayList<>();
      } else {
        if (constructId == null || products == null) {
          throw new RuntimeException("Found construct product step line without a pre-defined construct");
        }
        String[] fields = StringUtils.splitByWholeSeparatorPreserveAllTokens(line, PRODUCT_KIND_SEPARATOR);
        if (fields.length != 2) {
          System.err.format("Skipping line with unexpected number of fields (%d): %s\n", fields.length, line);
          continue;
        }
        String chemical = fields[0];
        String kind = fields[1];
        products.add(new ConstructAssociatedChemical(chemical, kind));
      }
    }
    // Finish processing anything that's left over.
    if (constructId != null) {
      handleConstructProductsList(constructId, products);
    }
  }
}
 
Example 11
Source File: ValidateCodeFilter.java    From paascloud-master with Apache License 2.0 5 votes vote down vote up
/**
 * 讲系统中配置的需要校验验证码的URL根据校验的类型放入map
 *
 * @param urlString the url string
 * @param type      the type
 */
private void addUrlToMap(String urlString, ValidateCodeType type) {
	if (StringUtils.isNotBlank(urlString)) {
		String[] urls = StringUtils.splitByWholeSeparatorPreserveAllTokens(urlString, ",");
		for (String url : urls) {
			urlMap.put(url, type);
		}
	}
}
 
Example 12
Source File: QQOAuth2Template.java    From paascloud-master with Apache License 2.0 5 votes vote down vote up
/**
 * Post for access grant access grant.
 *
 * @param accessTokenUrl the access token url
 * @param parameters     the parameters
 *
 * @return the access grant
 */
@Override
protected AccessGrant postForAccessGrant(String accessTokenUrl, MultiValueMap<String, String> parameters) {
	String responseStr = getRestTemplate().postForObject(accessTokenUrl, parameters, String.class);

	log.info("获取accessToke的响应={}", responseStr);

	String[] items = StringUtils.splitByWholeSeparatorPreserveAllTokens(responseStr, "&");

	String accessToken = StringUtils.substringAfterLast(items[0], "=");
	Long expiresIn = new Long(StringUtils.substringAfterLast(items[1], "="));
	String refreshToken = StringUtils.substringAfterLast(items[2], "=");

	return new AccessGrant(accessToken, null, refreshToken, expiresIn);
}
 
Example 13
Source File: ValidateCodeFilter.java    From codeway_service with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 将系统中配置的需要校验验证码的URL根据校验的类型放入map
 * @param urlString
 * @param type
 */
protected void addUrlToMap(String urlString, ValidateCodeType type) {
	if (StringUtils.isNotBlank(urlString)) {
		String[] urls = StringUtils.splitByWholeSeparatorPreserveAllTokens(urlString, ",");
		for (String url : urls) {
			urlMap.put(url, type);
		}
	}
}
 
Example 14
Source File: ValueListAdapter.java    From openhab1-addons with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public String[] unmarshal(String value) throws Exception {
    String[] result = StringUtils.splitByWholeSeparatorPreserveAllTokens(value, ",");
    return (result.length == 0 ? null : result);
}
 
Example 15
Source File: GamaFileMetaData.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
protected String[] split(final String s) {
	return StringUtils.splitByWholeSeparatorPreserveAllTokens(s, DELIMITER);
}
 
Example 16
Source File: ValueListAdapter.java    From openhab1-addons with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public String[] unmarshal(String value) throws Exception {
    String[] result = StringUtils.splitByWholeSeparatorPreserveAllTokens(value, ";");
    return (result.length == 0 ? null : result);
}
 
Example 17
Source File: CcuParamsetDescriptionParser.java    From smarthome with Eclipse Public License 2.0 4 votes vote down vote up
private String[] toOptionList(String options) {
    String[] result = StringUtils.splitByWholeSeparatorPreserveAllTokens(options, ";");
    return result == null || result.length == 0 ? null : result;
}
 
Example 18
Source File: ViewHelperServiceImpl.java    From rice with Educational Community License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
public void processMultipleValueLookupResults(ViewModel model, String collectionId, String collectionPath,
        String multiValueReturnFields, String lookupResultValues) {
    // if no line values returned, no population is needed
    if (StringUtils.isBlank(lookupResultValues) || !(model instanceof ViewModel)) {
        return;
    }

    ViewModel viewModel = (ViewModel) model;

    if (StringUtils.isBlank(collectionId)) {
        throw new RuntimeException(
                "Id is not set for this collection lookup: " + collectionId + ", " + "path: " + collectionPath);
    }

    // retrieve the collection group so we can get the collection class and collection lookup
    Class<?> collectionObjectClass = (Class<?>) viewModel.getViewPostMetadata().getComponentPostData(collectionId,
            UifConstants.PostMetadata.COLL_OBJECT_CLASS);
    Collection<Object> collection = ObjectPropertyUtils.getPropertyValue(model, collectionPath);
    if (collection == null) {
        Class<?> collectionClass = ObjectPropertyUtils.getPropertyType(model, collectionPath);
        collection = (Collection<Object>) KRADUtils.createNewObjectFromClass(collectionClass);
        ObjectPropertyUtils.setPropertyValue(model, collectionPath, collection);
    }

    // get the field conversions
    Map<String, String> fieldConversions =
            (Map<String, String>) viewModel.getViewPostMetadata().getComponentPostData(collectionId,
                    UifConstants.PostMetadata.COLL_LOOKUP_FIELD_CONVERSIONS);

    // filter the field conversions by what was returned from the multi value lookup return fields
    Map <String, String> returnedFieldConversions = filterByReturnedFieldConversions(multiValueReturnFields,
            fieldConversions);

    List<String> toFieldNamesColl = new ArrayList<String>(returnedFieldConversions.values());
    Collections.sort(toFieldNamesColl);
    String[] toFieldNames = new String[toFieldNamesColl.size()];
    toFieldNamesColl.toArray(toFieldNames);

    // first split to get the line value sets
    String[] lineValues = StringUtils.split(lookupResultValues, ",");

    List<Object> lineDataObjects = new ArrayList<Object>();
    // for each returned set create a new instance of collection class and populate with returned line values
    for (String lineValue : lineValues) {
        Object lineDataObject = null;

        // TODO: need to put this in data object service so logic can be reused
        ModuleService moduleService = KRADServiceLocatorWeb.getKualiModuleService().getResponsibleModuleService(
                collectionObjectClass);
        if (moduleService != null && moduleService.isExternalizable(collectionObjectClass)) {
            lineDataObject = moduleService.createNewObjectFromExternalizableClass(collectionObjectClass.asSubclass(
                    org.kuali.rice.krad.bo.ExternalizableBusinessObject.class));
        } else {
            lineDataObject = KRADUtils.createNewObjectFromClass(collectionObjectClass);
        }

        String[] fieldValues = StringUtils.splitByWholeSeparatorPreserveAllTokens(lineValue, ":");
        if (fieldValues.length != toFieldNames.length) {
            throw new RuntimeException(
                    "Value count passed back from multi-value lookup does not match field conversion count");
        }

        // set each field value on the line
        for (int i = 0; i < fieldValues.length; i++) {
            String fieldName = toFieldNames[i];
            ObjectPropertyUtils.setPropertyValue(lineDataObject, fieldName, fieldValues[i]);
        }

        lineDataObjects.add(lineDataObject);
        processAndAddLineObject(viewModel, lineDataObject, collectionId, collectionPath);
    }

    viewModel.getViewPostMetadata().getAddedCollectionObjects().put(collectionId, lineDataObjects);
}
 
Example 19
Source File: IOUtilFunctions.java    From systemds with Apache License 2.0 3 votes vote down vote up
/**
 * Splits a string by a specified delimiter into all tokens, including empty.
 * NOTE: This method is meant as a faster drop-in replacement of the regular 
 * string split.
 * 
 * @param str string to split
 * @param delim delimiter
 * @return string array
 */
public static String[] split(String str, String delim)
{
	//split by whole separator required for multi-character delimiters, preserve
	//all tokens required for empty cells and in order to keep cell alignment
	return StringUtils.splitByWholeSeparatorPreserveAllTokens(str, delim);
}
 
Example 20
Source File: IOUtilFunctions.java    From systemds with Apache License 2.0 3 votes vote down vote up
/**
 * Splits a string by a specified delimiter into all tokens, including empty.
 * NOTE: This method is meant as a faster drop-in replacement of the regular 
 * string split.
 * 
 * @param str string to split
 * @param delim delimiter
 * @return string array
 */
public static String[] split(String str, String delim)
{
	//split by whole separator required for multi-character delimiters, preserve
	//all tokens required for empty cells and in order to keep cell alignment
	return StringUtils.splitByWholeSeparatorPreserveAllTokens(str, delim);
}