Example usage for java.util HashSet contains

List of usage examples for java.util HashSet contains

Introduction

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

Prototype

public boolean contains(Object o) 

Source Link

Document

Returns true if this set contains the specified element.

Usage

From source file:edu.ku.brc.specify.config.SpecifySchemaI18NServiceXML.java

@Override
public List<Locale> getLocalesFromData(final Byte schemaType, final int disciplineId) {
    List<Locale> locales = new ArrayList<Locale>();

    HashSet<String> hash = new HashSet<String>();
    for (DisciplineBasedContainer container : schemaIO.getSpLocaleContainers()) {
        for (SpLocaleItemStr str : container.getNames()) {
            String language = str.getLanguage();
            String country = str.getCountry();
            String variant = str.getVariant();

            String key = String.format("%s_%s_%s", language, country != null ? country : "",
                    variant != null ? variant : "");
            if (!hash.contains(key)) {
                hash.add(key);/*  w  w w .  j a  va 2 s. c  om*/
                Locale locale = null;
                if (StringUtils.isNotBlank(language) && StringUtils.isNotBlank(country)
                        && StringUtils.isNotBlank(variant)) {
                    locale = new Locale(language, country, variant);

                } else if (StringUtils.isNotBlank(language) && StringUtils.isNotBlank(country)) {
                    locale = new Locale(language, country);

                } else if (StringUtils.isNotBlank(language)) {
                    locale = new Locale(language);
                }
                if (locale != null) {
                    locales.add(locale);
                }
            }
        }
    }
    return locales;
}

From source file:edu.uci.ics.jung.algorithms.cluster.WeakComponentClusterer.java

/**
  * Extracts the weak components from a graph.
  * @param graph the graph whose weak components are to be extracted
  * @return the list of weak components//from  ww w.  j  a va2s .c  o  m
  */
public Set<Set<V>> transform(Graph<V, E> graph) {

    Set<Set<V>> clusterSet = new HashSet<Set<V>>();

    HashSet<V> unvisitedVertices = new HashSet<V>(graph.getVertices());

    while (!unvisitedVertices.isEmpty()) {
        Set<V> cluster = new HashSet<V>();
        V root = unvisitedVertices.iterator().next();
        unvisitedVertices.remove(root);
        cluster.add(root);

        Buffer<V> queue = new UnboundedFifoBuffer<V>();
        queue.add(root);

        while (!queue.isEmpty()) {
            V currentVertex = queue.remove();
            Collection<V> neighbors = graph.getNeighbors(currentVertex);

            for (V neighbor : neighbors) {
                if (unvisitedVertices.contains(neighbor)) {
                    queue.add(neighbor);
                    unvisitedVertices.remove(neighbor);
                    cluster.add(neighbor);
                }
            }
        }
        clusterSet.add(cluster);
    }
    return clusterSet;
}

From source file:com.thinkbiganalytics.ingest.TableMergeSyncSupportTest.java

private void verifyUnique(List<String> results) {
    HashSet<String> existing = new HashSet<>();
    for (String r : results) {
        assertFalse(existing.contains(r));
        existing.add(r);//from w w  w  . ja  v a  2 s .  c o  m
    }
}

From source file:de.ks.flatadocdb.session.Session.java

private Set<SessionEntry> handleRenames() {
    Set<SessionEntry> renamed = entriesById.values().stream()//
            .filter(e -> !e.isChild())//
            .filter(e -> {/*  w  ww  .  jav  a 2s .c o m*/
                EntityDescriptor entityDescriptor = e.getEntityDescriptor();
                String newFileName = entityDescriptor.getFileGenerator().getFileName(repository,
                        entityDescriptor, e.object);
                return !newFileName.equals(e.getFileName());
            }).collect(Collectors.toSet());

    HashSet<Object> processed = new HashSet<>();
    for (SessionEntry sessionEntry : renamed) {
        boolean alreadyProcessed = processed.contains(sessionEntry.getObject());
        if (!alreadyProcessed) {
            removeSessionEntry(sessionEntry, sessionEntry.getObject(), processed);
            persist(sessionEntry.getObject());

            Set<Relation> allRelations = sessionEntry.getEntityDescriptor().getChildRelations();
            for (Relation child : allRelations) {
                Collection<Object> related = child.getRelatedEntities(sessionEntry.getObject());
                processed.addAll(related);
            }
            processed.add(sessionEntry.getObject());
        }
    }
    return renamed;
}

From source file:de.tudarmstadt.ukp.dkpro.wsd.si.dictionary.util.UkbDictionary.java

public UkbDictionary(String path, String neededMentionsPath) throws FileNotFoundException, IOException {

    HashSet<String> neededMentions = new HashSet<String>(FileUtils.readLines(new File(neededMentionsPath)));

    mentionMap = new HashMap<String, List<String[]>>();
    targetMap = new HashMap<String, Integer>();

    BufferedReader reader = new BufferedReader(
            new InputStreamReader(new BZip2CompressorInputStream(new FileInputStream(path))));

    String line;//from ww  w. ja v  a  2s.  c om
    String[] lineArray;
    List<String[]> entities;
    //      Timer timer = new Timer(9615853);
    while ((line = reader.readLine()) != null) {

        lineArray = line.split(" ");

        if (neededMentions.contains(lineArray[0].toLowerCase())) {
            entities = new LinkedList<String[]>();
            for (int i = 1; i < lineArray.length; i++) {

                String target = lineArray[i].substring(0, lineArray[i].lastIndexOf(":"));
                String frequency = lineArray[i].substring(lineArray[i].lastIndexOf(":") + 1,
                        lineArray[i].length());

                //add targets to mentionMap
                entities.add(new String[] { target, frequency });

                //add target to targetMap
                if (targetMap.containsKey(target)) {
                    targetMap.put(target, targetMap.get(target) + Integer.valueOf(frequency));
                } else {
                    targetMap.put(target, Integer.valueOf(frequency));
                }
            }
            mentionMap.put(lineArray[0].toLowerCase(), entities);
        }
    }
    reader.close();
}

From source file:com.comu.android.StreamRenderer.java

/**
 * Renders the posts' action links.//  w ww  . j  av  a 2 s. co  m
 * 
 * @param post
 */
private void renderActionLinks(JSONObject post) {
    HashSet<String> actions = getActions(post);
    append("<div class=\"action_links\">");
    append("<div class=\"action_link\">");
    renderTimeStamp(post);
    append("</div>");
    String post_id = post.optString("id");
    if (actions.contains("Comment")) {
        renderActionLink(post_id, "Comment", "comment");
    }
    boolean canLike = actions.contains("Like");
    renderActionLink(post_id, "Like", "like", canLike);
    renderActionLink(post_id, "Unlike", "unlike", !canLike);

    append("<div class=\"clear\"></div></div>");
}

From source file:com.dtolabs.rundeck.core.dispatcher.DataContextUtils.java

/**
 * Generate a dataset for a INodeEntry/*w ww  .  jav a 2s  .  c  o  m*/
 * @param nodeentry node
 * @return dataset
 */
public static Map<String, String> nodeData(final INodeEntry nodeentry) {
    final HashMap<String, String> data = new HashMap<String, String>();
    if (null != nodeentry) {
        HashSet<String> skipProps = new HashSet<String>();
        skipProps.addAll(Arrays.asList("nodename", "osName", "osVersion", "osArch", "osFamily"));
        data.put("name", notNull(nodeentry.getNodename()));
        data.put("hostname", notNull(nodeentry.getHostname()));
        data.put("os-name", notNull(nodeentry.getOsName()));
        data.put("os-version", notNull(nodeentry.getOsVersion()));
        data.put("os-arch", notNull(nodeentry.getOsArch()));
        data.put("os-family", notNull(nodeentry.getOsFamily()));
        data.put("username", notNull(nodeentry.getUsername()));
        data.put("description", notNull(nodeentry.getDescription()));
        data.put("tags", null != nodeentry.getTags() ? join(nodeentry.getTags(), ",") : "");
        //include attributes data
        if (null != nodeentry.getAttributes()) {
            for (final String name : nodeentry.getAttributes().keySet()) {
                if (null != nodeentry.getAttributes().get(name) && !data.containsKey(name)
                        && !skipProps.contains(name)) {

                    data.put(name, notNull(nodeentry.getAttributes().get(name)));
                }
            }
        }
    }
    return data;
}

From source file:edu.uah.itsc.aws.S3.java

public void addWorkflowSharePolicy(String groupName, String policyName, String workflowPath) {
    // Create ami with proper credentials
    AmazonIdentityManagementClient ami = new AmazonIdentityManagementClient(
            new BasicAWSCredentials(awsAdminAccessKey, awsAdminSecretKey));
    GetGroupPolicyRequest ggpRequest = new GetGroupPolicyRequest(groupName, policyName);
    GetGroupPolicyResult ggpResult = ami.getGroupPolicy(ggpRequest);
    String policy = ggpResult.getPolicyDocument();
    try {// w  w w. j  a v a  2 s . c o m
        policy = new URI(policy).getPath().toString();
        JSONObject policyObject = new JSONObject(policy);
        JSONArray policyStatementsArray = policyObject.getJSONArray("Statement");
        // We are going to add new bucket in the Resource array list in the json format
        for (int i = 0; i < policyStatementsArray.length(); i++) {
            JSONObject statementObject = (JSONObject) policyStatementsArray.get(i);
            JSONArray actionArray = (JSONArray) statementObject.getJSONArray("Action");
            if (actionArray.length() == 3) {
                HashSet<String> set = new HashSet<String>(3);
                set.add(actionArray.getString(0));
                set.add(actionArray.getString(1));
                set.add(actionArray.getString(2));
                if (set.contains("s3:Get*") && set.contains("s3:Put*") && set.contains("s3:List*")) {
                    JSONArray resourceArray = (JSONArray) statementObject.getJSONArray("Resource");
                    resourceArray.put(resourceArray.length(), "arn:aws:s3:::" + workflowPath + "/*");
                }
            }
        }

        policyObject.put("Statement", policyStatementsArray);
        policy = policyObject.toString(4);
        // if (1 == 1 ) return;
    } catch (URISyntaxException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        e.printStackTrace();

    }
    // Add new policy as required
    PutGroupPolicyRequest pgpRequest = new PutGroupPolicyRequest(groupName, policyName, policy);
    ami.putGroupPolicy(pgpRequest);

}

From source file:com.thinkbiganalytics.ingest.TableMergeSyncSupportTest.java

private void doTestMergeNoProcessingDttm(String targetTable, PartitionSpec spec) {

    List<String> results = fetchEmployees(targetSchema, targetTable);
    assertEquals(1, results.size());//from   w ww  .  j a va  2  s  . c  om

    // Call merge
    mergeSyncSupport.doMerge(sourceSchema, sourceTable, targetSchema, targetTable, spec, processingPartition,
            false);

    // We should have 5 records 4 from the sourceTable and 1 existing
    results = fetchEmployees(targetSchema, targetTable);
    assertEquals(5, results.size());

    // Run merge with dedupe and should get the following two additional results. The result should not include any duplicates in the target table.
    hiveShell.execute(
            "insert into emp_sr.employee_valid partition(processing_dttm='20160119974340') (  `id`, `timestamp`, `name`,`company`,`zip`,`phone`,`email`,  `hired`,`country`) "
                    + "values (100, '1', 'Bruce','ABC','94550','555-1212','bruce@acme.org','2016-01-01','Canada');");
    hiveShell.execute(
            "insert into emp_sr.employee_valid partition(processing_dttm='20160119974340') (  `id`, `timestamp`, `name`,`company`,`zip`,`phone`,`email`,  `hired`,`country`) "
                    + "values (101, '1','Harry','ABC','94550','555-1212','harry@acme.org','2016-01-01','Canada');");

    hiveShell.execute(
            "insert into emp_sr.employee partition(country='Canada',year=2016) (`id`, `timestamp`, `name`,`company`,`zip`,`phone`,`email`,  `hired`,`processing_dttm`)  "
                    + "values (100, '1', 'Bruce','ABC','94550','555-1212','bruce@acme.org','2016-01-01','20150119974340');");

    mergeSyncSupport.doMerge(sourceSchema, sourceTable, targetSchema, targetTable, spec, "20160119974340",
            true);

    results = fetchEmployees(targetSchema, targetTable);
    assertEquals(7, results.size());
    // Verify no duplicates exist in the table
    HashSet<String> existing = new HashSet<>();
    for (String r : results) {
        assertFalse(existing.contains(r));
        existing.add(r);
    }

}

From source file:edu.uah.itsc.aws.S3.java

public void addBucketGroupPolicy(String groupName, String policyName, String bucketName) {
    // Create ami with proper credentials
    AmazonIdentityManagementClient ami = new AmazonIdentityManagementClient(
            new BasicAWSCredentials(awsAdminAccessKey, awsAdminSecretKey));
    GetGroupPolicyRequest ggpRequest = new GetGroupPolicyRequest(groupName, policyName);
    GetGroupPolicyResult ggpResult = ami.getGroupPolicy(ggpRequest);
    String policy = ggpResult.getPolicyDocument();
    try {//from   w ww.j  av a2s . c o  m
        policy = new URI(policy).getPath().toString();
        JSONObject policyObject = new JSONObject(policy);
        JSONArray policyStatementsArray = policyObject.getJSONArray("Statement");
        // We are going to add new bucket in the Resource array list in the json format
        for (int i = 0; i < policyStatementsArray.length(); i++) {
            JSONObject statementObject = (JSONObject) policyStatementsArray.get(i);
            JSONArray actionArray = (JSONArray) statementObject.getJSONArray("Action");
            if (actionArray.length() == 1 && actionArray.getString(0).equalsIgnoreCase("s3:List*")) {
                JSONArray resourceArray = (JSONArray) statementObject.getJSONArray("Resource");
                resourceArray.put(resourceArray.length(), "arn:aws:s3:::" + bucketName);
            } else if (actionArray.length() == 3) {
                HashSet<String> set = new HashSet<String>(3);
                set.add(actionArray.getString(0));
                set.add(actionArray.getString(1));
                set.add(actionArray.getString(2));
                if (set.contains("s3:Get*") && set.contains("s3:Put*") && set.contains("s3:List*")) {
                    JSONArray resourceArray = (JSONArray) statementObject.getJSONArray("Resource");
                    resourceArray.put(resourceArray.length(),
                            "arn:aws:s3:::" + bucketName + "/${aws:username}/*");
                }
            }
        }

        policyObject.put("Statement", policyStatementsArray);
        policy = policyObject.toString(4);
        // if (1 == 1 ) return;
    } catch (URISyntaxException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        e.printStackTrace();

    }
    // Add new policy as required
    PutGroupPolicyRequest pgpRequest = new PutGroupPolicyRequest(groupName, policyName, policy);
    ami.putGroupPolicy(pgpRequest);

}