コード例 #1
0
    def populateMediaPlayers(self):

        #If there are no media objects, don't bother making Media Players.
        if self.__MEDIA_MASTER is None:
            return None

        from javafx.scene.media import MediaPlayer
        mpList = ArrayList()

        class makeNewMediaPlayer(Consumer):
            def __init__(self, mpList):
                self.mpList = mpList

            def accept(self, media):
                mpList.add(MediaPlayer(media))

        self.__MEDIA_MASTER.forEach(makeNewMediaPlayer(mpList))

        #Give us a set with the exact iteration order.
        # mpLhs = LinkedHashSet(mpList)

        #-- LinkedHashSet does not implement List<> and has no public API exposing the underlying LinkedList, no backward iterator !!!

        #The iterators returned by this class's iterator method are fail-fast: if the set is modified at any time after the
        #iterator is created, in any way except through the iterator's own remove method, the iterator will throw a ConcurrentModificationException.
        #No more need for the list
        # mpList = None
        # System.gc()

        #Iteration over a LinkedHashSet requires time proportional to the size of the set, regardless of its capacity.
        #Iteration over a HashSet is likely to be more expensive, requiring time proportional to its capacity

        ##LinkedHashMap< Iterator, LinkedHashSet<MediaPlayer> > is what we had wanted.

        #Return Map.Entry
        return AbstractMap.SimpleImmutableEntry(mpList.listIterator(), mpList)