Example usage for org.apache.commons.collections ComparatorUtils chainedComparator

List of usage examples for org.apache.commons.collections ComparatorUtils chainedComparator

Introduction

In this page you can find the example usage for org.apache.commons.collections ComparatorUtils chainedComparator.

Prototype

public static Comparator chainedComparator(Comparator comparator1, Comparator comparator2) 

Source Link

Document

Gets a comparator that compares using two Comparator s.

Usage

From source file:com.linkedin.pinot.common.restlet.PinotRestletApplication.java

protected void attachRoutesForClass(Router router, Class<? extends ServerResource> clazz) {
    TreeSet<String> pathsOrderedByLength = new TreeSet<String>(
            ComparatorUtils.chainedComparator(new Comparator<String>() {

                @Override/*from  w  ww  .  j av  a2  s .  c  o m*/
                public int compare(String left, String right) {
                    int leftLength = left.length();
                    int rightLength = right.length();
                    return leftLength < rightLength ? -1 : (leftLength == rightLength ? 0 : 1);
                }
            }, ComparatorUtils.NATURAL_COMPARATOR));

    for (Method method : clazz.getDeclaredMethods()) {
        Annotation annotationInstance = method.getAnnotation(Paths.class);
        if (annotationInstance != null) {
            pathsOrderedByLength.addAll(Arrays.asList(((Paths) annotationInstance).value()));
        }
    }

    for (String routePath : pathsOrderedByLength) {
        LOGGER.info("Attaching route {} -> {}", routePath, clazz.getSimpleName());
        attachRoute(router, routePath, clazz);
    }
}

From source file:ips1ap101.lib.core.db.util.VistaFuncionWrapper.java

private void init() throws ExcepcionAplicacion {
    _vista = EJBL.getVistaFuncionFacade().find(_id, true);
    if (_vista == null) {
        throw new ExcepcionAplicacion(Bitacora.getTextoMensaje(CBM.VISTA_NO_DISPONIBLE, _nombre));
    }/*ww w.j a va2  s  . c o m*/
    _nombre = _vista.getNombre();
    _from = from(_select);
    if (StringUtils.isBlank(_from)) {
        // vista "{0}" no tiene origen
        throw new ExcepcionAplicacion(Bitacora.getTextoMensaje(CBM.ERROR_COMANDO_SELECT_VISTA_1, _nombre));
    }
    _where = where(_select);
    _columnas = new ArrayList<>(_vista.getVistaFuncionColByVistaCollection());
    _columnasOcultas = new ArrayList<>();
    _grupos = new ArrayList<>();
    _agregaciones = new ArrayList<>();
    VistaFuncionColPorSecuencia c1 = new VistaFuncionColPorSecuencia();
    VistaFuncionColPorId c2 = new VistaFuncionColPorId();
    Comparator<VistaFuncionColBase> comparator = (Comparator<VistaFuncionColBase>) ComparatorUtils
            .chainedComparator(c1, c2);
    Collections.sort((List<VistaFuncionColBase>) _columnas, comparator);
    boolean parametrosRestringidos = TLC.getControlador()
            .esFuncionConParametrosRestringidos(_vista.getFuncion().getIdFuncion());
    String codigoDominio = _vista.getFuncion().getIdDominio().getCodigoDominio();
    TipoAgregacionBase agregacion;
    TipoAgregacionEnumeration tipoAgregacion;
    VistaFuncionColBase grupo;
    String alias;
    String propertyColumn;
    Long propertySelect;
    boolean parametroAutorizado;
    for (VistaFuncionColBase vistaFuncionCol : _columnas) {
        agregacion = vistaFuncionCol.getAgregacion();
        tipoAgregacion = agregacion == null ? null : TipoAgregacionEnumeration.valueOf(agregacion.getNumero());
        grupo = vistaFuncionCol.getGrupo();
        alias = vistaFuncionCol.getAlias();
        if (parametrosRestringidos) {
            propertyColumn = BaseBundle.getPropertyColumn(codigoDominio, alias);
            propertySelect = BaseBundle.getPropertySelect(codigoDominio, alias);
            parametroAutorizado = propertyColumn == null || propertySelect == null
                    || TLC.getControlador().esParametroAutorizado(propertyColumn, propertySelect);
        } else {
            parametroAutorizado = true;
        }
        if (parametroAutorizado) {
            if (tipoAgregacion != null) {
                if (TipoAgregacionEnumeration.GRUPO.equals(tipoAgregacion)) {
                    if (grupo != null && vistaFuncionCol.getId().equals(grupo.getId())) {
                        _grupos.add(vistaFuncionCol);
                        _ultimo = vistaFuncionCol;
                    }
                } else {
                    _agregaciones.add(vistaFuncionCol);
                }
            }
            _orden |= BitUtils.valueOf(vistaFuncionCol.getOrden());
        } else {
            _columnasOcultas.add(vistaFuncionCol);
        }
    }
    if (_columnasOcultas.isEmpty()) {
        if (_columnas.isEmpty()) {
            // vista "{0}" no tiene columnas
            throw new ExcepcionAplicacion(Bitacora.getTextoMensaje(CBM.ERROR_COMANDO_SELECT_VISTA_2, _nombre));
        }
        switch (_tipo) {
        case DETALLE:
            if (_grupos.isEmpty()) {
            } else if (_agregaciones.isEmpty()) {
                // vista "{0}" no tiene agregaciones
                throw new ExcepcionAplicacion(
                        Bitacora.getTextoMensaje(CBM.ERROR_COMANDO_SELECT_VISTA_4, _nombre));
            }
            break;
        case GRAFICO:
            if (_grupos.isEmpty()) {
                // vista "{0}" no tiene grupos
                throw new ExcepcionAplicacion(
                        Bitacora.getTextoMensaje(CBM.ERROR_COMANDO_SELECT_VISTA_3, _nombre));
            }
            if (_agregaciones.isEmpty()) {
                // vista "{0}" no tiene agregaciones
                throw new ExcepcionAplicacion(
                        Bitacora.getTextoMensaje(CBM.ERROR_COMANDO_SELECT_VISTA_4, _nombre));
            }
            agregacion = null;
            for (VistaFuncionColBase vistaFuncionCol : _agregaciones) {
                if (BitUtils.valueOf(vistaFuncionCol.getGraficable())) {
                    continue;
                }
                agregacion = vistaFuncionCol.getAgregacion();
                tipoAgregacion = TipoAgregacionEnumeration.valueOf(agregacion.getNumero());
                TLC.getBitacora().error(CBM.COLUMNA_NO_GRAFICABLE, vistaFuncionCol.getNombre(),
                        tipoAgregacion.getLabel());
            }
            if (agregacion != null) {
                throw new ExcepcionAplicacion(Bitacora.getTextoMensaje(CBM.VISTA_NO_GRAFICABLE, _nombre));
            }
            break;
        case RESUMEN:
            if (_agregaciones.isEmpty()) {
                // vista "{0}" no tiene agregaciones
                throw new ExcepcionAplicacion(
                        Bitacora.getTextoMensaje(CBM.ERROR_COMANDO_SELECT_VISTA_4, _nombre));
            }
            break;
        }
    } else {
        for (VistaFuncionColBase vistaFuncionCol : _columnasOcultas) {
            TLC.getBitacora().error(CBM.COLUMNA_NO_AUTORIZADA, vistaFuncionCol.getNombre());
        }
        throw new ExcepcionAplicacion(Bitacora.getTextoMensaje(CBM.VISTA_NO_AUTORIZADA, _nombre));
    }
    if (_orden) {
    } else {
        // vista "{0}" no tiene orden
        TLC.getBitacora().warn(CBM.ERROR_COMANDO_SELECT_VISTA_5, _nombre);
    }
    _vistaValida = true;
}

From source file:com.linkedin.pinot.controller.api.ControllerRestApplication.java

private void attachRoutesForClass(Router router, Class<? extends ServerResource> clazz) {
    TreeSet<String> pathsOrderedByLength = new TreeSet<String>(
            ComparatorUtils.chainedComparator(new Comparator<String>() {
                private IntComparator _intComparator = IntComparators.NATURAL_COMPARATOR;

                @Override//  w w  w .  ja  va  2s  .com
                public int compare(String o1, String o2) {
                    return _intComparator.compare(o1.length(), o2.length());
                }
            }, ComparatorUtils.NATURAL_COMPARATOR));

    for (Method method : clazz.getDeclaredMethods()) {
        Annotation annotationInstance = method.getAnnotation(Paths.class);
        if (annotationInstance != null) {
            pathsOrderedByLength.addAll(Arrays.asList(((Paths) annotationInstance).value()));
        }
    }

    for (String routePath : pathsOrderedByLength) {
        LOGGER.info("Attaching route {} -> {}", routePath, clazz.getSimpleName());
        router.attach(routePath, clazz);
    }
}

From source file:com.inkubator.hrm.web.account.RoleFormController.java

@Override
public void onDialogReturn(SelectEvent event) {

    /** looping sampai parent paling atas dari node, 
     *  exclude jika terdapat duplicate parent node */
    Set<HrmMenu> menuSets = new HashSet<HrmMenu>();
    TreeNode[] selectedNodes = (TreeNode[]) event.getObject();
    if (selectedNodes != null) {
        for (TreeNode node : selectedNodes) {
            HrmMenu menu = (HrmMenu) node.getData();
            if (menu.getId() != null) {
                menuSets.add(menu);/*from w w w.j a v  a2s .  c  om*/
            }

            while (node.getParent() != null) {
                node = node.getParent();
                HrmMenu parentMenu = (HrmMenu) node.getData();
                if (parentMenu.getId() != null) {
                    menuSets.add(parentMenu);
                }
            }
        }
    }

    /** order list by menu level asc, orderMenuLevel asc */
    Comparator<HrmMenu> byMenuLevel = new ArgumentComparator(Lambda.on(HrmMenu.class).getMenuLevel());
    Comparator<HrmMenu> byOrderLevelMenu = new ArgumentComparator(Lambda.on(HrmMenu.class).getOrderLevelMenu());
    Comparator<HrmMenu> orderBy = ComparatorUtils.chainedComparator(byMenuLevel, byOrderLevelMenu);

    menus.clear();
    menus = Lambda.sort(menuSets, Lambda.on(HrmMenu.class), orderBy);
}