Example usage for java.util List retainAll

List of usage examples for java.util List retainAll

Introduction

In this page you can find the example usage for java.util List retainAll.

Prototype

boolean retainAll(Collection<?> c);

Source Link

Document

Retains only the elements in this list that are contained in the specified collection (optional operation).

Usage

From source file:org.wso2.carbon.appmgt.impl.APIConsumerImpl.java

/**
 * Check whether given Tier is denied for the user
 *
 * @param tierName/*from www  .j av a2 s  .c o m*/
 * @return
 * @throws org.wso2.carbon.appmgt.api.AppManagementException if failed to get the tiers
 */
public boolean isTierDeneid(String tierName) throws AppManagementException {
    String[] currentUserRoles = new String[0];
    try {
        if (tenantId != 0) {
            /* Get the roles of the Current User */
            currentUserRoles = ((UserRegistry) ((UserAwareAPIConsumer) this).registry).getUserRealm()
                    .getUserStoreManager().getRoleListOfUser(((UserRegistry) this.registry).getUserName());
            TierPermissionDTO tierPermission = appMDAO.getTierPermission(tierName, tenantId);
            if (tierPermission == null) {
                return false;
            } else {
                List<String> currentRolesList = new ArrayList<String>(Arrays.asList(currentUserRoles));
                List<String> roles = new ArrayList<String>(Arrays.asList(tierPermission.getRoles()));
                currentRolesList.retainAll(roles);
                if (AppMConstants.TIER_PERMISSION_ALLOW.equals(tierPermission.getPermissionType())) {
                    if (currentRolesList.size() == 0) {
                        return true;
                    }
                } else {
                    if (currentRolesList.size() > 0) {
                        return true;
                    }
                }
            }
        }
    } catch (org.wso2.carbon.user.api.UserStoreException e) {
        log.error("cannot retrieve user role list for tenant" + tenantDomain);
    }
    return false;
}

From source file:org.wso2.carbon.appmgt.impl.APIConsumerImpl.java

/**
 * Returns a list of tiers denied/*from   w  w w .  j a  v a  2s  .  com*/
 *
 * @return Set<Tier>
 */
public Set<String> getDeniedTiers() throws AppManagementException {
    Set<String> deniedTiers = new HashSet<String>();
    String[] currentUserRoles = new String[0];
    try {
        if (tenantId != 0) {
            /* Get the roles of the Current User */
            currentUserRoles = ((UserRegistry) ((UserAwareAPIConsumer) this).registry).getUserRealm()
                    .getUserStoreManager().getRoleListOfUser(((UserRegistry) this.registry).getUserName());

            Set<TierPermissionDTO> tierPermissions = appMDAO.getTierPermissions(tenantId);
            for (TierPermissionDTO tierPermission : tierPermissions) {
                String type = tierPermission.getPermissionType();

                List<String> currentRolesList = new ArrayList<String>(Arrays.asList(currentUserRoles));
                List<String> roles = new ArrayList<String>(Arrays.asList(tierPermission.getRoles()));
                currentRolesList.retainAll(roles);

                if (AppMConstants.TIER_PERMISSION_ALLOW.equals(type)) {
                    /* Current User is not allowed for this Tier*/
                    if (currentRolesList.size() == 0) {
                        deniedTiers.add(tierPermission.getTierName());
                    }
                } else {
                    /* Current User is denied for this Tier*/
                    if (currentRolesList.size() > 0) {
                        deniedTiers.add(tierPermission.getTierName());
                    }
                }
            }
        }
    } catch (org.wso2.carbon.user.api.UserStoreException e) {
        log.error("cannot retrieve user role list for tenant" + tenantDomain);
    }
    return deniedTiers;
}

From source file:nl.strohalm.cyclos.services.groups.GroupServiceImpl.java

@Override
public List<MemberGroup> getPossibleInitialGroups(GroupFilter groupFilter) {
    if (LoggedUser.hasUser() && LoggedUser.isBroker()) {
        BrokerGroup brokerGroup = LoggedUser.group();
        brokerGroup = fetchService.fetch(brokerGroup, BrokerGroup.Relationships.POSSIBLE_INITIAL_GROUPS);
        return (List<MemberGroup>) brokerGroup.getPossibleInitialGroups();
    }//from w w  w. j  a  v a  2s  .  c  o  m
    groupFilter = fetchService.fetch(groupFilter, GroupFilter.Relationships.GROUPS);
    final GroupQuery query = new GroupQuery();
    query.setNatures(Group.Nature.BROKER, Group.Nature.MEMBER);
    final List<MemberGroup> initialGroups = new ArrayList<MemberGroup>();
    for (Group group : search(query)) {
        final MemberGroup memberGroup = (MemberGroup) fetchService.fetch(group);
        if (memberGroup.isInitialGroup()) {
            initialGroups.add(memberGroup);
        }
    }
    if (groupFilter != null) {
        // If group filter is used, only return groups in that group filter
        initialGroups.retainAll(groupFilter.getGroups());
    }
    return initialGroups;
}

From source file:ubic.gemma.analysis.expression.coexpression.GeneCoexpressionServiceImpl.java

/**
 * @param baseSet//ww w. j a v  a2  s  .  com
 * @param eeIds
 * @param queryGenes
 * @param stringency
 * @param maxResults
 * @param queryGenesOnly
 * @return
 */
private Collection<CoexpressionValueObjectExt> getFilteredCannedAnalysisResults2(
        ExpressionExperimentSet baseSet, Collection<Long> eeIds, Collection<Gene> queryGenes, int stringency,
        int maxResults, boolean queryGenesOnly, boolean skipDetails) {

    if (queryGenes.isEmpty()) {
        throw new IllegalArgumentException("No genes in query");
    }

    List<ExpressionExperimentValueObject> eevos = null;
    List<Long> filteredEeIds = null;

    eevos = getSortedEEvos(eeIds);

    if (eevos.isEmpty()) {
        throw new IllegalArgumentException("There are no usable experiments in the selected set");
    }

    filteredEeIds = (List<Long>) EntityUtils.getIds(eevos);
    /*
     * We get this prior to filtering so it matches the vectors stored with the analysis.
     */
    expressionExperimentSetService.thaw(baseSet);
    List<Long> positionToIDMap = Gene2GenePopulationServiceImpl
            .getPositionToIdMap(EntityUtils.getIds(baseSet.getExperiments()));

    /*
     * This set of links must be filtered to include those in the data sets being analyzed.
     */
    Map<Long, Collection<Gene2GeneCoexpression>> gg2gs = getRawCoexpression(queryGenes, stringency, maxResults,
            queryGenesOnly);

    List<CoexpressionValueObjectExt> ecvos = new ArrayList<CoexpressionValueObjectExt>();

    Collection<Long> seenGene2Gene = new HashSet<Long>();

    Collection<Long> queryGeneIds = gg2gs.keySet();

    // return empty collection if no coexpression results
    if (queryGeneIds.isEmpty()) {
        return ecvos;
    }

    Collection<Long> gidsNeeded = new HashSet<Long>();

    StopWatch timerGeneLoad = new StopWatch();

    for (Long gid : queryGeneIds) {

        Element e = this.getGeneLightWeightCache().getCache().get(gid);

        if (e == null) {
            gidsNeeded.add(gid);
        }

    }

    if (!gidsNeeded.isEmpty()) {

        Collection<Gene> justLoadedGenes = geneService.loadThawedLiter(gidsNeeded);

        for (Gene g : justLoadedGenes) {

            this.getGeneLightWeightCache().getCache().put(new Element(g.getId(), g));
        }
    }

    if (timerGeneLoad.getTime() > 100) {
        log.info("Loading and caching query genes took " + timerGeneLoad.getTime() + "ms");
    }

    timerGeneLoad.reset();
    timerGeneLoad.start();

    gidsNeeded = new HashSet<Long>();

    // load all genes first
    for (Long queryGid : queryGeneIds) {

        Collection<Gene2GeneCoexpression> g2gs = gg2gs.get(queryGid);

        for (Gene2GeneCoexpression g2g : g2gs) {

            Gene foundGene = g2g.getFirstGene().getId().equals(queryGid) ? g2g.getSecondGene()
                    : g2g.getFirstGene();

            if (this.getGeneLightWeightCache().getCache().get(foundGene.getId()) == null) {
                gidsNeeded.add(foundGene.getId());
            }

        }

    }

    // Put all needed genes in Cache to that they are guaranteed to be there
    // for this method call
    if (!gidsNeeded.isEmpty()) {

        Collection<Gene> forCache = geneService.loadThawedLiter(gidsNeeded);

        for (Gene g : forCache) {
            this.getGeneLightWeightCache().getCache().put(new Element(g.getId(), g));
        }

    }
    if (timerGeneLoad.getTime() > 100) {
        log.info("Loading and caching found genes took " + timerGeneLoad.getTime() + "ms");
    }

    StopWatch timer = new StopWatch();
    Collection<Long> allUsedGenes = new HashSet<Long>();

    for (Long queryGid : queryGeneIds) {
        timer.reset();
        timer.start();

        Gene qGene = (Gene) this.getGeneLightWeightCache().getCache().get(queryGid).getValue();

        if (!qGene.getTaxon().equals(baseSet.getTaxon())) {
            throw new IllegalArgumentException(
                    "Mismatch between taxon for expression experiment set selected and gene queries");
        }

        allUsedGenes.add(queryGid);

        /*
         * For summary statistics
         */
        CountingMap<Long> supportCount = new CountingMap<Long>();

        Collection<Long> allDatasetsWithSpecificProbes = new HashSet<Long>();
        Collection<Long> allTestedDataSets = new HashSet<Long>();

        Collection<Gene2GeneCoexpression> g2gs = gg2gs.get(queryGid);

        assert g2gs != null;

        List<Long> relevantEEIdList = null;

        if (!skipDetails) {
            relevantEEIdList = getRelevantEEidsForBitVector(positionToIDMap, g2gs);
            relevantEEIdList.retainAll(filteredEeIds);
        }
        GeneValueObject queryGeneValueObject = new GeneValueObject(qGene);

        Map<Long, Collection<Gene2GeneCoexpression>> foundGenes = new HashMap<Long, Collection<Gene2GeneCoexpression>>();

        if (timer.getTime() > 100) {
            log.info("Postprocess " + qGene.getOfficialSymbol() + " Phase I: " + timer.getTime() + "ms");
        }
        timer.stop();
        timer.reset();
        timer.start();

        for (Gene2GeneCoexpression g2g : g2gs) {

            Gene foundGene = g2g.getFirstGene().getId().equals(queryGid) ? g2g.getSecondGene()
                    : g2g.getFirstGene();

            allUsedGenes.add(foundGene.getId());

            // use this flag to test for a duplicate link with opposite
            // stringency support (positive/negative)
            boolean testForDuplicateFlag = false;

            // duplicate found genes can occur when there is both positive
            // and negative support for the same link
            // Keep track of the found genes that we can correctly identify
            // duplicates.
            // All keep the g2g object for debugging purposes.
            if (foundGenes.containsKey(foundGene.getId())) {

                testForDuplicateFlag = true;

            } else {
                foundGenes.put(foundGene.getId(), new ArrayList<Gene2GeneCoexpression>());
            }

            foundGenes.get(foundGene.getId()).add(g2g);

            CoexpressionValueObjectExt cvo = new CoexpressionValueObjectExt();

            Long idToGet = foundGene.getId();

            foundGene = (Gene) this.getGeneLightWeightCache().getCache().get(idToGet).getValue();

            if (foundGene == null) {
                log.error("Gene id:" + idToGet + " Not in the GeneLightWeightCache, something is wrong");
                continue;
            }

            cvo.setQueryGene(queryGeneValueObject);
            cvo.setFoundGene(new GeneValueObject(foundGene));

            List<Long> supportingDatasets = Gene2GenePopulationServiceImpl.getSupportingExperimentIds(g2g,
                    positionToIDMap);

            // necessary in case any were filtered out.
            supportingDatasets.retainAll(filteredEeIds);
            cvo.setSupportingExperiments(supportingDatasets);

            List<Long> testingDatasets;
            List<Long> specificDatasets;
            if (!skipDetails) {

                testingDatasets = Gene2GenePopulationServiceImpl.getTestedExperimentIds(g2g, positionToIDMap);
                testingDatasets.retainAll(filteredEeIds);

                /*
                 * necesssary in case any were filtered out (for example, if this is a virtual analysis; or there
                 * were 'troubled' ees. Note that 'supporting' includes 'non-specific' if they were recorded by the
                 * analyzer.
                 */

                specificDatasets = Gene2GenePopulationServiceImpl.getSpecificExperimentIds(g2g,
                        positionToIDMap);

                /*
                 * Specific probe EEids contains 1 even if the data set wasn't supporting.
                 */
                specificDatasets.retainAll(supportingDatasets);

                int numTestingDatasets = testingDatasets.size();
                int numSupportingDatasets = supportingDatasets.size();

                /*
                 * SANITY CHECKS
                 */
                assert specificDatasets.size() <= numSupportingDatasets;
                assert numTestingDatasets >= numSupportingDatasets;
                assert numTestingDatasets <= eevos.size();

                cvo.setDatasetVector(getDatasetVector(supportingDatasets, testingDatasets, specificDatasets,
                        relevantEEIdList));

                if (testForDuplicateFlag) {

                    testAndModifyDuplicateResultForOppositeStringency(ecvos, qGene, foundGene, g2g.getEffect(),
                            numSupportingDatasets, specificDatasets.size(), numTestingDatasets);

                    continue;

                } else if (numSupportingDatasets < stringency) {// check in case any data sets were filtered
                                                                // out.(i.e., we're not
                                                                // interested in the full set of data sets that
                                                                // were used in the
                                                                // original analysis.
                    continue;
                }

                allTestedDataSets.addAll(testingDatasets);

                int supportFromSpecificProbes = specificDatasets.size();

                if (g2g.getEffect() < 0) {
                    cvo.setPosSupp(0);
                    cvo.setNegSupp(numSupportingDatasets);
                    if (numSupportingDatasets != supportFromSpecificProbes)
                        cvo.setNonSpecNegSupp(numSupportingDatasets - supportFromSpecificProbes);

                } else {
                    cvo.setPosSupp(numSupportingDatasets);
                    if (numSupportingDatasets != supportFromSpecificProbes)
                        cvo.setNonSpecPosSupp(numSupportingDatasets - supportFromSpecificProbes);
                    cvo.setNegSupp(0);
                }
                cvo.setSupportKey(Math.max(cvo.getPosSupp(), cvo.getNegSupp()));
                cvo.setNumTestedIn(numTestingDatasets);

                for (Long id : supportingDatasets) {
                    supportCount.increment(id);
                }

                allDatasetsWithSpecificProbes.addAll(specificDatasets);

            } else {

                int numSupportingDatasets = supportingDatasets.size();

                if (testForDuplicateFlag) {

                    testAndModifyDuplicateResultForOppositeStringency(ecvos, qGene, foundGene, g2g.getEffect(),
                            numSupportingDatasets, null, null);

                    continue;

                } else if (numSupportingDatasets < stringency) {
                    continue;
                }

                if (g2g.getEffect() < 0) {
                    cvo.setPosSupp(0);
                    cvo.setNegSupp(numSupportingDatasets);
                } else {
                    cvo.setPosSupp(numSupportingDatasets);
                    cvo.setNegSupp(0);
                }

                cvo.setSupportKey(Math.max(cvo.getPosSupp(), cvo.getNegSupp()));

            }

            cvo.setSortKey();

            /*
             * This check prevents links from being shown twice when we do "among query genes". We don't skip
             * entirely so we get the counts for the summary table populated correctly.
             */
            if (!seenGene2Gene.contains(g2g.getId())) {
                ecvos.add(cvo);
            }

            seenGene2Gene.add(g2g.getId());

        }

        if (timer.getTime() > 300) {
            log.info("Postprocess " + g2gs.size() + " results for " + qGene.getOfficialSymbol() + " Phase II: "
                    + timer.getTime() + "ms");
        }
        timer.stop();

        Collections.sort(ecvos);

    } // Over querygenes

    populateNodeDegree(ecvos, allUsedGenes, filteredEeIds);
    return ecvos;

}

From source file:com.linkedin.pinot.controller.helix.core.PinotHelixResourceManager.java

/**
 * Computes the server nodes that are untagged and free to be used.
 * @return List of untagged online server instances.
 *//*  w  ww  .  j  ava2 s .c  om*/
public List<String> getOnlineUnTaggedServerInstanceList() {
    final List<String> instanceList = _helixAdmin.getInstancesInClusterWithTag(_helixClusterName,
            CommonConstants.Helix.UNTAGGED_SERVER_INSTANCE);
    final List<String> liveInstances = _helixDataAccessor.getChildNames(_keyBuilder.liveInstances());
    instanceList.retainAll(liveInstances);
    return instanceList;
}

From source file:com.linkedin.pinot.controller.helix.core.PinotHelixResourceManager.java

/**
 * Computes the broker nodes that are untagged and free to be used.
 * @return List of online untagged broker instances.
 *//*from ww w . ja va 2 s .  c  o m*/
public List<String> getOnlineUnTaggedBrokerInstanceList() {

    final List<String> instanceList = _helixAdmin.getInstancesInClusterWithTag(_helixClusterName,
            CommonConstants.Helix.UNTAGGED_BROKER_INSTANCE);
    final List<String> liveInstances = _helixDataAccessor.getChildNames(_keyBuilder.liveInstances());
    instanceList.retainAll(liveInstances);
    return instanceList;
}

From source file:org.richfaces.tests.metamer.ftest.MatrixConfigurator.java

private List<TemplatesList> getTemplatesParameter(Class<?> testClass, Class<?> parameterType,
        Templates templatesAnnotation, Map<Field, List<? extends Object>> parameters) {
    if (parameterType != TemplatesList.class) {
        throw new IllegalStateException(
                "only " + Template.class.getName() + " fields can be annotated with @Inject @Templates");
    }/*from  w w  w . j  a  v a  2s  .c o  m*/

    List<TemplatesList> templates = null;

    // if templates was already set, load them
    if (templatesField != null) {
        templates = (List<TemplatesList>) parameters.get(templatesField);
    }

    // get user defined templates
    List<TemplatesList> userTemplates = MetamerProperties.getTemplates();

    // if "value" is defined, takes precedens
    if (templatesAnnotation.value().length > 0) {
        templates = MetamerProperties.parseTemplates(templatesAnnotation.value());
    }

    // include all "include" to current list
    if (templatesAnnotation.include().length > 0) {
        List<TemplatesList> includeTemplates = MetamerProperties.parseTemplates(templatesAnnotation.include());
        if (templates == null) {
            templates = includeTemplates;
        } else {
            includeTemplates.removeAll(templates);
            templates.addAll(includeTemplates);
        }
    }

    // exclude all "exclude" from current list
    if (templatesAnnotation.exclude().length > 0) {
        List<TemplatesList> excludeTemplates = MetamerProperties.parseTemplates(templatesAnnotation.exclude());
        if (templates != null) {
            templates.removeAll(excludeTemplates);
        }
    }

    // remove all templates which wasn't in user defined set
    if (userTemplates != null) {
        if (templates == null) {
            templates = userTemplates;
        } else {
            templates.retainAll(userTemplates);
        }
    }

    return templates;
}

From source file:hw.java

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed

    //        ResultSet rs1;
    //         //from w  ww . j  a va 2s .c o  m
    //        try {
    MongoCollection<Document> coll = db.getCollection("business");
    //MongoCollection<Document> catcollection = db.getCollection("catout");
    MongoCollection<Document> rcoll = db.getCollection("review");
    //final DBCollection collection = db.getCollection("review");
    MongoCollection<Document> ccoll = db.getCollection("checkin");
    String from_dropdown = jComboBox3.getSelectedItem().toString();
    String to_dropdown = jComboBox6.getSelectedItem().toString();

    String from_value = jTextField9.getText();
    String to_value = jTextField10.getText();
    String check_count_value = jTextField11.getText();

    String check_count_dropdown = jComboBox8.getSelectedItem().toString();
    String fromdate_value = jTextField1.getText();
    String todate_value = jTextField3.getText();
    String stars_value = jTextField12.getText();
    String votes_value = jTextField13.getText();
    String stars_dropdown = jComboBox4.getSelectedItem().toString();
    String votes_dropdown = jComboBox12.getSelectedItem().toString();
    String select = jComboBox1.getSelectedItem().toString();
    List<String> category_value = jList2.getSelectedValuesList();
    String poi = jComboBox5.getSelectedItem().toString();
    String proximity = jComboBox2.getSelectedItem().toString();
    BasicDBObject qryBusiness = new BasicDBObject();
    BasicDBObject qryReview = new BasicDBObject();
    BasicDBList BusinessList = new BasicDBList();
    BasicDBList ReviewList = new BasicDBList();
    FindIterable<Document> cursor;
    FindIterable<Document> cursor1;
    List<String> catout = new ArrayList<String>();
    List<String> proout = new ArrayList<String>();
    List<String> checkinout = new ArrayList<String>();
    List<String> reviewout = new ArrayList<String>();
    List<String> finalout = new ArrayList<String>();

    if (category_value.isEmpty())//&& poi == null && proximity == null && from_value == null && fromdate_value == null)
    {
        BasicDBObject nu = new BasicDBObject();
        FindIterable<Document> fi;
        fi = coll.find(nu);
        jTextField8.setText("db.business.find()");
        String Columnames[] = { "business_id", "state", "city", "stars" };
        DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel();
        dtm.setColumnCount(0);
        dtm.setRowCount(0);
        int numberOfColumns = Columnames.length;

        for (int i = 0; i < numberOfColumns; i++) {
            String name = Columnames[i];
            dtm.addColumn(name);

        }

        fi.forEach(new Block<Document>() {
            @Override
            public void apply(final Document document) {

                Object rowData[] = new Object[numberOfColumns];

                rowData[0] = document.get("business_id");
                rowData[1] = document.get("state");
                rowData[2] = document.get("city");
                rowData[3] = document.get("stars");

                dtm.addRow(rowData);
                rowData = null;
            }
        });

        jTable1.setRowSelectionAllowed(true);
        jTable1.setModel(dtm);

        jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        dtm.fireTableDataChanged();

    } else {

        Object[] l = jList2.getSelectedValues();
        //BasicDBList subcat = new BasicDBList();
        BasicDBList clist = new BasicDBList();
        BasicDBObject qrycategory;
        if (l.length > 0) {
            for (int i = 0; i < l.length; i++) {
                BasicDBObject buinessop = new BasicDBObject("categories", l[i]);
                clist.add(buinessop);
            }
        }
        qrycategory = new BasicDBObject("$or", clist);
        //               subcatquery = new BasicDBObject("$out","subcat");
        //               subcat.add(qrycategory);
        //               subcat.add(subcatquery);
        //               System.out.println(subcat);
        cursor = coll.find(qrycategory);

        System.out.println(qrycategory);
        //BasicDBObject category = new BasicDBObject();
        cursor.forEach(new Block<Document>() {
            @Override
            public void apply(final Document document) {

                System.out.println(document.get("business_id"));
                //category.put((String)document.get("business_id"), db);

                catout.add((String) document.get("business_id"));
                //                                System.out.println(document.get("state"));
                //                                System.out.println(document.get("city"));
                //                                System.out.println(document.get("stars"));
                //                               

            }
        });

        MongoCollection<Document> collecttest = db.getCollection("test");
        String[] addresses5 = { "", "4840 E Indian School Rd\\nSte 101\\nPhoenix, AZ 85018",
                "631 S Main St\\nDe Forest, WI 53532", "5813 Main St\\nMc Farland, WI 53558",
                "2039 Allen Blvd\\nMiddleton, WI 53562", "6230 University Ave\\nMiddleton, WI 53562" };
        String[][] latLong = { { "33.499313000000001", "-111.98375799999999" },
                { "43.2408748", "-89.343721700000003" }, { "43.014164000000001", "-89.288567" },
                { "43.090642000000003", "-89.485168999999999" }, { "43.0910607", "-89.487486700000005" } };

        BasicDBObject queryBusiness = new BasicDBObject();
        BasicDBList businessinputlist = new BasicDBList();

        String selectedAddress = jComboBox5.getSelectedItem().toString();
        String selectedProximity = jComboBox2.getSelectedItem().toString();
        Double pro = Double.parseDouble(selectedProximity) / 3963.2;
        int index = Arrays.asList(addresses5).indexOf(selectedAddress);
        Double Latitude = Double.parseDouble(latLong[index][0]);
        Double Longitude = Double.parseDouble(latLong[index][1]);
        System.out.println("lat" + Latitude);
        System.out.println("longi" + Longitude);
        //BasicDBObject lat = new BasicDBObject(Latitude.toString(),Longitude);
        BasicDBList c1 = new BasicDBList();
        BasicDBList cs = new BasicDBList();
        cs.add(Latitude);
        cs.add(Longitude);
        c1.add(cs);
        c1.add(pro);
        BasicDBObject c = new BasicDBObject("$centerSphere", c1);
        BasicDBObject bq = new BasicDBObject("loc", new BasicDBObject("$geoWithin", c));
        FindIterable<Document> fi;
        fi = collecttest.find(bq);
        System.out.println(bq);
        jTextField8.setText("db.test.find(" + bq + ")");
        fi.forEach(new Block<Document>() {
            @Override
            public void apply(final Document document) {

                System.out.println(document.get("business_id"));

                proout.add((String) document.get("business_id"));

                //System.out.println(document.get("loc"));
            }
        });
        int checkinempty = 0;
        if (from_value == null || to_value == null || check_count_value.equals("0")) {
            checkinempty = 1;
            List<String> pr = new ArrayList<String>(catout);
            System.out.println(pr.size());
            pr.retainAll(proout);
            System.out.println(pr.size());
            String Columnames[] = { "Business_id", "state", "city", "stars" };
            DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel();
            dtm.setColumnCount(0);
            dtm.setRowCount(0);
            int numberOfColumns = Columnames.length;
            Object rowData[] = new Object[numberOfColumns];

            for (int i = 0; i < numberOfColumns; i++) {
                String name = Columnames[i];
                dtm.addColumn(name);

            }
            for (int i = 0; i < pr.size(); i++) {

                rowData[0] = pr.get(i);
                BasicDBObject c11 = new BasicDBObject("business_id", pr.get(i));
                FindIterable<Document> f1;
                f1 = coll.find(c11);
                f1.forEach(new Block<Document>() {
                    @Override
                    public void apply(final Document document) {

                        Object rowData[] = new Object[numberOfColumns];
                        rowData[0] = document.get("business_id");
                        rowData[1] = document.get("state");
                        rowData[2] = document.get("city");
                        rowData[3] = document.get("stars");
                        dtm.addRow(rowData);
                        rowData = null;

                    }
                });

                //                                
                //                                
                //                              

            }

            jTable1.setRowSelectionAllowed(true);
            jTable1.setModel(dtm);

            jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
            dtm.fireTableDataChanged();

        }
        if (checkinempty != 1) {

            BasicDBList checkinputlist = new BasicDBList();
            //               
            ArrayList<String> list1;
            list1 = new ArrayList<String>();
            list1.add("0");
            list1.add("1");
            list1.add("2");
            list1.add("3");
            list1.add("4");
            list1.add("5");
            list1.add("6");

            int from = list1.indexOf(from_dropdown);
            int to = list1.indexOf(to_dropdown);
            int count = to - from;
            int hoursfrom1 = Integer.parseInt(from_value);
            int hoursto1 = Integer.parseInt(to_value);
            int count1 = hoursto1 - hoursfrom1;

            FindIterable<Document> iterable = ccoll.find();

            iterable.forEach(new Block<Document>() {
                @Override
                public void apply(final Document document) {
                    //System.out.println(document.get("checkin_info"));

                    String s = document.toJson();
                    s.replace("Document", "");
                    // System.out.println(s);
                    JSONParser parser = new JSONParser();
                    try {
                        Object obj = parser.parse(s);
                        JSONObject doc = (JSONObject) obj;

                        //System.out.println(doc.get("checkin_info"));
                        JSONObject cinfo = (JSONObject) doc.get("checkin_info");
                        if (count >= 0) {
                            long num_checkin = 0;
                            for (int i = from; i <= to; i++) {
                                if (count1 >= 0) {
                                    for (int j = hoursfrom1; j <= hoursto1; j++) {
                                        //System.out.println(cinfo.get(j+"-"+i));
                                        if (cinfo.containsKey(j + "-" + i)) {
                                            num_checkin = num_checkin + (long) cinfo.get(j + "-" + i);
                                            //                              System.out.println(document.get("checkin_info."+j+"-"+i));

                                        }

                                    }
                                }
                            }
                            if (num_checkin != 0) {
                                if (jComboBox8.getSelectedItem().equals(">")
                                        && num_checkin > Long.parseLong(check_count_value)) {
                                    System.out
                                            .println(num_checkin + " checkins into " + doc.get("business_id"));
                                    checkinout.add((String) document.get("business_id"));

                                }
                                if (jComboBox8.getSelectedItem().equals("<")
                                        && num_checkin < Long.parseLong(check_count_value)) {
                                    System.out
                                            .println(num_checkin + " checkins into  " + doc.get("business_id"));
                                    checkinout.add((String) document.get("business_id"));

                                }
                                if (jComboBox8.getSelectedItem().equals("=")
                                        && num_checkin == Long.parseLong(check_count_value)) {
                                    System.out
                                            .println(num_checkin + " checkins into  " + doc.get("business_id"));
                                    checkinout.add((String) document.get("business_id"));

                                }
                            }

                            num_checkin = 0;

                        }
                    } catch (Exception e) {
                        System.out.println(e);
                    }
                }
            });

            if (fromdate_value != null && todate_value != null) {
                BasicDBObject fdv = new BasicDBObject("date", new BasicDBObject("$gte", fromdate_value));
                ReviewList.add(fdv);
                BasicDBObject tdv = new BasicDBObject("date", new BasicDBObject("$lte", todate_value));
                ReviewList.add(tdv);
            }
            if (stars_value != null) {
                if (stars_dropdown == ">") {
                    BasicDBObject sv = new BasicDBObject("stars",
                            new BasicDBObject("$gt", Integer.parseInt(stars_value)));
                    ReviewList.add(sv);
                }
                if (stars_dropdown == "<") {
                    BasicDBObject sv = new BasicDBObject("stars",
                            new BasicDBObject("$lt", Integer.parseInt(stars_value)));
                    ReviewList.add(sv);
                }
                if (stars_dropdown == "=") {
                    BasicDBObject sv = new BasicDBObject("stars", Integer.parseInt(stars_value));
                    ReviewList.add(sv);
                }
            }

            if (votes_value != null) {
                if (votes_dropdown == ">") {
                    BasicDBObject vv = new BasicDBObject("votes",
                            new BasicDBObject("$gt", Integer.parseInt(votes_value)));
                    //ReviewList.add(vv);
                }
                if (votes_dropdown == "<") {
                    BasicDBObject vv = new BasicDBObject("votes",
                            new BasicDBObject("$lt", Integer.parseInt(votes_value)));
                    //ReviewList.add(vv);
                }
                if (votes_dropdown == "=") {
                    BasicDBObject vv = new BasicDBObject("votes", Integer.parseInt(votes_value));
                    //ReviewList.add(vv);
                }
            }
            qryReview = new BasicDBObject("$and", ReviewList);
            if (qryReview == null) {
                //jTextField8.setText("db.review.find()");
                cursor1 = rcoll.find();

            } else {

                //jTextField8.setText("db.review.find("+qryReview.toString()+")");
                cursor1 = rcoll.find(qryReview);
            }

            cursor1.forEach(new Block<Document>() {
                @Override
                public void apply(final Document document) {
                    System.out.println(document.get("business_id"));
                    reviewout.add((String) document.get("business_id"));

                }
            });
            if ("AND".equals(jComboBox1.getSelectedItem().toString())) {
                //jTextField8.setText("db.checkin.find("+"{}"+","+"{business_id"+":1}"+")");
                List<String> fin = new ArrayList<String>(catout);
                System.out.println(fin.size());
                fin.retainAll(proout);
                System.out.println(fin.size());

                fin.retainAll(checkinout);

                System.out.println(fin.size());

                fin.retainAll(reviewout);

                //
                System.out.println(fin.size());
                String Columnames[] = { "Business_id", "state", "city", "stars" };
                DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel();
                dtm.setColumnCount(0);
                dtm.setRowCount(0);
                int numberOfColumns = Columnames.length;
                Object rowData[] = new Object[numberOfColumns];

                for (int i = 0; i < numberOfColumns; i++) {
                    String name = Columnames[i];
                    dtm.addColumn(name);

                }
                for (int i = 0; i < fin.size(); i++) {

                    rowData[0] = fin.get(i);
                    BasicDBObject c11 = new BasicDBObject("business_id", fin.get(i));
                    FindIterable<Document> f1;
                    f1 = coll.find(c11);
                    f1.forEach(new Block<Document>() {
                        @Override
                        public void apply(final Document document) {

                            Object rowData[] = new Object[numberOfColumns];
                            rowData[0] = document.get("business_id");
                            rowData[1] = document.get("state");
                            rowData[2] = document.get("city");
                            rowData[3] = document.get("stars");
                            dtm.addRow(rowData);
                            rowData = null;

                        }
                    });

                    //                                
                    //                                
                    //                              

                }

                jTable1.setRowSelectionAllowed(true);
                jTable1.setModel(dtm);

                jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
                dtm.fireTableDataChanged();

            }
            if ("OR".equals(jComboBox1.getSelectedItem().toString())) {
                //MongoCollection<Document> = db.getCollection("business");
                //jTextField8.setText("db.checkin.find("+"{}"+","+"{business_id"+":1}"+")");
                List<String> fin = new ArrayList<String>(catout); //create a Set with all the elements in a
                fin.addAll(proout);
                System.out.println(fin.size());
                fin.addAll(checkinout);
                System.out.println(fin.size());
                fin.addAll(reviewout);
                System.out.println(fin.size());

                String Columnames[] = { "Business_id", "state", "city", "stars" };
                DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel();
                dtm.setColumnCount(0);
                dtm.setRowCount(0);
                int numberOfColumns = Columnames.length;
                //Object rowData[] = new Object[numberOfColumns];
                //Object rd1,rd2,rd3; 

                for (int i = 0; i < numberOfColumns; i++) {
                    String name = Columnames[i];
                    dtm.addColumn(name);

                }
                for (int i = 0; i < fin.size(); i++) {

                    Object rowData[] = new Object[numberOfColumns];

                    rowData[0] = fin.get(i);

                    BasicDBObject c11 = new BasicDBObject("business_id", fin.get(i));
                    FindIterable<Document> f1;
                    f1 = coll.find(c11);
                    f1.forEach(new Block<Document>() {
                        @Override
                        public void apply(final Document document) {

                            Object rowData[] = new Object[numberOfColumns];
                            rowData[0] = document.get("business_id");
                            rowData[1] = document.get("state");
                            rowData[2] = document.get("city");
                            rowData[3] = document.get("stars");
                            dtm.addRow(rowData);
                            rowData = null;
                        }
                    });

                }
                //                       });

                //Object rowData[] = new Object[numberOfColumns];

                //                                
                //                                
                //                              

                jTable1.setRowSelectionAllowed(true);
                jTable1.setModel(dtm);

                jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
                dtm.fireTableDataChanged();

            }
            if (qryBusiness == null) {
                //jTextField8.setText("db.business.find()");
                cursor = coll.find();

            } else {

                //jTextField8.setText("db.business.find("+qryBusiness.toString()+")");
                cursor = coll.find(qryBusiness);
            }

            //         } catch (SQLException ex) {
            //             Logger.getLogger(hw.class.getName()).log(Level.SEVERE, null, ex);
            //         }
            //             
            //             
            //         
            //     

        }

    }
}