Re: Make iterators cloneable?
>> Iterators reading from a BufferedReader yes that's true. altho given the contract of Cloneable, adding the clone method on Iterator would be safe, as it would only be available if the real implementing class 'extends Cloneable'... it's actually kind of funny that Object methods aren't available on interface references, anyway. But i get the "age of Iterator" answer.. Shame there isn't an answer, tho. thanks, dave On 09/10/2016 07:44 PM, Louis Wasserman wrote: Some iterators might be. Many may not be. Certainly Iterator as an interface has been out there for long enough there are Iterator implementations out there that aren't cloneable -- say, Iterators reading from a BufferedReader, where there really won't be any way to do what you're hoping for; BufferedReaders certainly aren't cloneable. On Sat, Sep 10, 2016 at 4:33 PM Dave Brosius> wrote: Yes Louis is correct. I want the pair wise associations or all elements of a set. Fee-Fi Fee-Fo Fee-Fum Fi-Fo Fi-Fum Fo-Fum the independent iterators produce Fee-Fee (etc) as well as the duplicate Fee-Fi and Fi-Fee (etc), both of which i don't want. This is obviously simplistic with index based collections, but not with sets/maps I don't see why an Iterator isn't by nature easily cloneable. On 09/10/2016 06:45 PM, Jonathan Bluett-Duncan wrote: Ah okay Louis, if that's the case then that certainly makes sense, and I'd agree that there's no good way of doing so, as one would need to copy the set into a list. Dave, did Louis hit the mark? If not, would you kindly go into further detail as to exactly what it is you're trying to do? Best, Jonathan On 10 September 2016 at 23:36, Jonathan Bluett-Duncan > wrote: Hi Dave, Rather than using Iterator.clone(), how about you just call collection.iterator() 2 times to return 2 unique, non-same iterators; something like the following: import java.util.Collections; import java.util.Iterator; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; public class Example {public static void main(String[] args) { Set s = Collections.newSetFromMap(new ConcurrentHashMap ()); s.add("Fee"); s.add("Fi"); s.add("Fo"); s.add("Fum"); Iterator it1 = s.iterator(); for (String v1 =null; it1.hasNext(); v1 =it1.next()) { Iterator it2 = s.iterator();// a completely separate iterator to it1 for (String v2 =null; it2.hasNext(); v2 = it2.next()) {System.out.println(v1 + " <-->" + v2); } } } } Or, even better, if you're using Java 5+, you can skip using Iterators altogether and use for-loops directly: import java.util.Collections; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; public class Example {public static void main(String[] args) { Set s = Collections.newSetFromMap(new ConcurrentHashMap ()); s.add("Fee"); s.add("Fi"); s.add("Fo"); s.add("Fum"); for (String v1 : s) { for (String v2 : s) {System.out.println(v1 + "<-->" + v2); } } } } Kind regards, Jonathan On 10 September 2016 at 23:13, Dave Brosius > wrote: It would be nice to be able to associate each element in a collection with another element in the collection, which is something very easily done with index based collections, but with sets, etc this isn't so easy... unless i'm having a brainfart. So i'd like to do this, but Iterator doesn't implement Cloneable... Any reason not to? or is there another way that's missing me? public class ItClone { public static void main(String[] args) { Set s = Collections.newSetFromMap(new ConcurrentHashMap ()); s.add("Fee"); s.add("Fi"); s.add("Fo"); s.add("Fum"); Iterator it1 = s.iterator(); while (it1.hasNext()) { String v1 = it1.next(); Iterator it2 = (Iterator) it1.*clone*(); while (it2.hasNext()) { String v2 = it2.next(); System.out.println(v1 + " <-->" + v2); } } } }
Re: [PATCH] JDK-8134373: explore potential uses of convenience factories within the JDK
Sorry, it seems Gmail is not cooperating with me... If anyone does need to see the patches in-body, then I'd be happy to inline them directly in a reply, but that wouldn't be ideal since there are 18 of them in total... :/ On 11 September 2016 at 00:54, Jonathan Bluett-Duncan < jbluettdun...@gmail.com> wrote: > Oops, it didn't fully register for me that I actually needed to include > attachments in the body! So here they are again, this time in the body > (hopefully). >
Re: [PATCH] JDK-8134373: explore potential uses of convenience factories within the JDK
Oops, it didn't fully register for me that I actually needed to include attachments in the body! So here they are again, this time in the body (hopefully).
Re: Make iterators cloneable?
Some iterators might be. Many may not be. Certainly Iterator as an interface has been out there for long enough there are Iterator implementations out there that aren't cloneable -- say, Iterators reading from a BufferedReader, where there really won't be any way to do what you're hoping for; BufferedReaders certainly aren't cloneable. On Sat, Sep 10, 2016 at 4:33 PM Dave Brosiuswrote: > Yes Louis is correct. > > I want the pair wise associations or all elements of a set. > > Fee-Fi > > Fee-Fo > > Fee-Fum > > Fi-Fo > > Fi-Fum > > Fo-Fum > > > the independent iterators produce Fee-Fee (etc) as well as the duplicate > Fee-Fi and Fi-Fee (etc), both of which i don't want. > > > This is obviously simplistic with index based collections, but not with > sets/maps > > I don't see why an Iterator isn't by nature easily cloneable. > > > > On 09/10/2016 06:45 PM, Jonathan Bluett-Duncan wrote: > > Ah okay Louis, if that's the case then that certainly makes sense, and I'd > agree that there's no good way of doing so, as one would need to copy the > set into a list. > > Dave, did Louis hit the mark? If not, would you kindly go into further > detail as to exactly what it is you're trying to do? > > Best, > Jonathan > > On 10 September 2016 at 23:36, Jonathan Bluett-Duncan < > jbluettdun...@gmail.com> wrote: > > Hi Dave, > > Rather than using Iterator.clone(), how about you just call > collection.iterator() 2 times to return 2 unique, non-same iterators; > something like the following: > > import java.util.Collections;import java.util.Iterator;import > java.util.Set;import java.util.concurrent.ConcurrentHashMap; > public class Example { > public static void main(String[] args) { > Set s = Collections.newSetFromMap(new ConcurrentHashMap Boolean>()); > > s.add("Fee"); > s.add("Fi"); > s.add("Fo"); > s.add("Fum"); > > Iterator it1 = s.iterator();for (String v1 = null; > it1.hasNext(); v1 =it1.next()) { > Iterator it2 = s.iterator(); // a completely separate iterator > to it1 for (String v2 = null; it2.hasNext(); v2 = it2.next()) { > System.out.println(v1 + " <-->" + v2); > } > } > } > } > > Or, even better, if you're using Java 5+, you can skip using Iterators > altogether and use for-loops directly: > > import java.util.Collections;import java.util.Set;import > java.util.concurrent.ConcurrentHashMap; > public class Example { > public static void main(String[] args) { > Set s = Collections.newSetFromMap(new ConcurrentHashMap Boolean>()); > > s.add("Fee"); > s.add("Fi"); > s.add("Fo"); > s.add("Fum"); > for (String v1 : s) { > for (String v2 : s) { > System.out.println(v1 + "<-->" + v2); > } > } > } > } > > Kind regards, > Jonathan > On 10 September 2016 at 23:13, Dave Brosius > wrote: > > It would be nice to be able to associate each element in a collection with > another element in the collection, which is something very easily done with > index based collections, but with sets, etc this isn't so easy... unless > i'm having a brainfart. So i'd like to do this, but Iterator doesn't > implement Cloneable... Any reason not to? or is there another way that's > missing me? public class ItClone { public static void main(String[] > args) { Set s = Collections.newSetFromMap(new > ConcurrentHashMap ()); s.add("Fee"); > s.add("Fi"); s.add("Fo"); s.add("Fum"); > Iterator it1 = s.iterator(); while (it1.hasNext()) { > String v1 = it1.next(); Iterator it2 = > (Iterator) it1.*clone*(); while (it2.hasNext()) { > String v2 = it2.next(); System.out.println(v1 + " > <-->" + v2); } } } } > >
[PATCH] JDK-8134373: explore potential uses of convenience factories within the JDK
Hi all, Would you kindly review this patch to replace existing uses of Collections.unmodifiable*(*Arrays.asList(*)) and plain Arrays.asList(*) with (List|Set|Map).of(*). You may find the patch files in the attachments. My rationale for replacing uses of Collections.unmodifiable*... with (List|Set|Map).of is to make use of the memory savings allowed by the newer APIs. The general rationale for replacing the Arrays.asList calls I've touched is to again make use of memory savings, but this may be naive or misguided reasoning on my part, as Arrays.asList may or may not be more memory-efficient than List.of. However, where I've replaced Arrays.asList for List.of in FileTreeIterator, my reasoning for doing so instead was to help prevent TOCTOU attacks, but again this may be misguided on my part. It doesn't seem practical to me to include new unit tests, as these are mainly performance improvements, but if it's believed that new unit tests are needed, then I'd be happy to go back and try to include some. Kind regards, Jonathan
Re: Make iterators cloneable?
Yes Louis is correct. I want the pair wise associations or all elements of a set. Fee-Fi Fee-Fo Fee-Fum Fi-Fo Fi-Fum Fo-Fum the independent iterators produce Fee-Fee (etc) as well as the duplicate Fee-Fi and Fi-Fee (etc), both of which i don't want. This is obviously simplistic with index based collections, but not with sets/maps I don't see why an Iterator isn't by nature easily cloneable. On 09/10/2016 06:45 PM, Jonathan Bluett-Duncan wrote: Ah okay Louis, if that's the case then that certainly makes sense, and I'd agree that there's no good way of doing so, as one would need to copy the set into a list. Dave, did Louis hit the mark? If not, would you kindly go into further detail as to exactly what it is you're trying to do? Best, Jonathan On 10 September 2016 at 23:36, Jonathan Bluett-Duncan> wrote: Hi Dave, Rather than using Iterator.clone(), how about you just call collection.iterator() 2 times to return 2 unique, non-same iterators; something like the following: import java.util.Collections; import java.util.Iterator; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; public class Example {public static void main(String[] args) { Set s = Collections.newSetFromMap(new ConcurrentHashMap ()); s.add("Fee"); s.add("Fi"); s.add("Fo"); s.add("Fum"); Iterator it1 = s.iterator(); for (String v1 =null; it1.hasNext(); v1 =it1.next()) { Iterator it2 = s.iterator();// a completely separate iterator to it1 for (String v2 =null; it2.hasNext(); v2 = it2.next()) {System.out.println(v1 + " <-->" + v2); } } } } Or, even better, if you're using Java 5+, you can skip using Iterators altogether and use for-loops directly: import java.util.Collections; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; public class Example {public static void main(String[] args) { Set s = Collections.newSetFromMap(new ConcurrentHashMap ()); s.add("Fee"); s.add("Fi"); s.add("Fo"); s.add("Fum"); for (String v1 : s) { for (String v2 : s) {System.out.println(v1 + "<-->" + v2); } } } } Kind regards, Jonathan On 10 September 2016 at 23:13, Dave Brosius > wrote: It would be nice to be able to associate each element in a collection with another element in the collection, which is something very easily done with index based collections, but with sets, etc this isn't so easy... unless i'm having a brainfart. So i'd like to do this, but Iterator doesn't implement Cloneable... Any reason not to? or is there another way that's missing me? public class ItClone { public static void main(String[] args) { Set s = Collections.newSetFromMap(new ConcurrentHashMap ()); s.add("Fee"); s.add("Fi"); s.add("Fo"); s.add("Fum"); Iterator it1 = s.iterator(); while (it1.hasNext()) { String v1 = it1.next(); Iterator it2 = (Iterator) it1.*clone*(); while (it2.hasNext()) { String v2 = it2.next(); System.out.println(v1 + " <-->" + v2); } } } }
Re: Make iterators cloneable?
Ah okay Louis, if that's the case then that certainly makes sense, and I'd agree that there's no good way of doing so, as one would need to copy the set into a list. Dave, did Louis hit the mark? If not, would you kindly go into further detail as to exactly what it is you're trying to do? Best, Jonathan On 10 September 2016 at 23:36, Jonathan Bluett-Duncan < jbluettdun...@gmail.com> wrote: > Hi Dave, > > Rather than using Iterator.clone(), how about you just call > collection.iterator() 2 times to return 2 unique, non-same iterators; > something like the following: > > import java.util.Collections; > import java.util.Iterator; > import java.util.Set; > import java.util.concurrent.ConcurrentHashMap; > > public class Example { > public static void main(String[] args) { > Set s = Collections.newSetFromMap(new ConcurrentHashMapBoolean>()); > > s.add("Fee"); > s.add("Fi"); > s.add("Fo"); > s.add("Fum"); > > Iterator it1 = s.iterator(); > for (String v1 = null; it1.hasNext(); v1 =it1.next()) { > Iterator it2 = s.iterator(); // a completely separate iterator > to it1 > for (String v2 = null; it2.hasNext(); v2 = it2.next()) { > System.out.println(v1 + " <-->" + v2); > } > } > } > } > > > Or, even better, if you're using Java 5+, you can skip using Iterators > altogether and use for-loops directly: > > import java.util.Collections; > import java.util.Set; > import java.util.concurrent.ConcurrentHashMap; > > public class Example { > public static void main(String[] args) { > Set s = Collections.newSetFromMap(new ConcurrentHashMap Boolean>()); > > s.add("Fee"); > s.add("Fi"); > s.add("Fo"); > s.add("Fum"); > > for (String v1 : s) { > for (String v2 : s) { > System.out.println(v1 + "<-->" + v2); > } > } > } > } > > > Kind regards, > Jonathan > > On 10 September 2016 at 23:13, Dave Brosius > wrote: > >> It would be nice to be able to associate each element in a collection >> with another element in the collection, which is something very easily done >> with index based collections, but with sets, etc this isn't so easy... >> unless i'm having a brainfart. >> >> So i'd like to do this, but Iterator doesn't implement Cloneable... Any >> reason not to? or is there another way that's missing me? >> >> public class ItClone { >> >> public static void main(String[] args) { >> Set s = Collections.newSetFromMap(new >> ConcurrentHashMap ()); >> >> s.add("Fee"); >> s.add("Fi"); >> s.add("Fo"); >> s.add("Fum"); >> >> Iterator it1 = s.iterator(); >> while (it1.hasNext()) { >> String v1 = it1.next(); >> >> Iterator it2 = (Iterator) it1.*clone*(); >> while (it2.hasNext()) { >> String v2 = it2.next(); >> >> System.out.println(v1 + " <-->" + v2); >> } >> } >> } >> } >> > >
Re: Make iterators cloneable?
Hi Dave, Rather than using Iterator.clone(), how about you just call collection.iterator() 2 times to return 2 unique, non-same iterators; something like the following: import java.util.Collections; import java.util.Iterator; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; public class Example { public static void main(String[] args) { Set s = Collections.newSetFromMap(new ConcurrentHashMap()); s.add("Fee"); s.add("Fi"); s.add("Fo"); s.add("Fum"); Iterator it1 = s.iterator(); for (String v1 = null; it1.hasNext(); v1 =it1.next()) { Iterator it2 = s.iterator(); // a completely separate iterator to it1 for (String v2 = null; it2.hasNext(); v2 = it2.next()) { System.out.println(v1 + " <-->" + v2); } } } } Or, even better, if you're using Java 5+, you can skip using Iterators altogether and use for-loops directly: import java.util.Collections; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; public class Example { public static void main(String[] args) { Set s = Collections.newSetFromMap(new ConcurrentHashMap ()); s.add("Fee"); s.add("Fi"); s.add("Fo"); s.add("Fum"); for (String v1 : s) { for (String v2 : s) { System.out.println(v1 + "<-->" + v2); } } } } Kind regards, Jonathan On 10 September 2016 at 23:13, Dave Brosius wrote: > It would be nice to be able to associate each element in a collection with > another element in the collection, which is something very easily done with > index based collections, but with sets, etc this isn't so easy... unless > i'm having a brainfart. > > So i'd like to do this, but Iterator doesn't implement Cloneable... Any > reason not to? or is there another way that's missing me? > > public class ItClone { > > public static void main(String[] args) { > Set s = Collections.newSetFromMap(new > ConcurrentHashMap ()); > > s.add("Fee"); > s.add("Fi"); > s.add("Fo"); > s.add("Fum"); > > Iterator it1 = s.iterator(); > while (it1.hasNext()) { > String v1 = it1.next(); > > Iterator it2 = (Iterator) it1.*clone*(); > while (it2.hasNext()) { > String v2 = it2.next(); > > System.out.println(v1 + " <-->" + v2); > } > } > } > } >
Make iterators cloneable?
It would be nice to be able to associate each element in a collection with another element in the collection, which is something very easily done with index based collections, but with sets, etc this isn't so easy... unless i'm having a brainfart. So i'd like to do this, but Iterator doesn't implement Cloneable... Any reason not to? or is there another way that's missing me? public class ItClone { public static void main(String[] args) { Set s = Collections.newSetFromMap(new ConcurrentHashMap()); s.add("Fee"); s.add("Fi"); s.add("Fo"); s.add("Fum"); Iterator it1 = s.iterator(); while (it1.hasNext()) { String v1 = it1.next(); Iterator it2 = (Iterator) it1.*clone*(); while (it2.hasNext()) { String v2 = it2.next(); System.out.println(v1 + " <-->" + v2); } } } }
Re: Participating on https://bugs.openjdk.java.net/browse/JDK-8156070
Hi Aleksey, Sorry for the late reply. Thank for you pointing me to the contribute page; it gave me all the information I needed. Stuart, I'm now ready to make a patch review request, so submit one as soon as I have the time. Kind regards, Jonathan On 6 September 2016 at 09:46, Aleksey Shipilevwrote: > On 09/06/2016 01:49 AM, Jonathan Bluett-Duncan wrote: > > I decided to have a crack at "JDK-8134373 explore potential uses of > > convenience factories within the JDK" today. I recognise it's only a P4 > bug > > and most likely won't be prioritised for Java 9, but I believe I found a > > number of places where uses of > > "Collections.unmodifiableList(Arrays.asList(...))" and > "Arrays.asList(..)" > > can be replaced with "List.of(...)". I've thus made some changes to my > > local clone of the jdk9 codebase. > > > > I'm now at a point where I'm unfamiliar with what one does next when > > contributing to OpenJDK, so I wonder if you'd kindly advise me on what my > > next step(s) are. > > See: http://openjdk.java.net/contribute/ > > In short, sign and send OCA, prepare and send the patch for review, work > with your sponsor. > > Thanks, > -Aleksey >
RFR: jsr166 jdk9 integration wave 10
http://cr.openjdk.java.net/~martin/webrevs/openjdk9/jsr166-jdk9-integration/ Mostly docs and tests. jsr166 CVS is now caught up with jdk9+135 Paul, I think we need to update AtomicInteger for VarHandle#getAndAdd: http://cr.openjdk.java.net/~martin/webrevs/openjdk9/jsr166-jdk9-integration/miscellaneous/src/java.base/share/classes/java/util/concurrent/atomic/AtomicInteger.java.udiff.html