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

The following examples show how to use org.apache.commons.lang3.StringUtils#chop() . 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: sample-timesheets   File: Task.java    License: Apache License 2.0 6 votes vote down vote up
@MetaProperty(related = {"defaultTags"})
public String getDefaultTagsList() {
    if (!PersistenceHelper.isLoaded(this, "defaultTags")) {
        return null;
    }

    if (defaultTags != null) {
        StringBuilder stringBuilder = new StringBuilder();
        for (Tag defaultTag : defaultTags) {
            stringBuilder.append(defaultTag.getInstanceName()).append(",");
        }
        return StringUtils.chop(stringBuilder.toString());
    }

    return "";
}
 
Example 2
Source Project: sample-timesheets   File: Task.java    License: Apache License 2.0 6 votes vote down vote up
@MetaProperty(related = {"requiredTagTypes"})
public String getRequiredTagTypesList() {
    if (!PersistenceHelper.isLoaded(this, "requiredTagTypes")) {
        return null;
    }

    if (requiredTagTypes != null) {
        StringBuilder stringBuilder = new StringBuilder();
        for (TagType requiredTagType : requiredTagTypes) {
            stringBuilder.append(requiredTagType.getInstanceName()).append(",");
        }
        return StringUtils.chop(stringBuilder.toString());
    }

    return "";
}
 
Example 3
Source Project: metron   File: StringFunctions.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Object apply(List<Object> strings) {

  if(strings == null || strings.size() == 0 ) {
    throw new IllegalArgumentException("[CHOP] missing argument: string to be chopped");
  }
  String var = strings.get(0) == null?null: (String) strings.get(0);
  if(var == null) {
    return null;
  }
  else if(var.length() == 0) {
    return var;
  }
  else {
    return StringUtils.chop(var);
  }
}
 
Example 4
Source Project: incubator-pinot   File: ThirdEyeUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static String getSortedFiltersFromMultiMap(Multimap<String, String> filterMultiMap) {
  Set<String> filterKeySet = filterMultiMap.keySet();
  ArrayList<String> filterKeyList = new ArrayList<String>(filterKeySet);
  Collections.sort(filterKeyList);

  StringBuilder sb = new StringBuilder();
  for (String filterKey : filterKeyList) {
    ArrayList<String> values = new ArrayList<String>(filterMultiMap.get(filterKey));
    Collections.sort(values);
    for (String value : values) {
      sb.append(filterKey);
      sb.append(FILTER_VALUE_ASSIGNMENT_SEPARATOR);
      sb.append(value);
      sb.append(FILTER_CLAUSE_SEPARATOR);
    }
  }
  return StringUtils.chop(sb.toString());
}
 
Example 5
/**
 * For each string lines we trim them to avoid whitespace issue when comparing strings
 */
private String trimEachLines(String string) {
    String[] lines = string.split(System.lineSeparator());
    StringBuilder sb = new StringBuilder();
    for (String line : lines) {
        sb.append(StringUtils.trim(line)).append(System.lineSeparator());
    }
    return StringUtils.chop(sb.toString());
}
 
Example 6
/**
 * Return a Set of
 */
private void readyAnnotationDataCache(){

	//Map<String,String> idToInit = new HashMap<String,String>();
	//Map<String,Set<String>> initToId = new HashMap<String,Set<String>>();

	// Parse down every annotation line.
	//for( String aLine : treeAnns. ){
	for( int ti = 0; ti < treeAnns.length; ti++){

		String aLine = treeAnns[ti];

		// First, get rid of the terminal semicolon.
		String cleanALine = StringUtils.chop(aLine);

		// Split out the sections.
		String[] sections = StringUtils.split(cleanALine, "|");
		if( sections.length != 3 ) throw new Error("Expected three sections in " + treeID);

		// Isolate the initial internal identifier and map it to a node.
		String initSection = sections[0];
		String rawNodeID = StringUtils.substringBefore(initSection, ":");
		String nodeID = uuidInternal(rawNodeID);

		// Isolate and convert the rest. This is done as individuals
		// And not a loop for now to higlight the fact that I think this will become
		// rather more complicated later on.
		String rawIdentifierOne = sections[1];
		String rawIdentifierTwo = sections[2];
		String oneID = StringUtils.replaceChars(rawIdentifierOne, '=', ':');
		String twoID = StringUtils.replaceChars(rawIdentifierTwo, '=', ':');

		// // Now make a map from the initial identitifer to the other two, the other
		// two to the identifier, and a batch Set for the existence of just the
		// other two.
		//
		// String finalInitID = uuidInternal(initID);
		// Existence.
		annotationSet.add(oneID);
		annotationSet.add(twoID);
		//LOG.info("groupSet in: " + oneID);
		//LOG.info("groupSet in: " + twoID);

		// Create the gp -> node map.
		gpToNodeMap.put(oneID, nodeID);
		gpToNodeMap.put(twoID, nodeID);

		// Create the node -> gp map.
		Set<String> gps = null;
		if( nodeToGpMap.containsKey(nodeID) ){
			gps = nodeToGpMap.get(nodeID);
		}else{
			gps = new HashSet<String>();
		}
		gps.add(oneID);
		gps.add(twoID);
		nodeToGpMap.put(nodeID, gps);
	}

	//LOG.info("N->GP" + StringUtils.join(nodeToGpMap, ", "));
	//LOG.info("GP->N" + StringUtils.join(gpToNodeMap, ", "));
}
 
Example 7
private String getMailboxName(ZipEntry current) {
    return StringUtils.chop(current.getName());
}
 
Example 8
@Test
public void delete_last_char_apache() {
	
	String phrase = "level up lunch";
	
	String rephrase = StringUtils.chop(phrase);
	
	assertEquals("level up lunc", rephrase);
}
 
Example 9
Source Project: java-sdk   File: WatsonServiceUnitTest.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Gets the mock web server url.
 *
 * @return the server url
 */
protected String getMockWebServerUrl() {
  return StringUtils.chop(server.url("/").toString());
}