I am maintaining a tree of some sort. The generic tree node has this form:
public class Node {
private String s;
private ReadWriteLock sLock; //read on.
private List<Node> descendants;
private ReadWriteLock descLock; //read on.
}
I am trying to map it to a NodeDTO class having about the same structure, except the nested collection is of type List too:
public class NodeDTO {
private String s;
private List<NodeDTO> descendants;
}
The ModelMapper library offers a default map(src-obj, dest-class)
method which works fine for many use-cases. However, given the risk for race-conditions, I would like to override the mapping function to take and release the locks during the mapping operation.
- Primary question: if I write a custom
PropertyMap
, should I map all the levels by myself down to the leaves (as each descendant node may have descendants of its own), or will it suffice to return a list that maps the first level of descendants while setting the descendant nodes for each element in that list to an empty list, and the library will do the rest? (Even without lambda expressions. This is the point I'm most interested in) Secondary question (not a problem if this is not answered): the documentation reads that it is possible to use lambda expressions to override the mapping. However, I haven't been able to produce a working code of the form:
map(src-> { [lock - read value - unlock] / return value;}, (dest, retVal) -> { [operations setting the returned value] })
Which is what I am looking for.