Map > backmap = new HashMap() įor (Map.Entry entry : barToFoo. The streaming API is a nice thing, but in this case it might not be providing you with the simplest solution. As always, the examples in this article are available over on GitHub. These methods help us to get mapped objects by applying the provided mapping function. We can invoke them on Streams and Optionals. However, you could generate a generalized inverse if you relaxed the typing to an almost-inverse: Map x They missed a step in this example, the addMappings method they use is the addMappings from TypeMap, not from ModelMapper.You need to define a TypeMap for your 2 objects. Java 8 gives us the opportunity to use the map() and flatMap() methods that originally were used in functional languages. This means that Maps, in general are not invertible. So the inverse function would have to do f'(0) = 0 (the zero's are swapped compared to the above example)į'(1) = 1 or -1 (sorry, but that's not valid output for a function) So a map that takes keys of A and provides values of B looks like f(A) -> Bīut there are many maps where one cannot write it's inverse and have the inverse still be a function f'(B) -> A (only exists for some functions) There are a few issues with this, the first being that a mathematical Map (sometimes represented as a function) is not guaranteed to be a mathematical Identity (which is a fancy way of saying the function has an inverse function). It seems that you want a reverse map, or a map where each value points back to it's key. toMap() return a Collector which produces a new instance of Map, populated with keys per provided keyMapper function and values per provided valueMap function.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |