Example usage for java.util HashSet addAll

List of usage examples for java.util HashSet addAll

Introduction

In this page you can find the example usage for java.util HashSet addAll.

Prototype

boolean addAll(Collection<? extends E> c);

Source Link

Document

Adds all of the elements in the specified collection to this set if they're not already present (optional operation).

Usage

From source file:com.isoftstone.proxy.utils.ProxyPool.java

/**
 * ???./*from www. j  av  a2s.  c o  m*/
 * @param proxyList ?.
 */
public void insertProxyList(List<ProxyVo> proxyList) {
    if (CollectionUtils.isEmpty(proxyList)) {
        return;
    }
    //--HashSet??.
    HashSet<ProxyVo> hashSet = new HashSet<ProxyVo>();
    if (CollectionUtils.isNotEmpty(this.proxyQueue)) {
        hashSet.addAll(this.proxyQueue);
    }
    hashSet.addAll(proxyList);
    this.proxyQueue.clear();
    try {
        for (ProxyVo proxyVo : hashSet) {
            this.proxyQueue.offer(proxyVo, 1, TimeUnit.SECONDS);
        }
    } catch (InterruptedException e) {
        LOG.error("InterruptedException", e);
    }
}

From source file:org.apache.solr.client.solrj.SolrSchemalessExampleTest.java

@Test
public void testFieldMutating() throws Exception {
    HttpSolrClient client = (HttpSolrClient) getSolrClient();
    client.deleteByQuery("*:*");
    client.commit();//from  w ww  .j a v a 2 s .c  om
    assertNumFound("*:*", 0); // make sure it got in
    // two docs, one with uniqueKey, another without it
    String json = "{\"name one\": \"name\"} " + "{\"name  two\" : \"name\"}" + "{\"first-second\" : \"name\"}"
            + "{\"x+y\" : \"name\"}" + "{\"p%q\" : \"name\"}" + "{\"p.q\" : \"name\"}" + "{\"a&b\" : \"name\"}";
    HttpClient httpClient = client.getHttpClient();
    HttpPost post = new HttpPost(client.getBaseURL() + "/update/json/docs");
    post.setHeader("Content-Type", "application/json");
    post.setEntity(new InputStreamEntity(new ByteArrayInputStream(json.getBytes("UTF-8")), -1));
    HttpResponse response = httpClient.execute(post);
    assertEquals(200, response.getStatusLine().getStatusCode());
    client.commit();
    List<String> expected = Arrays.asList("name_one", "name__two", "first-second", "a_b", "p_q", "p.q", "x_y");
    HashSet set = new HashSet();
    QueryResponse rsp = assertNumFound("*:*", expected.size());
    for (SolrDocument doc : rsp.getResults())
        set.addAll(doc.getFieldNames());
    for (String s : expected) {
        assertTrue(s + " not created " + rsp, set.contains(s));
    }

}

From source file:org.apache.tika.parser.ner.NLTKNERecogniserTest.java

@Test
public void testGetEntityTypes() throws Exception {
    System.setProperty(NamedEntityParser.SYS_PROP_NER_IMPL, NLTKNERecogniser.class.getName());
    Tika tika = new Tika(new TikaConfig(NamedEntityParser.class.getResourceAsStream("tika-config.xml")));

    JSONParser parser = new JSONParser();
    String text = "";

    HashMap<Integer, String> hmap = new HashMap<Integer, String>();
    HashMap<String, HashMap<Integer, String>> outerhmap = new HashMap<String, HashMap<Integer, String>>();

    int index = 0;
    //Input Directory Path
    String inputDirPath = "/Users/AravindMac/Desktop/polardata_json_grobid/application_pdf";
    int count = 0;

    try {/* www  . j  ava2s.c  om*/

        File root = new File(inputDirPath);
        File[] listDir = root.listFiles();
        for (File filename : listDir) {

            if (!filename.getName().equals(".DS_Store") && count < 3239) {
                count += 1;
                System.out.println(count);

                String absoluteFilename = filename.getAbsolutePath().toString();

                //   System.out.println(absoluteFilename);
                //Read the json file, parse and retrieve the text present in the content field.

                Object obj = parser.parse(new FileReader(absoluteFilename));

                BufferedWriter bw = new BufferedWriter(new FileWriter(new File(absoluteFilename)));

                JSONObject jsonObject = (JSONObject) obj;
                text = (String) jsonObject.get("content");

                Metadata md = new Metadata();
                tika.parse(new ByteArrayInputStream(text.getBytes()), md);

                //Parse the content and retrieve the values tagged as the NER entities
                HashSet<String> set = new HashSet<String>();

                // Store values tagged as NER_NAMES
                set.addAll(Arrays.asList(md.getValues("NER_NAMES")));

                hmap = new HashMap<Integer, String>();
                index = 0;

                for (Iterator<String> i = set.iterator(); i.hasNext();) {
                    String f = i.next();
                    hmap.put(index, f);
                    index++;
                }

                if (!hmap.isEmpty()) {
                    outerhmap.put("NAMES", hmap);
                }

                JSONArray array = new JSONArray();
                array.put(outerhmap);

                if (!outerhmap.isEmpty()) {
                    jsonObject.put("NLTK", array); //Add the NER entities to the json under NER key as a JSON array.
                }

                System.out.println(jsonObject);

                bw.write(jsonObject.toJSONString()); //Stringify thr JSON and write it back to the file 
                bw.close();

            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:de.vanita5.twittnuker.fragment.support.AddStatusFilterDialogFragment.java

private FilterItemInfo[] getFilterItemsInfo() {
    final Bundle args = getArguments();
    if (args == null || !args.containsKey(EXTRA_STATUS))
        return new FilterItemInfo[0];
    final ParcelableStatus status = args.getParcelable(EXTRA_STATUS);
    final ArrayList<FilterItemInfo> list = new ArrayList<FilterItemInfo>();
    list.add(new FilterItemInfo(FilterItemInfo.FILTER_TYPE_USER, status));
    final ParcelableUserMention[] mentions = status.mentions;
    if (mentions != null) {
        for (final ParcelableUserMention mention : mentions) {
            if (mention.id != status.user_id) {
                list.add(new FilterItemInfo(FilterItemInfo.FILTER_TYPE_USER, mention));
            }/* www.  jav a2s. c  o  m*/
        }
    }
    final HashSet<String> hashtags = new HashSet<String>();
    hashtags.addAll(mExtractor.extractHashtags(status.text_plain));
    for (final String hashtag : hashtags) {
        list.add(new FilterItemInfo(FilterItemInfo.FILTER_TYPE_KEYWORD, hashtag));
    }
    final String source = HtmlEscapeHelper.toPlainText(status.source);
    list.add(new FilterItemInfo(FilterItemInfo.FILTER_TYPE_SOURCE, source));
    return list.toArray(new FilterItemInfo[list.size()]);
}

From source file:gov.nih.nci.caarray.application.translation.magetab.SdrfTranslator.java

private static Set<gov.nih.nci.caarray.magetab.ProtocolApplication> getAllProtocols(
        Set<? extends AbstractSampleDataRelationshipNode> nodes) {
    final HashSet<gov.nih.nci.caarray.magetab.ProtocolApplication> all = new HashSet<gov.nih.nci.caarray.magetab.ProtocolApplication>();
    for (final AbstractSampleDataRelationshipNode n : nodes) {
        all.addAll(n.getProtocolApplications());
    }/*from www .  ja  v a2 s. c  o m*/
    return all;
}

From source file:net.digitalfeed.pdroidalternative.intenthandler.PackageChangeHandler.java

private boolean havePermissionsChanged(Context context, Application oldApp, Application newApp) {
    //TODO: Add detection of permissions change
    //Maybe add a table which stores 'changed since last' info, so new permissions can be highlighted?
    if (oldApp == null) {
        //this is an error situtation
        Log.d("PDroidAlternative", "oldApp == null; thus permissions have changed");
        return true;
    } else {/*from ww w  . jav  a2 s .  com*/
        /*
         * Now to find if there are any non-matches between the two lists: have the permissions
         * changed?
         */
        //If only one array is null, then permissions have changed. If both are, then they haven't.
        if (oldApp.getPermissions() == null) {
            if (newApp.getPermissions() == null) {
                Log.d("PDroidAlternative",
                        "oldApp and newApp permissions are both null; permissions have not changed");
                return false;
            } else {
                Log.d("PDroidAlternative",
                        "oldApp permissions == null; newApp not; thus permissions have changed");
                return true;
            }
        } else if (newApp.getPermissions() == null) {
            Log.d("PDroidAlternative", "oldApp permissions != null; newApp are; thus permissions have changed");
            return true;
        }

        //if the number of permissions is different, then permissions have changed
        if (oldApp.getPermissions().length != newApp.getPermissions().length) {
            Log.d("PDroidAlternative",
                    "permissions lengths differ: oldapp: " + Integer.toString(oldApp.getPermissions().length)
                            + " newapp: " + Integer.toString(newApp.getPermissions().length));
            return true;
        }

        HashSet<String> currPermissions = new HashSet<String>();
        currPermissions.addAll(Arrays.asList(oldApp.getPermissions()));
        if (!currPermissions.containsAll(Arrays.asList(newApp.getPermissions()))) {
            Log.d("PDroidAlternative", "containsAll returned false: thus permissions have changed");
            return true;
        }
    }
    Log.d("PDroidAlternative", "Got to the end; permissions have stayed the same, it seems");
    return false;
}

From source file:net.yacy.cora.language.synonyms.AutotaggingLibrary.java

public Set<String> getVocabularyNames() {
    // this must return a clone of the set to prevent that the vocabularies are destroyed in a side effect
    HashSet<String> names = new HashSet<>();
    names.addAll(this.vocabularies.keySet());
    return names;
}

From source file:org.cgiar.ccafs.marlo.action.center.json.monitoring.project.SuggestedProjectsAction.java

/**
 * Check the OSC codes suggestions according MARLO CRP Projects.
 *///from   w  w w  .  j  av  a2s  .c  o  m
public void ocsSuggestions() {

    long projectID = Long.parseLong(syncCode);
    Project project = projectManager.getProjectById(projectID);

    Map<String, Object> dataProject = new HashMap<>();
    dataProject.put("id", project.getId());
    // dataProject.put("name", project.getTitle());

    List<ProjectBudget> projectBudgets = new ArrayList<>(project.getProjectBudgets().stream()
            .filter(pb -> pb.isActive() && pb.getYear() == this.getActualPhase().getYear())
            .collect(Collectors.toList()));

    List<FundingSource> fundingSources = new ArrayList<>();

    for (ProjectBudget projectBudget : projectBudgets) {
        FundingSource fundingSource = projectBudget.getFundingSource();
        fundingSources.add(fundingSource);
    }

    if (!fundingSources.isEmpty()) {

        HashSet<FundingSource> hashFundignSources = new HashSet<>();
        hashFundignSources.addAll(fundingSources);
        fundingSources = new ArrayList<>(hashFundignSources);

        List<Map<String, Object>> dataSuggestions = new ArrayList<>();
        /*
         * for (FundingSource fundingSource : fundingSources) {
         * if (fundingSource.getFinanceCode() != null) {
         * agreement = ocsClient.getagreement(fundingSource.getFinanceCode());
         * Map<String, Object> dataSuggestion = new HashMap<>();
         * if (agreement != null) {
         * dataSuggestion.put("code", fundingSource.getFinanceCode());
         * dataSuggestion.put("title", agreement.getShortTitle());
         * dataSuggestions.add(dataSuggestion);
         * }
         * }
         * }
         */
        dataProject.put("suggestions", dataSuggestions);

    }

    suggestedProjects.add(dataProject);
}

From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.IntroduceProjectsRule.java

protected boolean introduceProjects(AbstractLogicalOperator parentOp, int parentInputIndex,
        Mutable<ILogicalOperator> opRef, Set<LogicalVariable> parentUsedVars, IOptimizationContext context)
        throws AlgebricksException {
    AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
    boolean modified = false;

    usedVars.clear();//from  w ww . jav  a  2s  .  c o  m
    VariableUtilities.getUsedVariables(op, usedVars);

    // In the top-down pass, maintain a set of variables that are used in op and all its parents.
    HashSet<LogicalVariable> parentsUsedVars = new HashSet<LogicalVariable>();
    parentsUsedVars.addAll(parentUsedVars);
    parentsUsedVars.addAll(usedVars);

    // Descend into children.        
    for (int i = 0; i < op.getInputs().size(); i++) {
        Mutable<ILogicalOperator> inputOpRef = op.getInputs().get(i);
        if (introduceProjects(op, i, inputOpRef, parentsUsedVars, context)) {
            modified = true;
        }
    }

    if (modified) {
        context.computeAndSetTypeEnvironmentForOperator(op);
    }
    // In the bottom-up pass, determine which live variables are not used by op's parents.
    // Such variables are be projected away.
    liveVars.clear();
    VariableUtilities.getLiveVariables(op, liveVars);
    producedVars.clear();
    VariableUtilities.getProducedVariables(op, producedVars);
    liveVars.removeAll(producedVars);

    projectVars.clear();
    for (LogicalVariable liveVar : liveVars) {
        if (parentsUsedVars.contains(liveVar)) {
            projectVars.add(liveVar);
        }
    }

    // Some of the variables that are live at this op are not used above.
    if (projectVars.size() != liveVars.size()) {
        // Add a project operator under each of op's qualifying input branches.
        for (int i = 0; i < op.getInputs().size(); i++) {
            ILogicalOperator childOp = op.getInputs().get(i).getValue();
            liveVars.clear();
            VariableUtilities.getLiveVariables(childOp, liveVars);
            List<LogicalVariable> vars = new ArrayList<LogicalVariable>();
            vars.addAll(projectVars);
            // Only retain those variables that are live in the i-th input branch.
            vars.retainAll(liveVars);
            if (vars.size() != liveVars.size()) {
                ProjectOperator projectOp = new ProjectOperator(vars);
                projectOp.getInputs().add(new MutableObject<ILogicalOperator>(childOp));
                op.getInputs().get(i).setValue(projectOp);
                context.computeAndSetTypeEnvironmentForOperator(projectOp);
                modified = true;
            }
        }
    } else if (op.getOperatorTag() == LogicalOperatorTag.PROJECT) {
        // Check if the existing project has become useless.
        liveVars.clear();
        VariableUtilities.getLiveVariables(op.getInputs().get(0).getValue(), liveVars);
        ProjectOperator projectOp = (ProjectOperator) op;
        List<LogicalVariable> projectVars = projectOp.getVariables();
        if (liveVars.size() == projectVars.size() && liveVars.containsAll(projectVars)) {
            boolean eliminateProject = true;
            // For UnionAll the variables must also be in exactly the correct order.
            if (parentOp.getOperatorTag() == LogicalOperatorTag.UNIONALL) {
                eliminateProject = canEliminateProjectBelowUnion((UnionAllOperator) parentOp, projectOp,
                        parentInputIndex);
            }
            if (eliminateProject) {
                // The existing project has become useless. Remove it.
                parentOp.getInputs().get(parentInputIndex).setValue(op.getInputs().get(0).getValue());
            }
        }
    }

    if (modified) {
        context.computeAndSetTypeEnvironmentForOperator(op);
    }
    return modified;
}

From source file:com.github.frapontillo.pulse.crowd.remstopword.simple.SimpleStopWordRemover.java

/**
 * Return a dictionary containing all of the term included in the files whose names are
 * included in the input list.//w w w  .  j  av  a2  s  . c  om
 *
 * @param fileNames A {@link List} of {@link String} representing the files to read.
 *
 * @return A {@link HashSet<String>} containing all of the dictionary terms.
 */
private HashSet<String> getDictionariesByFileNames(List<String> fileNames) {
    HashSet<String> set = new HashSet<>();
    for (String fileName : fileNames) {
        set.addAll(getDictionaryByFileName(fileName));
    }
    set.addAll(punctuation);
    return set;
}