private void applyConstraint() { filteredSize = 0; ListModel filteredListModel = getFilteredModel(); for (int i = 0, size = filteredListModel.getSize(); i < size; i++) { Object element = filteredListModel.getElementAt(i); if (constraint.test(element)) { indexes[filteredSize++] = i; onMatchingElement(element); } } postConstraintApplied(); }
/** * Defines the constraint which is applied to the list model elements * * @param constraint the constraint to set * @throws IllegalArgumentException if constraint is null */ public final void setConstraint(Constraint constraint) { Assert.notNull(constraint); if (!constraint.equals(this.constraint)) { if (this.constraint instanceof Observable) { ((Observable) constraint).deleteObserver(this); } this.constraint = constraint; if (constraint instanceof Observable) { ((Observable) constraint).addObserver(this); } fireContentsChanged(this, -1, -1); } }