Example usage for java.util Collections binarySearch

List of usage examples for java.util Collections binarySearch

Introduction

In this page you can find the example usage for java.util Collections binarySearch.

Prototype

@SuppressWarnings("unchecked")
public static <T> int binarySearch(List<? extends T> list, T key, Comparator<? super T> c) 

Source Link

Document

Searches the specified list for the specified object using the binary search algorithm.

Usage

From source file:pe.gob.mef.gescon.web.ui.WikiMB.java

public void onListTipoConocimientoChange(AjaxBehaviorEvent event) {
    try {//ww  w.j av a 2 s  .c  o  m
        if (event != null) {
            final BigDecimal id = (BigDecimal) ((SelectOneMenu) event.getSource()).getValue();
            this.setIdTipoConocimiento(id);
            if (id != null) {
                HashMap filters = new HashMap();
                filters.put("ntipoconocimientoid", id);
                ConocimientoService service = (ConocimientoService) ServiceFinder
                        .findBean("ConocimientoService");
                if (this.getSelectedWiki() != null) {
                    filters.put("nconocimientoid", this.getSelectedWiki().getNconocimientoid().toString());
                    this.setListaTargetVinculos(new ArrayList());
                    List<Consulta> lista = service.getConcimientosVinculados(filters);
                    Collections.sort(lista, Consulta.Comparators.ID);
                    if (id.equals(Constante.BASELEGAL)) {
                        for (Consulta ele : lista) {
                            int pos = Collections.binarySearch(this.getListaTargetVinculosBL(), ele,
                                    Consulta.Comparators.ID);
                            if (pos < 0) {
                                this.getListaTargetVinculosBL().add(ele);
                            }
                        }
                        this.getListaTargetVinculos().addAll(this.getListaTargetVinculosBL());
                    } else if (id.equals(Constante.PREGUNTAS)) {
                        for (Consulta ele : lista) {
                            int pos = Collections.binarySearch(this.getListaTargetVinculosPR(), ele,
                                    Consulta.Comparators.ID);
                            if (pos < 0) {
                                this.getListaTargetVinculosPR().add(ele);
                            }
                        }
                        this.getListaTargetVinculos().addAll(this.getListaTargetVinculosPR());
                    } else if (id.equals(Constante.WIKI)) {
                        for (Consulta ele : lista) {
                            int pos = Collections.binarySearch(this.getListaTargetVinculosWK(), ele,
                                    Consulta.Comparators.ID);
                            if (pos < 0) {
                                this.getListaTargetVinculosWK().add(ele);
                            }
                        }
                        this.getListaTargetVinculos().addAll(this.getListaTargetVinculosWK());
                    } else if (id.equals(Constante.CONTENIDO)) {
                        for (Consulta ele : lista) {
                            int pos = Collections.binarySearch(this.getListaTargetVinculosCT(), ele,
                                    Consulta.Comparators.ID);
                            if (pos < 0) {
                                this.getListaTargetVinculosCT().add(ele);
                            }
                        }
                        this.getListaTargetVinculos().addAll(this.getListaTargetVinculosCT());
                    } else if (id.equals(Constante.BUENAPRACTICA)) {
                        for (Consulta ele : lista) {
                            int pos = Collections.binarySearch(this.getListaTargetVinculosBP(), ele,
                                    Consulta.Comparators.ID);
                            if (pos < 0) {
                                this.getListaTargetVinculosBP().add(ele);
                            }
                        }
                        this.getListaTargetVinculos().addAll(this.getListaTargetVinculosBP());
                    } else if (id.equals(Constante.OPORTUNIDADMEJORA)) {
                        for (Consulta ele : lista) {
                            int pos = Collections.binarySearch(this.getListaTargetVinculosOM(), ele,
                                    Consulta.Comparators.ID);
                            if (pos < 0) {
                                this.getListaTargetVinculosOM().add(ele);
                            }
                        }
                        this.getListaTargetVinculos().addAll(this.getListaTargetVinculosOM());
                    }
                } else {
                    if (id.equals(Constante.BASELEGAL)) {
                        this.setListaTargetVinculos(this.getListaTargetVinculosBL());
                    } else if (id.equals(Constante.PREGUNTAS)) {
                        this.setListaTargetVinculos(this.getListaTargetVinculosPR());
                    } else if (id.equals(Constante.WIKI)) {
                        this.setListaTargetVinculos(this.getListaTargetVinculosWK());
                    } else if (id.equals(Constante.CONTENIDO)) {
                        this.setListaTargetVinculos(this.getListaTargetVinculosCT());
                    } else if (id.equals(Constante.BUENAPRACTICA)) {
                        this.setListaTargetVinculos(this.getListaTargetVinculosBP());
                    } else if (id.equals(Constante.OPORTUNIDADMEJORA)) {
                        this.setListaTargetVinculos(this.getListaTargetVinculosOM());
                    }
                }
                if (CollectionUtils.isNotEmpty(this.getListaTargetVinculos())) {
                    List<String> ids = new ArrayList<String>();
                    for (Consulta c : this.getListaTargetVinculos()) {
                        ids.add(c.getIdconocimiento().toString());
                    }
                    String filter = StringUtils.join(ids, ',');
                    if (id.equals(Constante.WIKI)) {
                        filter = filter.concat(",")
                                .concat(this.getSelectedWiki().getNconocimientoid().toString());
                    }
                    filters.put("nconocimientovinc", filter);
                }
                if (id.equals(Constante.BASELEGAL)) {
                    this.setListaSourceVinculosBL(service.getConcimientosDisponibles(filters));
                    this.setListaSourceVinculos(this.getListaSourceVinculosBL());
                } else if (id.equals(Constante.PREGUNTAS)) {
                    this.setListaSourceVinculosPR(service.getConcimientosDisponibles(filters));
                    this.setListaSourceVinculos(this.getListaSourceVinculosPR());
                } else if (id.equals(Constante.WIKI)) {
                    this.setListaSourceVinculosWK(service.getConcimientosDisponibles(filters));
                    this.setListaSourceVinculos(this.getListaSourceVinculosWK());
                } else if (id.equals(Constante.CONTENIDO)) {
                    this.setListaSourceVinculosCT(service.getConcimientosDisponibles(filters));
                    this.setListaSourceVinculos(this.getListaSourceVinculosCT());
                } else if (id.equals(Constante.BUENAPRACTICA)) {
                    this.setListaSourceVinculosBP(service.getConcimientosDisponibles(filters));
                    this.setListaSourceVinculos(this.getListaSourceVinculosBP());
                } else if (id.equals(Constante.OPORTUNIDADMEJORA)) {
                    this.setListaSourceVinculosOM(service.getConcimientosDisponibles(filters));
                    this.setListaSourceVinculos(this.getListaSourceVinculosOM());
                }
                this.setPickList(new DualListModel<Consulta>(this.getListaSourceVinculos(),
                        this.getListaTargetVinculos()));
            }
        }
    } catch (Exception e) {
        e.getMessage();
        e.printStackTrace();
    }
}

From source file:pe.gob.mef.gescon.web.ui.BuenaPracticaMB.java

public void onListTipoConocimientoChange(AjaxBehaviorEvent event) {
    try {/*w  w w.j a v  a 2s.  c o m*/
        if (event != null) {
            final BigDecimal id = (BigDecimal) ((SelectOneMenu) event.getSource()).getValue();
            this.setIdTipoConocimiento(id);
            if (id != null) {
                HashMap filters = new HashMap();
                filters.put("ntipoconocimientoid", id);
                ConocimientoService service = (ConocimientoService) ServiceFinder
                        .findBean("ConocimientoService");
                if (this.getSelectedBuenaPractica() != null) {
                    filters.put("nconocimientoid",
                            this.getSelectedBuenaPractica().getNconocimientoid().toString());
                    this.setListaTargetVinculos(new ArrayList());
                    List<Consulta> lista = service.getConcimientosVinculados(filters);
                    Collections.sort(lista, Consulta.Comparators.ID);
                    if (id.equals(Constante.BASELEGAL)) {
                        for (Consulta ele : lista) {
                            int pos = Collections.binarySearch(this.getListaTargetVinculosBL(), ele,
                                    Consulta.Comparators.ID);
                            if (pos < 0) {
                                this.getListaTargetVinculosBL().add(ele);
                            }
                        }
                        this.getListaTargetVinculos().addAll(this.getListaTargetVinculosBL());
                    } else if (id.equals(Constante.PREGUNTAS)) {
                        for (Consulta ele : lista) {
                            int pos = Collections.binarySearch(this.getListaTargetVinculosPR(), ele,
                                    Consulta.Comparators.ID);
                            if (pos < 0) {
                                this.getListaTargetVinculosPR().add(ele);
                            }
                        }
                        this.getListaTargetVinculos().addAll(this.getListaTargetVinculosPR());
                    } else if (id.equals(Constante.WIKI)) {
                        for (Consulta ele : lista) {
                            int pos = Collections.binarySearch(this.getListaTargetVinculosWK(), ele,
                                    Consulta.Comparators.ID);
                            if (pos < 0) {
                                this.getListaTargetVinculosWK().add(ele);
                            }
                        }
                        this.getListaTargetVinculos().addAll(this.getListaTargetVinculosWK());
                    } else if (id.equals(Constante.CONTENIDO)) {
                        for (Consulta ele : lista) {
                            int pos = Collections.binarySearch(this.getListaTargetVinculosCT(), ele,
                                    Consulta.Comparators.ID);
                            if (pos < 0) {
                                this.getListaTargetVinculosCT().add(ele);
                            }
                        }
                        this.getListaTargetVinculos().addAll(this.getListaTargetVinculosCT());
                    } else if (id.equals(Constante.BUENAPRACTICA)) {
                        for (Consulta ele : lista) {
                            int pos = Collections.binarySearch(this.getListaTargetVinculosBP(), ele,
                                    Consulta.Comparators.ID);
                            if (pos < 0) {
                                this.getListaTargetVinculosBP().add(ele);
                            }
                        }
                        this.getListaTargetVinculos().addAll(this.getListaTargetVinculosBP());
                    } else if (id.equals(Constante.OPORTUNIDADMEJORA)) {
                        for (Consulta ele : lista) {
                            int pos = Collections.binarySearch(this.getListaTargetVinculosOM(), ele,
                                    Consulta.Comparators.ID);
                            if (pos < 0) {
                                this.getListaTargetVinculosOM().add(ele);
                            }
                        }
                        this.getListaTargetVinculos().addAll(this.getListaTargetVinculosOM());
                    }
                } else {
                    if (id.equals(Constante.BASELEGAL)) {
                        this.setListaTargetVinculos(this.getListaTargetVinculosBL());
                    } else if (id.equals(Constante.PREGUNTAS)) {
                        this.setListaTargetVinculos(this.getListaTargetVinculosPR());
                    } else if (id.equals(Constante.WIKI)) {
                        this.setListaTargetVinculos(this.getListaTargetVinculosWK());
                    } else if (id.equals(Constante.CONTENIDO)) {
                        this.setListaTargetVinculos(this.getListaTargetVinculosCT());
                    } else if (id.equals(Constante.BUENAPRACTICA)) {
                        this.setListaTargetVinculos(this.getListaTargetVinculosBP());
                    } else if (id.equals(Constante.OPORTUNIDADMEJORA)) {
                        this.setListaTargetVinculos(this.getListaTargetVinculosOM());
                    }
                }
                if (CollectionUtils.isNotEmpty(this.getListaTargetVinculos())) {
                    List<String> ids = new ArrayList<String>();
                    for (Consulta c : this.getListaTargetVinculos()) {
                        ids.add(c.getIdconocimiento().toString());
                    }
                    String filter = StringUtils.join(ids, ',');
                    if (id.equals(Constante.WIKI)) {
                        filter = filter.concat(",")
                                .concat(this.getSelectedBuenaPractica().getNconocimientoid().toString());
                    }
                    filters.put("nconocimientovinc", filter);
                }
                if (id.equals(Constante.BASELEGAL)) {
                    this.setListaSourceVinculosBL(service.getConcimientosDisponibles(filters));
                    this.setListaSourceVinculos(this.getListaSourceVinculosBL());
                } else if (id.equals(Constante.PREGUNTAS)) {
                    this.setListaSourceVinculosPR(service.getConcimientosDisponibles(filters));
                    this.setListaSourceVinculos(this.getListaSourceVinculosPR());
                } else if (id.equals(Constante.WIKI)) {
                    this.setListaSourceVinculosWK(service.getConcimientosDisponibles(filters));
                    this.setListaSourceVinculos(this.getListaSourceVinculosWK());
                } else if (id.equals(Constante.CONTENIDO)) {
                    this.setListaSourceVinculosCT(service.getConcimientosDisponibles(filters));
                    this.setListaSourceVinculos(this.getListaSourceVinculosCT());
                } else if (id.equals(Constante.BUENAPRACTICA)) {
                    this.setListaSourceVinculosBP(service.getConcimientosDisponibles(filters));
                    this.setListaSourceVinculos(this.getListaSourceVinculosBP());
                } else if (id.equals(Constante.OPORTUNIDADMEJORA)) {
                    this.setListaSourceVinculosOM(service.getConcimientosDisponibles(filters));
                    this.setListaSourceVinculos(this.getListaSourceVinculosOM());
                }
                this.setPickList(new DualListModel<Consulta>(this.getListaSourceVinculos(),
                        this.getListaTargetVinculos()));
            }
        }
    } catch (Exception e) {
        e.getMessage();
        e.printStackTrace();
    }
}

From source file:org.broadleafcommerce.openadmin.server.dao.DynamicEntityDaoImpl.java

protected void buildProperties(Class<?> targetClass, ForeignKey foreignField,
        ForeignKey[] additionalForeignFields, String[] additionalNonPersistentProperties,
        MergedPropertyType mergedPropertyType, Map<String, FieldMetadata> presentationAttributes,
        List<Property> componentProperties, Map<String, FieldMetadata> fields, List<String> propertyNames,
        List<Type> propertyTypes, String idProperty, Boolean populateManyToOneFields, String[] includeFields,
        String[] excludeFields, String configurationKey, String ceilingEntityFullyQualifiedClassname,
        List<Class<?>> parentClasses, String prefix, Boolean isParentExcluded, Boolean isComponentPrefix) {
    int j = 0;// w w w  .  ja  va 2s.c om
    Comparator<String> propertyComparator = new Comparator<String>() {
        @Override
        public int compare(String o1, String o2) {
            //check for property name equality and for map field properties
            if (o1.equals(o2) || o1.startsWith(o2 + FieldManager.MAPFIELDSEPARATOR)
                    || o2.startsWith(o1 + FieldManager.MAPFIELDSEPARATOR)) {
                return 0;
            }
            return o1.compareTo(o2);
        }
    };
    List<String> presentationKeyList = new ArrayList<String>(presentationAttributes.keySet());
    Collections.sort(presentationKeyList);

    for (String propertyName : propertyNames) {
        final Type type = propertyTypes.get(j);
        boolean isPropertyForeignKey = testForeignProperty(foreignField, prefix, propertyName);
        int additionalForeignKeyIndexPosition = findAdditionalForeignKeyIndex(additionalForeignFields, prefix,
                propertyName);
        j++;
        Field myField = getFieldManager().getField(targetClass, propertyName);
        if (myField == null) {
            //try to get the field with the prefix - needed for advanced collections that appear in @Embedded classes
            myField = getFieldManager().getField(targetClass, prefix + propertyName);
        }
        if (!type.isAnyType() && !type.isCollectionType() || isPropertyForeignKey
                || additionalForeignKeyIndexPosition >= 0
                || Collections.binarySearch(presentationKeyList, propertyName, propertyComparator) >= 0) {
            if (myField != null) {
                boolean handled = false;
                for (FieldMetadataProvider provider : fieldMetadataProviders) {
                    FieldMetadata presentationAttribute = presentationAttributes.get(propertyName);
                    if (presentationAttribute != null) {
                        setExcludedBasedOnShowIfProperty(presentationAttribute);
                    }
                    FieldProviderResponse response = provider
                            .addMetadataFromFieldType(
                                    new AddMetadataFromFieldTypeRequest(myField, targetClass, foreignField,
                                            additionalForeignFields, mergedPropertyType, componentProperties,
                                            idProperty, prefix, propertyName, type, isPropertyForeignKey,
                                            additionalForeignKeyIndexPosition, presentationAttributes,
                                            presentationAttribute, null, type.getReturnedClass(), this),
                                    fields);
                    if (FieldProviderResponse.NOT_HANDLED != response) {
                        handled = true;
                    }
                    if (FieldProviderResponse.HANDLED_BREAK == response) {
                        break;
                    }
                }
                if (!handled) {
                    buildBasicProperty(myField, targetClass, foreignField, additionalForeignFields,
                            additionalNonPersistentProperties, mergedPropertyType, presentationAttributes,
                            componentProperties, fields, idProperty, populateManyToOneFields, includeFields,
                            excludeFields, configurationKey, ceilingEntityFullyQualifiedClassname,
                            parentClasses, prefix, isParentExcluded, propertyName, type, isPropertyForeignKey,
                            additionalForeignKeyIndexPosition, isComponentPrefix);
                }
            }
        }
    }
}

From source file:pe.gob.mef.gescon.web.ui.OportunidadMB.java

public void onListTipoConocimientoChange(AjaxBehaviorEvent event) {
    try {//from  w  ww .j  a v  a 2s .c  om
        if (event != null) {
            final BigDecimal id = (BigDecimal) ((SelectOneMenu) event.getSource()).getValue();
            this.setIdTipoConocimiento(id);
            if (id != null) {
                HashMap filters = new HashMap();
                filters.put("ntipoconocimientoid", id);
                ConocimientoService service = (ConocimientoService) ServiceFinder
                        .findBean("ConocimientoService");
                if (this.getSelectedOportunidad() != null) {
                    filters.put("nconocimientoid",
                            this.getSelectedOportunidad().getNconocimientoid().toString());
                    this.setListaTargetVinculos(new ArrayList());
                    List<Consulta> lista = service.getConcimientosVinculados(filters);
                    Collections.sort(lista, Consulta.Comparators.ID);
                    if (id.equals(Constante.BASELEGAL)) {
                        for (Consulta ele : lista) {
                            int pos = Collections.binarySearch(this.getListaTargetVinculosBL(), ele,
                                    Consulta.Comparators.ID);
                            if (pos < 0) {
                                this.getListaTargetVinculosBL().add(ele);
                            }
                        }
                        this.getListaTargetVinculos().addAll(this.getListaTargetVinculosBL());
                    } else if (id.equals(Constante.PREGUNTAS)) {
                        for (Consulta ele : lista) {
                            int pos = Collections.binarySearch(this.getListaTargetVinculosPR(), ele,
                                    Consulta.Comparators.ID);
                            if (pos < 0) {
                                this.getListaTargetVinculosPR().add(ele);
                            }
                        }
                        this.getListaTargetVinculos().addAll(this.getListaTargetVinculosPR());
                    } else if (id.equals(Constante.WIKI)) {
                        for (Consulta ele : lista) {
                            int pos = Collections.binarySearch(this.getListaTargetVinculosWK(), ele,
                                    Consulta.Comparators.ID);
                            if (pos < 0) {
                                this.getListaTargetVinculosWK().add(ele);
                            }
                        }
                        this.getListaTargetVinculos().addAll(this.getListaTargetVinculosWK());
                    } else if (id.equals(Constante.CONTENIDO)) {
                        for (Consulta ele : lista) {
                            int pos = Collections.binarySearch(this.getListaTargetVinculosCT(), ele,
                                    Consulta.Comparators.ID);
                            if (pos < 0) {
                                this.getListaTargetVinculosCT().add(ele);
                            }
                        }
                        this.getListaTargetVinculos().addAll(this.getListaTargetVinculosCT());
                    } else if (id.equals(Constante.BUENAPRACTICA)) {
                        for (Consulta ele : lista) {
                            int pos = Collections.binarySearch(this.getListaTargetVinculosBP(), ele,
                                    Consulta.Comparators.ID);
                            if (pos < 0) {
                                this.getListaTargetVinculosBP().add(ele);
                            }
                        }
                        this.getListaTargetVinculos().addAll(this.getListaTargetVinculosBP());
                    } else if (id.equals(Constante.OPORTUNIDADMEJORA)) {
                        for (Consulta ele : lista) {
                            int pos = Collections.binarySearch(this.getListaTargetVinculosOM(), ele,
                                    Consulta.Comparators.ID);
                            if (pos < 0) {
                                this.getListaTargetVinculosOM().add(ele);
                            }
                        }
                        this.getListaTargetVinculos().addAll(this.getListaTargetVinculosOM());
                    }
                } else {
                    if (id.equals(Constante.BASELEGAL)) {
                        this.setListaTargetVinculos(this.getListaTargetVinculosBL());
                    } else if (id.equals(Constante.PREGUNTAS)) {
                        this.setListaTargetVinculos(this.getListaTargetVinculosPR());
                    } else if (id.equals(Constante.WIKI)) {
                        this.setListaTargetVinculos(this.getListaTargetVinculosWK());
                    } else if (id.equals(Constante.CONTENIDO)) {
                        this.setListaTargetVinculos(this.getListaTargetVinculosCT());
                    } else if (id.equals(Constante.BUENAPRACTICA)) {
                        this.setListaTargetVinculos(this.getListaTargetVinculosBP());
                    } else if (id.equals(Constante.OPORTUNIDADMEJORA)) {
                        this.setListaTargetVinculos(this.getListaTargetVinculosOM());
                    }
                }
                if (CollectionUtils.isNotEmpty(this.getListaTargetVinculos())) {
                    List<String> ids = new ArrayList<String>();
                    for (Consulta c : this.getListaTargetVinculos()) {
                        ids.add(c.getIdconocimiento().toString());
                    }
                    String filter = StringUtils.join(ids, ',');
                    if (id.equals(Constante.WIKI)) {
                        filter = filter.concat(",")
                                .concat(this.getSelectedOportunidad().getNconocimientoid().toString());
                    }
                    filters.put("nconocimientovinc", filter);
                }
                if (id.equals(Constante.BASELEGAL)) {
                    this.setListaSourceVinculosBL(service.getConcimientosDisponibles(filters));
                    this.setListaSourceVinculos(this.getListaSourceVinculosBL());
                } else if (id.equals(Constante.PREGUNTAS)) {
                    this.setListaSourceVinculosPR(service.getConcimientosDisponibles(filters));
                    this.setListaSourceVinculos(this.getListaSourceVinculosPR());
                } else if (id.equals(Constante.WIKI)) {
                    this.setListaSourceVinculosWK(service.getConcimientosDisponibles(filters));
                    this.setListaSourceVinculos(this.getListaSourceVinculosWK());
                } else if (id.equals(Constante.CONTENIDO)) {
                    this.setListaSourceVinculosCT(service.getConcimientosDisponibles(filters));
                    this.setListaSourceVinculos(this.getListaSourceVinculosCT());
                } else if (id.equals(Constante.BUENAPRACTICA)) {
                    this.setListaSourceVinculosBP(service.getConcimientosDisponibles(filters));
                    this.setListaSourceVinculos(this.getListaSourceVinculosBP());
                } else if (id.equals(Constante.OPORTUNIDADMEJORA)) {
                    this.setListaSourceVinculosOM(service.getConcimientosDisponibles(filters));
                    this.setListaSourceVinculos(this.getListaSourceVinculosOM());
                }
                this.setPickList(new DualListModel<Consulta>(this.getListaSourceVinculos(),
                        this.getListaTargetVinculos()));
            }
        }
    } catch (Exception e) {
        e.getMessage();
        e.printStackTrace();
    }
}

From source file:org.pentaho.di.repository.Repository.java

private synchronized int searchStepAttributeIndexInBuffer(long id_step, String code, long nr)
        throws KettleValueException {
    Object[] key = new Object[] { new Long(id_step), // ID_STEP
            code, // CODE
            new Long(nr), // NR
    };/*w ww  . j a  v a 2  s.  co  m*/

    int index = Collections.binarySearch(stepAttributesBuffer, key, new StepAttributeComparator());

    if (index >= stepAttributesBuffer.size() || index < 0)
        return -1;

    // 
    // Check this...  If it is not in there, we didn't find it!
    // stepAttributesRowMeta.compare returns 0 when there are conversion issues
    // so the binarySearch could have 'found' a match when there really isn't one
    //
    Object[] look = stepAttributesBuffer.get(index);

    if (stepAttributesRowMeta.compare(look, key, KEY_POSITIONS) == 0) {
        return index;
    }

    return -1;
}

From source file:org.sparkcommerce.openadmin.server.service.persistence.module.BasicPersistenceModule.java

protected void extractPropertiesFromMetadata(Class<?>[] inheritanceLine,
        Map<String, FieldMetadata> mergedProperties, List<Property> properties, Boolean isHiddenOverride,
        MergedPropertyType type) {//www  .  j  a  v a  2 s . co  m
    for (Map.Entry<String, FieldMetadata> entry : mergedProperties.entrySet()) {
        String property = entry.getKey();
        Property prop = new Property();
        FieldMetadata metadata = mergedProperties.get(property);
        prop.setName(property);
        Comparator<Property> comparator = new Comparator<Property>() {
            @Override
            public int compare(Property o1, Property o2) {
                return o1.getName().compareTo(o2.getName());
            }
        };
        Collections.sort(properties, comparator);
        int pos = Collections.binarySearch(properties, prop, comparator);
        if (pos >= 0 && MergedPropertyType.MAPSTRUCTUREKEY != type
                && MergedPropertyType.MAPSTRUCTUREVALUE != type) {
            logWarn: {
                if ((metadata instanceof BasicFieldMetadata)
                        && SupportedFieldType.ID.equals(((BasicFieldMetadata) metadata).getFieldType())) {
                    //don't warn for id field collisions, but still ignore the colliding fields
                    break logWarn;
                }
                LOG.warn("Detected a field name collision (" + metadata.getTargetClass() + "." + property
                        + ") during inspection for the inheritance line starting with ("
                        + inheritanceLine[0].getName()
                        + "). Ignoring the additional field. This can occur most commonly when using the @AdminPresentationAdornedTargetCollection and the collection type and target class have field names in common. This situation should be avoided, as the system will strip the repeated fields, which can cause unpredictable behavior.");
            }
            continue;
        }
        properties.add(prop);
        prop.setMetadata(metadata);
        if (isHiddenOverride && prop.getMetadata() instanceof BasicFieldMetadata) {
            //this only makes sense for non collection types
            ((BasicFieldMetadata) prop.getMetadata()).setVisibility(VisibilityEnum.HIDDEN_ALL);
        }
    }
}

From source file:com.panet.imeta.repository.Repository.java

private synchronized int searchStepAttributeIndexInBuffer(long id_step, String code, long nr)
        throws KettleValueException {
    Object[] key = new Object[] { new Long(id_step), // ID_STEP
            code, // CODE
            new Long(nr), // NR
    };//from w  w  w .ja v a2 s . c  o m

    int index = Collections.binarySearch(stepAttributesBuffer, key, new StepAttributeComparator());

    if (index >= stepAttributesBuffer.size() || index < 0)
        return -1;

    // 
    // Check this... If it is not in there, we didn't find it!
    // stepAttributesRowMeta.compare returns 0 when there are conversion
    // issues
    // so the binarySearch could have 'found' a match when there really
    // isn't one
    //
    Object[] look = stepAttributesBuffer.get(index);

    if (stepAttributesRowMeta.compare(look, key, KEY_POSITIONS) == 0) {
        return index;
    }

    return -1;
}

From source file:org.broadleafcommerce.openadmin.server.service.persistence.module.BasicPersistenceModule.java

protected void extractPropertiesFromMetadata(Class<?>[] inheritanceLine,
        Map<String, FieldMetadata> mergedProperties, List<Property> properties, Boolean isHiddenOverride,
        MergedPropertyType type) {//www.  j a v  a2s. c o m
    for (Map.Entry<String, FieldMetadata> entry : mergedProperties.entrySet()) {
        String property = entry.getKey();
        Property prop = new Property();
        FieldMetadata metadata = mergedProperties.get(property);
        prop.setName(property);
        Comparator<Property> comparator = new Comparator<Property>() {
            @Override
            public int compare(Property o1, Property o2) {
                return o1.getName().compareTo(o2.getName());
            }
        };
        Collections.sort(properties, comparator);
        int pos = Collections.binarySearch(properties, prop, comparator);
        if (pos >= 0 && MergedPropertyType.MAPSTRUCTUREKEY != type
                && MergedPropertyType.MAPSTRUCTUREVALUE != type) {
            logWarn: {
                if ((metadata instanceof BasicFieldMetadata)
                        && SupportedFieldType.ID.equals(((BasicFieldMetadata) metadata).getFieldType())) {
                    //don't warn for id field collisions, but still ignore the colliding fields
                    break logWarn;
                }
                //LOG.warn("Detected a field name collision (" + metadata.getTargetClass() + "." + property + ") during inspection for the inheritance line starting with (" + inheritanceLine[0].getName() + "). Ignoring the additional field. This can occur most commonly when using the @AdminPresentationAdornedTargetCollection and the collection type and target class have field names in common. This situation should be avoided, as the system will strip the repeated fields, which can cause unpredictable behavior.");
            }
            continue;
        }
        properties.add(prop);
        prop.setMetadata(metadata);
        if (isHiddenOverride && prop.getMetadata() instanceof BasicFieldMetadata) {
            //this only makes sense for non collection types
            ((BasicFieldMetadata) prop.getMetadata()).setVisibility(VisibilityEnum.HIDDEN_ALL);
        }
    }
}

From source file:com.inkubator.hrm.service.impl.TempAttendanceRealizationServiceImpl.java

private Boolean isDateIsInListDate(Date dateToCheck, List<Date> listDate) {
    return Collections.binarySearch(listDate, dateToCheck, new MyDateComparator()) >= 0;
}

From source file:pe.gob.mef.gescon.web.ui.ContenidoMB.java

public void onListTipoConocimientoChange(AjaxBehaviorEvent event) {
    try {//w w w  .ja va  2 s  . co m
        if (event != null) {
            final BigDecimal id = (BigDecimal) ((SelectOneMenu) event.getSource()).getValue();
            this.setIdTipoConocimiento(id);
            if (id != null) {
                HashMap filters = new HashMap();
                filters.put("ntipoconocimientoid", id);
                ConocimientoService service = (ConocimientoService) ServiceFinder
                        .findBean("ConocimientoService");
                if (this.getSelectedContenido() != null) {
                    filters.put("nconocimientoid", this.getSelectedContenido().getNconocimientoid().toString());
                    this.setListaTargetVinculos(new ArrayList());
                    List<Consulta> lista = service.getConcimientosVinculados(filters);
                    Collections.sort(lista, Consulta.Comparators.ID);
                    if (id.equals(Constante.BASELEGAL)) {
                        for (Consulta ele : lista) {
                            int pos = Collections.binarySearch(this.getListaTargetVinculosBL(), ele,
                                    Consulta.Comparators.ID);
                            if (pos < 0) {
                                this.getListaTargetVinculosBL().add(ele);
                            }
                        }
                        this.getListaTargetVinculos().addAll(this.getListaTargetVinculosBL());
                    } else if (id.equals(Constante.PREGUNTAS)) {
                        for (Consulta ele : lista) {
                            int pos = Collections.binarySearch(this.getListaTargetVinculosPR(), ele,
                                    Consulta.Comparators.ID);
                            if (pos < 0) {
                                this.getListaTargetVinculosPR().add(ele);
                            }
                        }
                        this.getListaTargetVinculos().addAll(this.getListaTargetVinculosPR());
                    } else if (id.equals(Constante.WIKI)) {
                        for (Consulta ele : lista) {
                            int pos = Collections.binarySearch(this.getListaTargetVinculosWK(), ele,
                                    Consulta.Comparators.ID);
                            if (pos < 0) {
                                this.getListaTargetVinculosWK().add(ele);
                            }
                        }
                        this.getListaTargetVinculos().addAll(this.getListaTargetVinculosWK());
                    } else if (id.equals(Constante.CONTENIDO)) {
                        for (Consulta ele : lista) {
                            int pos = Collections.binarySearch(this.getListaTargetVinculosCT(), ele,
                                    Consulta.Comparators.ID);
                            if (pos < 0) {
                                this.getListaTargetVinculosCT().add(ele);
                            }
                        }
                        this.getListaTargetVinculos().addAll(this.getListaTargetVinculosCT());
                    } else if (id.equals(Constante.BUENAPRACTICA)) {
                        for (Consulta ele : lista) {
                            int pos = Collections.binarySearch(this.getListaTargetVinculosBP(), ele,
                                    Consulta.Comparators.ID);
                            if (pos < 0) {
                                this.getListaTargetVinculosBP().add(ele);
                            }
                        }
                        this.getListaTargetVinculos().addAll(this.getListaTargetVinculosBP());
                    } else if (id.equals(Constante.OPORTUNIDADMEJORA)) {
                        for (Consulta ele : lista) {
                            int pos = Collections.binarySearch(this.getListaTargetVinculosOM(), ele,
                                    Consulta.Comparators.ID);
                            if (pos < 0) {
                                this.getListaTargetVinculosOM().add(ele);
                            }
                        }
                        this.getListaTargetVinculos().addAll(this.getListaTargetVinculosOM());
                    }
                } else {
                    if (id.equals(Constante.BASELEGAL)) {
                        this.setListaTargetVinculos(this.getListaTargetVinculosBL());
                    } else if (id.equals(Constante.PREGUNTAS)) {
                        this.setListaTargetVinculos(this.getListaTargetVinculosPR());
                    } else if (id.equals(Constante.WIKI)) {
                        this.setListaTargetVinculos(this.getListaTargetVinculosWK());
                    } else if (id.equals(Constante.CONTENIDO)) {
                        this.setListaTargetVinculos(this.getListaTargetVinculosCT());
                    } else if (id.equals(Constante.BUENAPRACTICA)) {
                        this.setListaTargetVinculos(this.getListaTargetVinculosBP());
                    } else if (id.equals(Constante.OPORTUNIDADMEJORA)) {
                        this.setListaTargetVinculos(this.getListaTargetVinculosOM());
                    }
                }
                if (CollectionUtils.isNotEmpty(this.getListaTargetVinculos())) {
                    List<String> ids = new ArrayList<String>();
                    for (Consulta c : this.getListaTargetVinculos()) {
                        ids.add(c.getIdconocimiento().toString());
                    }
                    String filter = StringUtils.join(ids, ',');
                    if (id.equals(Constante.WIKI)) {
                        filter = filter.concat(",")
                                .concat(this.getSelectedContenido().getNconocimientoid().toString());
                    }
                    filters.put("nconocimientovinc", filter);
                }
                if (id.equals(Constante.BASELEGAL)) {
                    this.setListaSourceVinculosBL(service.getConcimientosDisponibles(filters));
                    this.setListaSourceVinculos(this.getListaSourceVinculosBL());
                } else if (id.equals(Constante.PREGUNTAS)) {
                    this.setListaSourceVinculosPR(service.getConcimientosDisponibles(filters));
                    this.setListaSourceVinculos(this.getListaSourceVinculosPR());
                } else if (id.equals(Constante.WIKI)) {
                    this.setListaSourceVinculosWK(service.getConcimientosDisponibles(filters));
                    this.setListaSourceVinculos(this.getListaSourceVinculosWK());
                } else if (id.equals(Constante.CONTENIDO)) {
                    this.setListaSourceVinculosCT(service.getConcimientosDisponibles(filters));
                    this.setListaSourceVinculos(this.getListaSourceVinculosCT());
                } else if (id.equals(Constante.BUENAPRACTICA)) {
                    this.setListaSourceVinculosBP(service.getConcimientosDisponibles(filters));
                    this.setListaSourceVinculos(this.getListaSourceVinculosBP());
                } else if (id.equals(Constante.OPORTUNIDADMEJORA)) {
                    this.setListaSourceVinculosOM(service.getConcimientosDisponibles(filters));
                    this.setListaSourceVinculos(this.getListaSourceVinculosOM());
                }
                this.setPickList(new DualListModel<Consulta>(this.getListaSourceVinculos(),
                        this.getListaTargetVinculos()));
            }
        }
    } catch (Exception e) {
        e.getMessage();
        e.printStackTrace();
    }
}