Closed GoogleCodeExporter closed 9 years ago
Why not use Map<String, Optional<?>> instead:
ImmutableMap.<String, Optional<?>> builder()
.put("obj1", Optional.fromNullable(couldBeNull))
.build();
Original comment by christof...@vimond.com
on 29 Apr 2013 at 5:56
The conditional I add is only to give an example, but with the signature I
suggest it could be any condition (in my case the conditions wasn't a not null
condition). I aggre the optional solves the not null but I think the suggest
method has more uses
Original comment by luizcc...@gmail.com
on 29 Apr 2013 at 6:07
There has to be a point of diminishing returns, where pushing an operation into
a builder just isn't worthwhile anymore. Could you explain why you think that
conditions are under that cutoff? (Most builders I've seen in other contexts
don't have this sort of thing.)
Original comment by lowas...@google.com
on 29 Apr 2013 at 6:09
Hi,
I think it's better if I give other example:
private Map<Property,Object> propertiesToChange(
final Entity1 entity1,
final Entity2 entity2,
final Entity3 entity3 )
{
final Builder<Property,Object> paramsBuilder = ImmutableMap.<Property,Object> builder().put(
Property.ENTITY2, entity2.getId() );
if( ! entity3.equals( entity1.getEntity3() ) ) {
paramsBuilder.put( Property.ENTITY3, entity3.getId() );
}
return paramsBuilder.build();
}
Original comment by luizcc...@gmail.com
on 29 Apr 2013 at 6:20
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
Original comment by cgdecker@google.com
on 1 Nov 2014 at 4:18
Original comment by cgdecker@google.com
on 3 Nov 2014 at 9:08
Original issue reported on code.google.com by
luizcc...@gmail.com
on 29 Apr 2013 at 1:10