Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8100820

ObservableList should have a method remove(int from, int to)

    Details

    • Subcomponent:

      Description

      The ObservableList API seems to have a deficiency: there's no way to remove a sublist of elements in a single operation, except for the removeAll(Collection) method that is generally undesirable because it makes a O(N) scan of the list. When I need to remove a single element which position is known, remove(int index) is ideal. But if I need to remove a large number of elements of known position, the only good solution would be a remove method that accepts a pair of from (inclusive) / to (exclusive) indexes.

      This can be considered a JavaSE API deficiency that JavaFX just inherits (literally); for one thing, in a JavaSE List, removing a large subrange of elements from an array-backed List degrades to O(N) unless we always remove the last element of the list; a remove(from, to) method would amortize the cost of "left-shifting" the last elements, delivering ~O(1) performance even when the range doesn't finish at the last preexisting element.

      But JavaFX's problem is much worse, because an invalidation event will be issued for each removed element. I want to remove 100 elements and have a single onChanged() invocation in the listeners, instead of 100 invocations. The ListChangeListener.Change class already supports reporting a list of removed items in a single event, but this is basically useless without a ObservableList.remove(from, to) method, so I'll classify this as a bug rather than an optimization RFE. (In JavaFX Script, the sequences had syntax to remove an indexed subrange of elements in a single operation, and this got lost in the translation to Java and its List collections.)

        Attachments

          Activity

            People

            • Assignee:
              msladecek Martin Sládeček
              Reporter:
              odoederlejfx Osvaldo Pinali Doederlein (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported: