0

I'm attempting to familiarize myself with lambdaj, and am unsure how the best way to solve this problem. Given the following test:

@Test
public void test() {
  final List<String> l1 = new ArrayList<>();
  final List<String> l2 = new ArrayList<>();

  l1.add("same");
  l1.add("Upper");
  l1.add("lower");

  l2.add("same");
  l2.add("upper");
  l2.add("lower");
  l2.add("extra");

  final List<String> l3 = Lambda.filter(Matchers.not(Matchers.isIn(l1)), l2);
  Assert.assertThat("There should be one item in l3", l3.size(), Matchers.equalTo(1));
}

How can I make the Matcher not care about case? i.e. I want a list of the items in l2 which are not in l1 irrespective of case? I'd prefer to not have to run another Lambda to convert each list of strings to the same case, but instead a way to modify the Matcher to do as I wish. Is this possible or do I have to convert the items to the same case first?

Scott
  • 9,458
  • 7
  • 54
  • 81

2 Answers2

0

This works for me:

import static org.hamcrest.text.IsEqualIgnoringCase.equalToIgnoringCase;
//..
List<String> allJedis = asList("Luke","Obiwan","Yoda");
List<String> someJedis = filter(equalToIgnoringCase("obiwan"), allJedis);
System.out.println(someJedis);

Output is [Obiwan]

Edwin Dalorzo
  • 76,803
  • 25
  • 144
  • 205
  • That works for a single element, but not for the multi-list in the question (which are dynamic), I just created the smallest reproducible test case for the question. – Scott Jun 13 '12 at 20:17
0

Hope this answer could help you:

    List<String> convert = convert(list1, new Converter<String, String>() {
        @Override
        public String convert(String from) {
            return from.toLowerCase();
        }
    });
    List<String> filter2 = filter(isIn(list2), convert);

    System.out.println("filter2 -> " + filter2);
    // filter2 -> [same, upper, lower]
Jake iOS
  • 1
  • 1