Re: please review draft JEP: Convenience Factory Methods for Collections

2014-07-21 Thread Stuart Marks
On 7/18/14 4:41 PM, David M. Lloyd wrote: On 07/18/2014 06:36 PM, Stuart Marks wrote: Map.of() .add(k0, v0) .add(k1, v1) ... .add(kN, vN); this would result in O(N^2) performance and space allocation, though most of the allocated space is garbage.

Re: please review draft JEP: Convenience Factory Methods for Collections

2014-07-21 Thread Stuart Marks
On 7/19/14 2:04 AM, Remi Forax wrote: You can combine these 2 approachesi using a Ruby like builder approach with a lambda, which provide a builder object (so static method call are replaced by instance method call) avoiding the creation of too many entry objects Map.of(b - b

Re: please review draft JEP: Convenience Factory Methods for Collections

2014-07-19 Thread Michael Kay
I don't think we want to have a Map.add(k,v) instance method (or default method) for immutable maps or for constructing them. For a fast, compact, immutable map implementation, the only way to implement Map.add() would be to copy the entire contents plus the additional pair into a new

Re: please review draft JEP: Convenience Factory Methods for Collections

2014-07-19 Thread Remi Forax
On 07/19/2014 01:36 AM, Stuart Marks wrote: On 7/18/14 2:17 AM, Michael Kay wrote: On 18 Jul 2014, at 10:09, Wang Weijun weijun.w...@oracle.com wrote: A .with(k, v) to create a new immutable map with an extra pair. Yes, that's the same as my A.add(k,v) - A proposal. Works whether A is

Re: please review draft JEP: Convenience Factory Methods for Collections

2014-07-18 Thread Michael Kay
Well, Remi had proposed raising the limit. Suppose we offered 7 key-value pairs instead of 5. Would you then complain about having to rewrite your code if you had to add an 8th entry to the map? Yes, I would. In fact, the higher you make the limit, the bigger the surprise when I find I

Re: please review draft JEP: Convenience Factory Methods for Collections

2014-07-18 Thread Wang Weijun
A .with(k, v) to create a new immutable map with an extra pair. --Max On Jul 18, 2014, at 16:11, Michael Kay m...@saxonica.com wrote: Well, Remi had proposed raising the limit. Suppose we offered 7 key-value pairs instead of 5. Would you then complain about having to rewrite your code if

Re: please review draft JEP: Convenience Factory Methods for Collections

2014-07-18 Thread Michael Kay
On 18 Jul 2014, at 10:09, Wang Weijun weijun.w...@oracle.com wrote: A .with(k, v) to create a new immutable map with an extra pair. Yes, that's the same as my A.add(k,v) - A proposal. Works whether A is mutable or immutable. Michael Kay Saxonica

Re: please review draft JEP: Convenience Factory Methods for Collections

2014-07-18 Thread Stuart Marks
On 7/18/14 2:17 AM, Michael Kay wrote: On 18 Jul 2014, at 10:09, Wang Weijun weijun.w...@oracle.com wrote: A .with(k, v) to create a new immutable map with an extra pair. Yes, that's the same as my A.add(k,v) - A proposal. Works whether A is mutable or immutable. I don't think we want to

Re: please review draft JEP: Convenience Factory Methods for Collections

2014-07-18 Thread David M. Lloyd
On 07/18/2014 06:36 PM, Stuart Marks wrote: On 7/18/14 2:17 AM, Michael Kay wrote: On 18 Jul 2014, at 10:09, Wang Weijun weijun.w...@oracle.com wrote: A .with(k, v) to create a new immutable map with an extra pair. Yes, that's the same as my A.add(k,v) - A proposal. Works whether A is

Re: please review draft JEP: Convenience Factory Methods for Collections

2014-07-17 Thread Michael Kay
Set.of() and List.of() look very attractive; Map.of() looks very ugly. I would much prefer to write something like Map.of( Map.pair(key, value), Map.pair(key, value), Map.pair(key, value) ); and have no limit on the number of pairs. (Don't care how it works internally...) The last thing

Re: please review draft JEP: Convenience Factory Methods for Collections

2014-07-17 Thread Tom Hawtin
I note that with the basic proposal, HashSet.of and indeed NavigableSet.of still work. They just do the wrong thing. Tom

Re: please review draft JEP: Convenience Factory Methods for Collections

2014-07-17 Thread Michael Kay
On 17 Jul 2014, at 08:21, Michael Kay m...@saxonica.com wrote: Set.of() and List.of() look very attractive; Map.of() looks very ugly. I would much prefer to write something like Map.of( Map.pair(key, value), Map.pair(key, value), Map.pair(key, value) ); Another style that would

Re: please review draft JEP: Convenience Factory Methods for Collections

2014-07-17 Thread Remi Forax
On 07/17/2014 04:05 AM, Paul Benedict wrote: Regarding why you didn't choose a straight vararg solution, I prefer you do allow any number of key/values as long as you throw an exception if the array is not an even sized. You can not extract/infer the type of the key and the type of the value

Re: please review draft JEP: Convenience Factory Methods for Collections

2014-07-17 Thread Steven Schlansker
On Jul 16, 2014, at 5:46 PM, Stuart Marks stuart.ma...@oracle.com wrote: Hi all, Please review this draft JEP for Convenience Factory Methods for Collections: https://bugs.openjdk.java.net/browse/JDK-8048330 Brief background: several times over the years there have been proposals to

Re: please review draft JEP: Convenience Factory Methods for Collections

2014-07-17 Thread Dan Smith
The motivation section ought to more directly survey what we have now: - Collections.emptyList/emptySet/emptyMap - Collections.singletonList/singleton/singletonMap - Arrays.asList - EnumSet.of (varargs, plus some overloads) - Stream.empty and Stream.of (singleton plus varargs) - Constructors that,

Re: please review draft JEP: Convenience Factory Methods for Collections

2014-07-17 Thread Stuart Marks
On 7/17/14 12:21 AM, Michael Kay wrote: Set.of() and List.of() look very attractive; Map.of() looks very ugly. The proposed Map.of() API offends our sensibilities as programmers, because of its repetition and its lack of generality. I think that's what you mean by ugly. There is a indeed

Re: please review draft JEP: Convenience Factory Methods for Collections

2014-07-17 Thread Stuart Marks
On 7/17/14 12:46 AM, Tom Hawtin wrote: I note that with the basic proposal, HashSet.of and indeed NavigableSet.of still work. They just do the wrong thing. I should have made more clear in the JEP that the proposed APIs are static methods on the List/Map/Set interfaces, not default methods.

Re: please review draft JEP: Convenience Factory Methods for Collections

2014-07-17 Thread Stuart Marks
On 7/17/14 10:17 AM, Steven Schlansker wrote: This is fantastic, I think a large number of developers will cheer as more and more of Guava makes it into core libs :) Great! One thing I notice is that you take a lot of care to not specify how the Map or Set will be implemented. This could

Re: please review draft JEP: Convenience Factory Methods for Collections

2014-07-17 Thread Stuart Marks
Hi Dan, thanks for the feedback. On 7/17/14 10:40 AM, Dan Smith wrote: The motivation section ought to more directly survey what we have now: - Collections.emptyList/emptySet/emptyMap - Collections.singletonList/singleton/singletonMap - Arrays.asList - EnumSet.of (varargs, plus some overloads)

Re: please review draft JEP: Convenience Factory Methods for Collections

2014-07-17 Thread Tom Hawtin
On 17/07/2014 22:56, Stuart Marks wrote: On 7/17/14 12:46 AM, Tom Hawtin wrote: I note that with the basic proposal, HashSet.of and indeed NavigableSet.of still work. They just do the wrong thing. I should have made more clear in the JEP that the proposed APIs are static methods on the

please review draft JEP: Convenience Factory Methods for Collections

2014-07-16 Thread Stuart Marks
Hi all, Please review this draft JEP for Convenience Factory Methods for Collections: https://bugs.openjdk.java.net/browse/JDK-8048330 Brief background: several times over the years there have been proposals to add collection literals to the language. The most recent round of this was in

Re: please review draft JEP: Convenience Factory Methods for Collections

2014-07-16 Thread Remi Forax
On 07/17/2014 02:46 AM, Stuart Marks wrote: Hi all, Please review this draft JEP for Convenience Factory Methods for Collections: https://bugs.openjdk.java.net/browse/JDK-8048330 Brief background: several times over the years there have been proposals to add collection literals to the

Re: please review draft JEP: Convenience Factory Methods for Collections

2014-07-16 Thread Stuart Marks
On 7/16/14 6:03 PM, Remi Forax wrote: On 07/17/2014 02:46 AM, Stuart Marks wrote: Please review this draft JEP for Convenience Factory Methods for Collections: https://bugs.openjdk.java.net/browse/JDK-8048330 Brief background: several times over the years there have been proposals to add

Re: please review draft JEP: Convenience Factory Methods for Collections

2014-07-16 Thread Paul Benedict
Regarding why you didn't choose a straight vararg solution, I prefer you do allow any number of key/values as long as you throw an exception if the array is not an even sized. Cheers, Paul On Wed, Jul 16, 2014 at 8:58 PM, Stuart Marks stuart.ma...@oracle.com wrote: On 7/16/14 6:03 PM, Remi