DaveAKing / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

Allow MapJoiner to transform the Entry keys #1470

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Allow the joiner to perform transformations on the Map keys during the join. 
Something like the withKeyTransformer method below.

Usage example:
Map<X, Y> map;
System.out.println(Joiner
   .on(';')
   .withKeyValueSeparator("=")
   .withKeyTransformer(new Function<X,String>() {
         public String apply(X val) {
           return String.valueOf(x);
         }
   })
   .join(map));

You could do something similar with value and entries, but that functionality 
already exists using the Maps.transform(Values|Entries) util functions so not 
important except for symmetry.

Original issue reported on code.google.com by mkraiz...@gmail.com on 5 Jul 2013 at 3:31

GoogleCodeExporter commented 9 years ago
Is this that much better than doing

   Joiner.on(';').join(Iterables.transform(map.entrySet(), 
      new Function<Entry<X, Y>, String>() {
        ...
      }
    );

?

Original comment by lowas...@google.com on 8 Aug 2013 at 10:38

GoogleCodeExporter commented 9 years ago
You could, but it doesn't flow with the API of Joiner. Why go through the 
trouble of entering entry and value transformers to the API and omit the key?

Original comment by mkraiz...@gmail.com on 9 Aug 2013 at 1:47

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<issue id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:12

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:17

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:08