Example usage for org.apache.commons.functor UnaryPredicate UnaryPredicate

List of usage examples for org.apache.commons.functor UnaryPredicate UnaryPredicate

Introduction

In this page you can find the example usage for org.apache.commons.functor UnaryPredicate UnaryPredicate.

Prototype

UnaryPredicate

Source Link

Usage

From source file:declarative.Sample1.java

public static void main(String[] args) {
    UnaryPredicate<Integer> isEven = new UnaryPredicate<Integer>() {
        public boolean test(Integer number) {
            return number % 2 == 0;
        }/*from   w w w  .  ja v  a 2 s  .c  o m*/
    };
    IntegerRange zeroToTen = new IntegerRange(0, 11);
    for (Integer number : zeroToTen.toCollection()) {
        if (isEven.test(number)) {
            System.out.println(number + " is even");
        }
    }
}

From source file:com.aw.swing.mvp.action.ActionResolver.java

public Action getActionToBeExecutedOnClickFor(GridProvider gridProvider) {
    List actions = getActionsFor(gridProvider);
    int actionIndex = ListUtils.indexOf(actions, new UnaryPredicate() {
        public boolean test(Object o) {
            Action action = (Action) o;
            return action.hasToBeExecutedOnClick();
        }//from  www .j a  v  a2s  .  c  o  m
    });
    return (Action) (actionIndex != -1 ? actions.get(actionIndex) : null);
}

From source file:com.aw.support.collection.ListUtils.java

public static <E> List<E> getSubList(Collection<E> list, final String propertyName,
        final Object propertyValue) {
    return getSubList(list, new UnaryPredicate() {
        @Override/* w  ww .  jav  a2s.c om*/
        public boolean test(Object o) {
            BeanWrapper wrapper = new BeanWrapperImpl(o);
            return propertyValue.equals(wrapper.getPropertyValue(propertyName));
        }
    });
}

From source file:com.aw.swing.mvp.action.ActionManager.java

private void selectingRowIfApply(GridProvider gdp, Flow lastFlow) {
    if (lastFlow != null) {
        List values = gdp.getValues();
        if (values.size() == 1) {
            gdp.getBndSJTable().setSelectedRow(0);
            return;
        }//  ww  w.  j  a v  a2 s .  co m
        final Object backBean = lastFlow.getAttribute(Flow.BACK_BEAN_NAME);
        if (backBean == null) {
            return;
        }
        Object firstCurrentValue = values.get(0);
        if ((firstCurrentValue instanceof Identifiable) && (backBean instanceof Identifiable)) {
            int index = ListUtils.indexOf(values, new UnaryPredicate() {
                public boolean test(Object o) {
                    Identifiable currentObjIdProv = (Identifiable) o;
                    Identifiable backBeanIdProv = (Identifiable) backBean;
                    return currentObjIdProv.getId().equals(backBeanIdProv.getId());
                }
            });
            if (index != -1) {
                gdp.getBndSJTable().setSelectedRow(index);
            }
        } else {
            gdp.getBndSJTable().setSelectedRow(backBean);
        }
    }
}

From source file:com.aw.swing.mvp.grid.GridProvider.java

public GridProvider registerRowColorChanger(final String attribute, final Object value) {
    UnaryPredicate predicate = new UnaryPredicate() {
        BeanWrapper beanWrapper;//from w  w  w .  jav a2s  . c  om

        public boolean test(Object row) {

            beanWrapper = new BeanWrapperImpl(row);

            return value.equals(beanWrapper.getPropertyValue(attribute));
        }
    };
    rowColorBkgChanger = new RowColorBkgChanger(predicate);
    return this;
}

From source file:com.aw.swing.mvp.binding.BindingManager.java

public List<BndIJTextField> getFunctionFields() {
    List functionFields = ListUtils.getSubList(getAllBindings(), new UnaryPredicate() {
        public boolean test(Object o) {
            if (o instanceof BndIJTextField) {
                return ((BndIJTextField) o).getGridFunction() != null;
            }//from w  w  w. j a v a  2  s  . c om
            return false;
        }
    });
    return functionFields;
}

From source file:com.aw.swing.mvp.binding.component.BndSJTable.java

public MainAuditColumn getMainAuditColumn() {
    List mainColumns = ListUtils.getSubList(Arrays.asList(getColumnsInfo()), new UnaryPredicate() {
        public boolean test(Object o) {
            return o instanceof MainAuditColumn;
        }//from   w  w w  . j  a  va  2  s.  c  o m
    });
    if (mainColumns.size() > 0) {
        return (MainAuditColumn) mainColumns.get(0);
    }
    return null;
}

From source file:com.aw.swing.mvp.binding.component.BndSJTable.java

public List<ColumnInfo> getRequiredColumns() {
    return ListUtils.getSubList(Arrays.asList(getColumnsInfo()), new UnaryPredicate() {
        public boolean test(Object o) {
            return ((ColumnInfo) o).isRequired();
        }/*  ww  w  .j av a 2  s . c om*/
    });
}

From source file:com.aw.swing.mvp.binding.component.BndSJTable.java

public List<ColumnInfo> getUniqueColumns() {
    return ListUtils.getSubList(Arrays.asList(getColumnsInfo()), new UnaryPredicate() {
        public boolean test(Object o) {
            return ((ColumnInfo) o).isUnique();
        }//from  ww  w  .ja va2 s  .c o m
    });
}

From source file:com.aw.swing.mvp.binding.component.BndSJTable.java

public List<ColumnInfo> getEditableColumns() {
    return ListUtils.getSubList(Arrays.asList(getColumnsInfo()), new UnaryPredicate() {
        public boolean test(Object o) {
            return ((ColumnInfo) o).isEditable() && !(o instanceof MainAuditColumn)
                    && !(o instanceof SelectorColumn);
        }//  w  w  w.j a v  a  2 s. co  m
    });
}