Java Code Examples for org.apache.commons.collections4.CollectionUtils#transform()

The following examples show how to use org.apache.commons.collections4.CollectionUtils#transform() . 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: JavaTransformTest.java    From java_in_examples with Apache License 2.0 5 votes vote down vote up
private static void transformTest() {
    Collection<String> collection = Lists.newArrayList("a1", "a2", "a3", "a1");
    Iterable<String> iterable = collection;
    Collection<String> apache = Lists.newArrayList(collection);
    MutableCollection<String> mutableCollection = FastList.newList(collection);

    // Transform all elements
    List<String> jdk = collection.stream().map((s) -> s + "_1").collect(Collectors.toList()); // using jdk
    Iterable<String> guava = Iterables.transform(iterable, (s) -> s + "_1"); // using guava
    CollectionUtils.transform(apache, (s) -> s + "_1"); // using apache
    MutableCollection<String> gs = mutableCollection.collect((s) -> s + "_1");  // using gs
    System.out.println("transform = " + jdk + ":" + guava + ":" + apache + ":" + gs); // print transform = [a1_1, a2_1, a3_1, a1_1]:[a1_1, a2_1, a3_1, a1_1]:[a1_1, a2_1, a3_1, a1_1]:[a1_1, a2_1, a3_1, a1_1]
}
 
Example 2
Source File: JavaTransformTest.java    From java_in_examples with Apache License 2.0 5 votes vote down vote up
private static void changeAllTest() {
    Collection<StringBuilder> jdk = Lists.newArrayList(new StringBuilder("a1"), new StringBuilder("a2"), new StringBuilder("a3"));
    Iterable<StringBuilder> iterable = Lists.newArrayList(new StringBuilder("a1"), new StringBuilder("a2"), new StringBuilder("a3"));;
    Collection<StringBuilder> apache = Lists.newArrayList(new StringBuilder("a1"), new StringBuilder("a2"), new StringBuilder("a3"));
    MutableCollection<StringBuilder> gs = FastList.newListWith(new StringBuilder("a1"), new StringBuilder("a2"), new StringBuilder("a3"));

    // Change property of all elements
    jdk.stream().forEach((s) -> s.append("_1")); // using jdk
    Iterable<StringBuilder> guava = Iterables.transform(iterable, (s) -> s.append("_1")); // using guava
    CollectionUtils.transform(apache, (s) -> s.append("_1")); // using apache
    gs.forEach((Procedure<StringBuilder>) (s) -> s.append("_1"));  // using gs

    System.out.println("change = " + jdk + ":" + guava + ":" + apache + ":" + gs); // print changeAll = [a1_1, a2_1, a3_1]:[a1_1, a2_1, a3_1]:[a1_1, a2_1, a3_1]:[a1_1, a2_1, a3_1]
}
 
Example 3
Source File: JavaTransformTest.java    From java_in_examples with Apache License 2.0 5 votes vote down vote up
private static void transformTest() {
    Collection<String> collection = Lists.newArrayList("a1", "a2", "a3", "a1");
    Iterable<String> iterable = collection;
    Collection<String> apache = Lists.newArrayList(collection);
    MutableCollection<String> mutableCollection = FastList.newList(collection);

    // Изменение всех элементов коллекции
    List<String> jdk = collection.stream().map((s) -> s + "_1").collect(Collectors.toList()); // с помощью jdk
    Iterable<String> guava = Iterables.transform(iterable, (s) -> s + "_1"); // с помощью guava
    CollectionUtils.transform(apache, (s) -> s + "_1"); // с помощью apache
    MutableCollection<String> gs = mutableCollection.collect((s) -> s + "_1");  // с помощью gs
    System.out.println("transform = " + jdk + ":" + guava + ":" + apache + ":" + gs); // напечатает transform = [a1_1, a2_1, a3_1, a1_1]:[a1_1, a2_1, a3_1, a1_1]:[a1_1, a2_1, a3_1, a1_1]:[a1_1, a2_1, a3_1, a1_1]
}
 
Example 4
Source File: JavaTransformTest.java    From java_in_examples with Apache License 2.0 5 votes vote down vote up
private static void changeAllTest() {
    Collection<StringBuilder> jdk = Lists.newArrayList(new StringBuilder("a1"), new StringBuilder("a2"), new StringBuilder("a3"));
    Iterable<StringBuilder> iterable = Lists.newArrayList(new StringBuilder("a1"), new StringBuilder("a2"), new StringBuilder("a3"));;
    Collection<StringBuilder> apache = Lists.newArrayList(new StringBuilder("a1"), new StringBuilder("a2"), new StringBuilder("a3"));
    MutableCollection<StringBuilder> gs = FastList.newListWith(new StringBuilder("a1"), new StringBuilder("a2"), new StringBuilder("a3"));

    // Изменение свойства каждого элемента коллекции
    jdk.stream().forEach((s) -> s.append("_1")); // с помощью jdk
    Iterable<StringBuilder> guava = Iterables.transform(iterable, (s) -> s.append("_1")); // с помощью guava
    CollectionUtils.transform(apache, (s) -> s.append("_1")); // с помощью apache
    gs.forEach((Procedure<StringBuilder>) (s) -> s.append("_1"));  // с помощью gs

    System.out.println("change = " + jdk + ":" + guava + ":" + apache + ":" + gs); // напечатает changeAll = [a1_1, a2_1, a3_1]:[a1_1, a2_1, a3_1]:[a1_1, a2_1, a3_1]:[a1_1, a2_1, a3_1]
}
 
Example 5
Source File: GnuDemanglerParser.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private static Pattern createOverloadedOperatorNamePattern() {

		// note: the order of these matters--the single characters must come after the 
		//       multi-character entries; otherwise, the single characters will match before
		//       longer matches
		//@formatter:off
		List<String> operators = new LinkedList<>(List.of(			
			"++", "--",
			">>=", "<<=",
			"->*", "->",
			"==", "!=", ">=", "<=",
			"&&", "||", ">>", "<<",
			"+=", "-=", "*=", "/=", "%=", "&=", "|=", "^=", 
			"+", "-", "*", "/", "%",
			"~", "^", "&", "|", "!", "<", ">", "=",			
			",", "()"
		));
		//@formatter:on

		CollectionUtils.transform(operators, Pattern::quote);
		String alternated = StringUtils.join(operators, "|");

		//
		// We have some extra 'operator' style constructs to add to the normal operator overloading
		// 
		// User Defined Literal 
		// Sample: operator"" _init(char const*, unsigned long)  
		//        
		// Pattern: operator"" _someText(opeartor_params)
		// 
		String userDefinedLiteral = "\"\"\\s_.+";
		String extra = userDefinedLiteral;
		alternated += '|' + extra;

		String operatorTemplates = "(<.+>){0,1}";
		String operatorPrefix =
			".*(.*" + OPERATOR + "(" + alternated + ")\\s*" + operatorTemplates + ".*)\\s*";
		String parameters = "(\\(.*\\))";
		String trailing = "(.*)";

		return Pattern.compile(operatorPrefix + parameters + trailing);
	}