Example usage for java.util HashSet add

List of usage examples for java.util HashSet add

Introduction

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

Prototype

public boolean add(E e) 

Source Link

Document

Adds the specified element to this set if it is not already present.

Usage

From source file:org.ambraproject.admin.service.AdminRolesServiceTest.java

@DataProvider(name = "userProfileAndRoles3")
public Object[][] roleSet3() {
    UserRole ur1 = new UserRole();
    ur1.setRoleName("Role5");

    dummyDataStore.store(ur1);//  ww w. j  a v a 2 s.  co  m

    UserRole ur2 = new UserRole();
    ur2.setRoleName("Role6");

    dummyDataStore.store(ur2);

    HashSet<UserRole> roles = new HashSet<UserRole>();

    roles.add(ur1);
    roles.add(ur2);

    UserProfile up = new UserProfile();
    up.setDisplayName("roles3");
    up.setEmail("roles3@example.org");
    up.setPassword("pass");
    up.setRoles(roles);

    dummyDataStore.store(up);

    return new Object[][] { { up, roles } };
}

From source file:fi.helsinki.lib.simplerest.CommunitiesResource.java

@Put
public Representation put(Representation dummy) {
    HashSet<Method> allowed = new HashSet();
    allowed.add(Method.GET);
    allowed.add(Method.POST);/*from w  w  w  . j  av a  2  s  . co  m*/
    setAllowedMethods(allowed);
    return error(null, "Communities resource does not allow PUT method.",
            Status.CLIENT_ERROR_METHOD_NOT_ALLOWED);
}

From source file:fi.helsinki.lib.simplerest.CommunitiesResource.java

@Delete
public Representation delete(Representation dummy) {
    HashSet<Method> allowed = new HashSet();
    allowed.add(Method.GET);
    allowed.add(Method.POST);//from   w ww. j  a va  2  s  .  co m
    setAllowedMethods(allowed);
    return error(null, "Communities resource does not allow DELETE method.",
            Status.CLIENT_ERROR_METHOD_NOT_ALLOWED);
}

From source file:org.ambraproject.admin.service.AdminRolesServiceTest.java

@DataProvider(name = "userProfileAndRoles1")
public Object[][] roleSet1() {
    UserRole ur1 = new UserRole();
    ur1.setRoleName("Role1");

    dummyDataStore.store(ur1);//  www  .ja v  a  2s.  com

    UserRole ur2 = new UserRole();
    ur2.setRoleName("Role2");

    dummyDataStore.store(ur2);

    HashSet<UserRole> roles = new HashSet<UserRole>();

    roles.add(ur1);
    roles.add(ur2);

    UserProfile up = new UserProfile();
    up.setDisplayName("Test User");
    up.setDisplayName("adminRolesServiceTest");
    up.setEmail("adminRolesServiceTest@example.org");
    up.setPassword("pass");
    up.setRoles(roles);

    dummyDataStore.store(up);

    return new Object[][] { { up, roles } };
}

From source file:org.openbaton.vim_impl.vim.TestVIM.java

@Override
@Async//from  w  ww. j a v  a2s.  c o  m
public Future<VNFCInstance> allocate(VimInstance vimInstance, VirtualDeploymentUnit vdu,
        VirtualNetworkFunctionRecord virtualNetworkFunctionRecord, VNFComponent vnfComponent, String userdata,
        Map<String, String> floatingIps, Set<Key> keys) throws VimException {
    log.trace("Initializing " + vimInstance);
    try {
        HashSet<String> networks = new HashSet<>();
        networks.add("network_id");
        HashSet<String> securityGroups = new HashSet<>();
        securityGroups.add("secGroup_id");

        Server server = client.launchInstanceAndWait(vimInstance, vdu.getHostname(),
                vimInstance.getImages().iterator().next().getExtId(), "flavor", "keypair", networks,
                securityGroups, "#userdate");

        VNFCInstance vnfcInstance = new VNFCInstance();
        vnfcInstance.setVc_id(server.getExtId());
        vnfcInstance.setVim_id(vimInstance.getId());

        if (vnfcInstance.getConnection_point() == null)
            vnfcInstance.setConnection_point(new HashSet<VNFDConnectionPoint>());

        for (VNFDConnectionPoint connectionPoint : vnfComponent.getConnection_point()) {
            VNFDConnectionPoint connectionPoint_new = new VNFDConnectionPoint();
            connectionPoint_new.setVirtual_link_reference(connectionPoint.getVirtual_link_reference());
            connectionPoint_new.setType(connectionPoint.getType());
            vnfcInstance.getConnection_point().add(connectionPoint_new);
        }

        if (vdu.getVnfc_instance() == null)
            vdu.setVnfc_instance(new HashSet<VNFCInstance>());

        vnfcInstance.setVnfComponent(vnfComponent);
        vnfcInstance.setFloatingIps(new HashSet<Ip>());
        vnfcInstance.setIps(new HashSet<Ip>());
        vnfcInstance.setHostname(vdu.getHostname() + "-" + ((int) (Math.random() * 1000)));
        vdu.getVnfc_instance().add(vnfcInstance);

        for (String network : server.getIps().keySet()) {
            for (String ip : server.getIps().get(network)) {
                virtualNetworkFunctionRecord.getVnf_address().add(ip);
            }
        }
        String id = server.getId();
        log.debug("launched instance with id " + id);
        return new AsyncResult<>(vnfcInstance);
    } catch (Exception e) {
        e.printStackTrace();
        throw new VimException(e);
    }
}

From source file:com.hurence.logisland.processor.MatchIP.java

@Override
protected void updateMatchingRules(ProcessContext context) {
    // loop over dynamic properties to add rules
    for (final Map.Entry<PropertyDescriptor, String> entry : context.getProperties().entrySet()) {
        if (!entry.getKey().isDynamic()) {
            continue;
        }//from  w w w  .ja va2  s.  c  o m

        final String name = entry.getKey().getName();
        final String query = entry.getValue();
        String[] params = query.split(":", 2);
        if (params.length == 2) {
            String queryField = params[0];
            String luceneQuery;
            String luceneValue;
            String ipValue = params[1];
            Matcher ipMatcher = ipPattern.matcher(ipValue);
            Matcher cidrMatcher = cidrPattern.matcher(ipValue);
            if (ipMatcher.lookingAt()) {
                // This is a static ip address
                // convert it to a long
                long addr = ipToLong(ipValue);
                luceneValue = String.valueOf(addr);
                luceneQuery = queryField + ":" + luceneValue;
                matchingRules.put(name, new MatchingRule(name, luceneQuery, query));
                luceneAttrsToQuery.add(queryField);
            } else if (cidrMatcher.lookingAt()) {
                // This is a cidr
                // Convert it to a range
                SubnetUtils su = new SubnetUtils(ipValue);
                String lowIp = su.getInfo().getLowAddress();
                String highIp = su.getInfo().getHighAddress();
                long lowIpLong = ipToLong(lowIp);
                long highIpLong = ipToLong(highIp);
                luceneValue = "[ " + String.valueOf(lowIpLong) + " TO " + String.valueOf(highIpLong) + " ]";
                luceneQuery = queryField + ":" + luceneValue;
                matchingRules.put(name, new MatchingRule(name, luceneQuery, query));
                luceneAttrsToQuery.add(queryField);
            } else {
                regexpMatchingRules.put(name, new MatchingRule(name, query));
                // Consider the value to be a regexp
                // To Be Done
                Pattern ipRegexp = Pattern.compile(ipValue);
                if (ipRegexps == null) {
                    ipRegexps = new HashMap<>();
                }
                if (ipRegexps.containsKey(queryField)) {
                    HashSet<Pair<String, Pattern>> regexpVals = ipRegexps.get(queryField);
                    regexpVals.add(new ImmutablePair<>(name, ipRegexp));
                    ipRegexps.put(queryField, regexpVals);
                } else {
                    HashSet<Pair<String, Pattern>> regexpVals = new HashSet<>();
                    regexpVals.add(new org.apache.commons.lang3.tuple.ImmutablePair<>(name, ipRegexp));
                    ipRegexps.put(queryField, regexpVals);
                }
            }
        }
    }
}

From source file:fi.helsinki.lib.simplerest.ItemsResource.java

@Put
public Representation put(Representation dummy) {
    HashSet<Method> allowed = new HashSet();
    allowed.add(Method.GET);
    allowed.add(Method.POST);/*from  w  ww . j  ava  2 s .  c om*/
    setAllowedMethods(allowed);
    return error(null, "Items resource does not allow PUT method.", Status.CLIENT_ERROR_METHOD_NOT_ALLOWED);
}

From source file:fi.helsinki.lib.simplerest.ItemsResource.java

@Delete
public Representation delete(Representation dummy) {
    HashSet<Method> allowed = new HashSet();
    allowed.add(Method.GET);
    allowed.add(Method.POST);//  w w  w .  j  a v a 2  s  .  com
    setAllowedMethods(allowed);
    return error(null, "Items resource does not allow DELETE method.", Status.CLIENT_ERROR_METHOD_NOT_ALLOWED);
}

From source file:org.openmrs.module.phrjournal.web.controller.JournalController.java

/**
 * Add missing comments written by doctors or caregivers
 * //ww w  . j a va2 s . c o m
 * @param entries original entries found through search
 */
private void addMissingComments(List<JournalEntry> entries) {
    // TODO Auto-generated method stub
    HashSet<JournalEntry> parents = new HashSet<JournalEntry>();
    for (JournalEntry entry : entries) {
        Integer parentId = entry.getParentEntryId();
        if (parentId == null) {
            parents.add(entry);
        }
    }

    for (JournalEntry parent : parents) {
        List<JournalEntry> comments = Context.getService(JournalEntryService.class).findComments(parent);
        for (JournalEntry comment : comments) {
            if (!comment.getCreator().getPersonId().equals(parent.getCreator().getPersonId())) {
                entries.add(comment);
            }
        }
    }
}

From source file:org.apache.james.transport.mailets.HeadersToHTTP.java

private HashSet<NameValuePair> getNameValuePairs(MimeMessage message)
        throws UnsupportedEncodingException, MessagingException {

    // to_address
    // from//from  w w  w  .j av  a  2  s .c  o  m
    // reply to
    // subject

    HashSet<NameValuePair> pairs = new HashSet<NameValuePair>();

    if (message != null) {
        if (message.getSender() != null) {
            pairs.add(new BasicNameValuePair("from", message.getSender().toString()));
        }
        if (message.getReplyTo() != null) {
            pairs.add(new BasicNameValuePair("reply_to", Arrays.toString(message.getReplyTo())));
        }
        if (message.getMessageID() != null) {
            pairs.add(new BasicNameValuePair("message_id", message.getMessageID()));
        }
        if (message.getSubject() != null) {
            pairs.add(new BasicNameValuePair("subject", message.getSubject()));
        }
        pairs.add(new BasicNameValuePair("size", Integer.toString(message.getSize())));
    }

    pairs.add(new BasicNameValuePair(parameterKey, parameterValue));

    return pairs;
}