Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7795823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:10:51+00:00 2026-06-01T23:10:51+00:00

From some API call, I am getting back an IObservableList<E> , from the Eclipse

  • 0

From some API call, I am getting back an IObservableList<E>, from the Eclipse Databinding framework. I’d wish to derive another IObservableList<E> from this one according to some predicate defined on the element type E. The derived list should be dynamically updated according to changes in the original list.

How can I best implement that? I’ve considered subclassing DecoratingObservableList, but couldn’t figure out how to use it.

Of course, I could implement myself the whole IObservableList interface, but I was wondering if there were not other utility classes around that I could use.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T23:10:53+00:00Added an answer on June 1, 2026 at 11:10 pm

    I think extending DecoratingObservableList is a good start. I would also suggest concentrating on exactly the intended usage instead of immediately implementing the entire API. For example, do you need random-acces writing via set? If not, then don’t bother implementing it. This covers a read-only view of a mutable ObservableList, mapping the change events of the decorated list to the appropriate change events on the filtered list:

    public class FilteredObservableList<E> extends DecoratingObservableList
    {
      private final IObservableList decorated;
      private final Predicate pred;
      private final List<E> filtered = new ArrayList();
    
      public FilteredObservableList(
          IObservableList decorated, Predicate pred, boolean disposeDecoratedOnDispose)
      {
        super(decorated, disposeDecoratedOnDispose);
        this.decorated = decorated;
        this.pred = pred;
        for (Object o : decorated) filtered.add(pred.eval(o)? (E) o : null);
      }
    
      @Override protected void handleListChange(ListChangeEvent event) {
        final List<ListDiffEntry> diffs = new ArrayList();
        final List<Integer> mapping = new ArrayList();
        int i = 0;
        for (E e : filtered) mapping.add(e != null? i++ : i);
        event.diff.accept(new ListDiffVisitor() {
          @Override public void handleAdd(int index, Object element) {
            final boolean passes = pred.eval(element);
            filtered.add(index, passes? (E) element : null);
            final Integer outInd = mapping.get(index);
            mapping.add(index, outInd);
            if (passes) {
              diffs.add(new FilteredDiffEntry(outInd, true, element));
              for (int i = index + 1; i < mapping.size(); i++)
                mapping.set(i, mapping.get(i) + 1);
            }
          }
          @Override public void handleRemove(int index, Object element) {
            final boolean passes = filtered.get(index) != null;
            filtered.remove(index);
            final int outInd = mapping.get(index);
            mapping.remove(index);
            if (passes) {
              diffs.add(new FilteredDiffEntry(outInd, false, element));
              for (int i = index; i < mapping.size(); i++)
                mapping.set(i, mapping.get(i)-1);
            }
          }
        });
        if (!diffs.isEmpty()) {
          final ListDiffEntry[] difAry = diffs.toArray(new ListDiffEntry[diffs.size()]);
          fireListChange(new ListDiff() {
            @Override public ListDiffEntry[] getDifferences() { return difAry; }
          });
        }
      }
    
      public ListIterator<E> listIterator() {
        getterCalled();
        final Iterator<E> it = decorated.iterator();
        return new ListIterator<E>() {
          E next;
          boolean nextReady;
          public boolean hasNext() {
            getterCalled();
            if (nextReady) return true;
            while (it.hasNext()) {
              next = it.next();
              if (next != null) { nextReady = true; break; }
            }
            return nextReady;
          }
          public E next() {
            getterCalled();
            if (hasNext()) { nextReady = false; return next; }
            else throw new NoSuchElementException();
          }
          public void add(Object o) { throw new UnsupportedOperationException(); }
          public boolean hasPrevious() { throw new UnsupportedOperationException(); }
          public int nextIndex() { throw new UnsupportedOperationException(); }
          public E previous() { throw new UnsupportedOperationException(); }
          public int previousIndex() { throw new UnsupportedOperationException(); }
          public void remove() { throw new UnsupportedOperationException(); }
          public void set(Object o) { throw new UnsupportedOperationException(); }
        };
      }
    
      public interface Predicate { boolean eval(Object o); }
    
      private static final class FilteredDiffEntry extends ListDiffEntry {
        private final int pos;
        private final boolean isAdd;
        private final Object el;
        FilteredDiffEntry(int pos, boolean isAdd, Object el) {
          this.pos = pos; this.isAdd = isAdd; this.el = el;
        }
        @Override public int getPosition() { return pos; }
        @Override public boolean isAddition() { return isAdd; }
        @Override public Object getElement() { return el; }
      }
    
      @Override public Object move(int _, int __) { throw new UnsupportedOperationException(); }
      @Override public Object remove(int _) { throw new UnsupportedOperationException(); }
      @Override public Object set(int _, Object __) { throw new UnsupportedOperationException(); }
      @Override public void add(int _, Object __) { throw new UnsupportedOperationException(); }
      @Override public boolean add(Object _) { throw new UnsupportedOperationException(); }
      @Override public boolean addAll(Collection _) { throw new UnsupportedOperationException(); }
      @Override public boolean addAll(int _, Collection __) {
        throw new UnsupportedOperationException();
      }
      @Override public void clear() { throw new UnsupportedOperationException(); }
      @Override public boolean remove(Object _) { throw new UnsupportedOperationException(); }
      @Override public boolean removeAll(Collection _) { throw new UnsupportedOperationException();}
      @Override public boolean retainAll(Collection _) { throw new UnsupportedOperationException();}
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting photos from facebook through graph api with this call: https://graph.facebook.com/[AlbumID]/photos The
Not sure why but I am not getting anything back from the json call.
I am getting this error: ERROR libEGL call to OpenGL ES API with no
There is some Win OS API call or so that would let one obtain
I am getting a list from an API call. I would like to be
I am trying to read some settings from php.ini using zend. The API that
I am working with rails 3.2 and want to request some services from http://api.de-captcher.com/
I'm working on an API that accepts data from remote clients, some of which
I have a Webserver running in Python. He is getting some Data from some
I'm a bit puzzled by this one. There are some methods in the Java

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.