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.italiangrid.storm.webdav.authz.vomap.DefaultVOMapDetailsService.java

@Override
public Set<String> getPrincipalVOs(X500Principal principal) {

    Assert.notNull(principal, "Principal cannot be null");

    HashSet<String> voNames = new HashSet<String>();

    for (VOMembershipProvider p : providers) {

        if (p.hasSubjectAsMember(principal.getName())) {
            voNames.add(p.getVOName());
        }/*  ww w. j  a va2 s  .c o m*/
    }

    return Collections.unmodifiableSet(voNames);
}

From source file:thingynet.hierarchy.HierarchyTest.java

@Test
public void getDescendantsWithLevelShouldReturnExpectedHierarchies() {
    Hierarchy parent = hierarchyService.createRoot(PARENT, null);
    Hierarchy child = hierarchyService.createChild(parent, CHILD, null);
    hierarchyService.createChild(parent, SIBLING, null);
    Hierarchy grandChild = hierarchyService.createChild(child, GRAND_CHILD, null);
    Hierarchy greatGrandChild = hierarchyService.createChild(grandChild, GREAT_GRAND_CHILD, null);
    hierarchyService.createChild(greatGrandChild, CHILD, null);

    HashSet<String> expectedIds = new HashSet<>();
    expectedIds.add(grandChild.getPath());
    expectedIds.add(greatGrandChild.getPath());

    Iterable<Hierarchy> actual = hierarchyService.getDescendants(child, 2);
    while (actual.iterator().hasNext()) {
        Hierarchy descendant = actual.iterator().next();
        assertThat(expectedIds.remove(descendant.getPath()), is(true));
    }/*from  w w w  .ja v a 2 s  . c o  m*/
    assertThat(expectedIds.size(), is(0));
}

From source file:com.evermal.xtractor.MaintenanceClassifierWordMatcher.java

private HashSet<String> nonFunctionalWords() {
    HashSet<String> words = new HashSet<String>();
    words.add("header");
    words.add("license");
    words.add("update");
    words.add("copyright");
    return words;
}

From source file:com.tk.httpClientErp.headmancheck.HeadmancheckListActivity.java

/**
 * json//from   w w  w .ja va 2  s.  com
 * 
 * @return
 */
private List<HashMap<String, Object>> classification(List<HashMap<String, Object>> jsontoList) {
    boolean initCompare = true; // true
    HashMap<String, Object> compareContainer = null; // 
    List<HashMap<String, Object>> fenzuList = new ArrayList<HashMap<String, Object>>();
    // 
    if (jsontoList.size() == 0)
        return fenzuList;
    // 
    HashSet<String> gd_no = new HashSet<String>();
    for (HashMap<String, Object> bean : jsontoList) {
        gd_no.add(bean.get("gd_no").toString());
    }
    //
    for (String gdstr : gd_no) {
        compareContainer = new HashMap<String, Object>();
        for (HashMap<String, Object> bean : jsontoList) {
            if (gdstr.equals(bean.get("gd_no").toString()) && initCompare) {
                compareContainer = bean;
                initCompare = false;
            } else if (gdstr.equals(bean.get("gd_no").toString())) {
                compareContainer = bean;
            }
        }
        fenzuList.add(compareContainer);
        initCompare = true;
    }
    return fenzuList;
}

From source file:info.magnolia.registry.RegistryMap.java

public synchronized Set<K> removeAndPutAll(Collection<K> toRemove, Collection<V> toPut) {
    if (!toPut.isEmpty()) {
        keyFromValue(toPut.iterator().next());
    }/*from  w w  w. j av  a2 s  . c  o m*/
    for (K key : toRemove) {
        map.remove(key);
    }
    HashSet<K> keys = new HashSet<K>();
    for (V value : toPut) {
        K key = keyFromValue(value);
        map.put(key, value);
        keys.add(key);
    }
    return keys;
}

From source file:com.evermal.xtractor.MaintenanceClassifierWordMatcher.java

private HashSet<String> adaptativeWords() {
    HashSet<String> words = new HashSet<String>();
    words.add("java-doc");
    words.add("zoneinfo");
    words.add("translation");
    words.add("build");
    words.add("docs");
    return words;
}

From source file:com.ibm.bi.dml.api.DMLScript.java

/**
 * /*w  w w . j a va2  s  .co  m*/
 * @param config 
 * @throws IOException
 * @throws DMLRuntimeException 
 */
private static void checkSecuritySetup(DMLConfig config) throws IOException, DMLRuntimeException {
    //analyze local configuration
    String userName = System.getProperty("user.name");
    HashSet<String> groupNames = new HashSet<String>();
    try {
        //check existence, for backwards compatibility to < hadoop 0.21
        if (UserGroupInformation.class.getMethod("getCurrentUser") != null) {
            String[] groups = UserGroupInformation.getCurrentUser().getGroupNames();
            for (String g : groups)
                groupNames.add(g);
        }
    } catch (Exception ex) {
    }

    //analyze hadoop configuration
    JobConf job = ConfigurationManager.getCachedJobConf();
    boolean localMode = InfrastructureAnalyzer.isLocalMode(job);
    String taskController = job.get("mapred.task.tracker.task-controller",
            "org.apache.hadoop.mapred.DefaultTaskController");
    String ttGroupName = job.get("mapreduce.tasktracker.group", "null");
    String perm = job.get(MRConfigurationNames.DFS_PERMISSIONS, "null"); //note: job.get("dfs.permissions.supergroup",null);
    URI fsURI = FileSystem.getDefaultUri(job);

    //determine security states
    boolean flagDiffUser = !(taskController.equals("org.apache.hadoop.mapred.LinuxTaskController") //runs map/reduce tasks as the current user
            || localMode // run in the same JVM anyway
            || groupNames.contains(ttGroupName)); //user in task tracker group 
    boolean flagLocalFS = fsURI == null || fsURI.getScheme().equals("file");
    boolean flagSecurity = perm.equals("yes");

    LOG.debug("SystemML security check: " + "local.user.name = " + userName + ", " + "local.user.groups = "
            + ProgramConverter.serializeStringCollection(groupNames) + ", " + "mapred.job.tracker = "
            + job.get("mapred.job.tracker") + ", " + "mapred.task.tracker.task-controller = " + taskController
            + "," + "mapreduce.tasktracker.group = " + ttGroupName + ", " + "fs.default.name = "
            + ((fsURI != null) ? fsURI.getScheme() : "null") + ", " + MRConfigurationNames.DFS_PERMISSIONS
            + " = " + perm);

    //print warning if permission issues possible
    if (flagDiffUser && (flagLocalFS || flagSecurity)) {
        LOG.warn("Cannot run map/reduce tasks as user '" + userName + "'. Using tasktracker group '"
                + ttGroupName + "'.");
    }

    //validate external filenames working directories
    String localtmpdir = config.getTextValue(DMLConfig.LOCAL_TMP_DIR);
    String hdfstmpdir = config.getTextValue(DMLConfig.SCRATCH_SPACE);
    if (!LocalFileUtils.validateExternalFilename(localtmpdir, false))
        throw new DMLRuntimeException("Invalid (non-trustworthy) local working directory.");
    if (!LocalFileUtils.validateExternalFilename(hdfstmpdir, true))
        throw new DMLRuntimeException("Invalid (non-trustworthy) hdfs working directory.");
}

From source file:de.appsolve.padelcampus.controller.pro.ProOperatorsController.java

@RequestMapping(method = POST, value = "newaccount")
public ModelAndView postNewAccount(HttpServletRequest request,
        @ModelAttribute("Model") CustomerRegistrationModel customerAccount, BindingResult bindingResult) {
    if (bindingResult.hasErrors()) {
        return new ModelAndView("pro/newaccount", "Model", customerAccount);
    }/* w w  w .ja va2s  .c  o  m*/
    try {
        if (StringUtils.isEmpty(customerAccount.getCustomer().getName())) {
            throw new Exception(msg.get("ProjectNameFormatRequirements"));
        }
        String projectName = customerAccount.getCustomer().getName().toLowerCase(Constants.DEFAULT_LOCALE)
                .replace(" ", "-");
        //verify dns name requirements
        if (!DNS_SUBDOMAIN_PATTERN.matcher(projectName).matches()) {
            throw new Exception(msg.get("ProjectNameFormatRequirements"));
        }

        //make sure customer does not exist yet
        Customer customer = customerDAO.findByName(projectName);
        if (customer != null) {
            throw new Exception(msg.get("ProjectAlreadyExists"));
        }

        String dnsHostname = environment.getProperty("DNS_HOSTNAME");
        String cloudflareUrl = environment.getProperty("CLOUDFLARE_URL");
        //create DNS subdomain in cloudflare
        String domainName = cloudFlareApiClient.addCnameRecord(projectName, cloudflareUrl, dnsHostname);

        //save customer to DB
        HashSet<String> domainNames = new HashSet<>();
        domainNames.add(domainName);
        customerAccount.getCustomer().setDomainNames(domainNames);
        customer = customerDAO.saveOrUpdate(customerAccount.getCustomer());

        //create admin account in DB
        Player adminPlayer = playerDAO.findByEmail(customerAccount.getPlayer().getEmail());
        if (adminPlayer == null) {
            customerAccount.getPlayer().setCustomer(customer);
            adminPlayer = playerDAO.saveOrUpdate(customerAccount.getPlayer());
        }

        //create admin group in DB
        AdminGroup adminGroup = adminGroupDAO.findByAttribute("customer", customer);
        if (adminGroup == null) {
            adminGroup = new AdminGroup();
            adminGroup.setName(domainName + " Admins");
            EnumSet<Privilege> privileges = EnumSet.complementOf(EnumSet.of(Privilege.ManageCustomers));
            adminGroup.setPrivileges(privileges);
            adminGroup.setPlayers(new HashSet<>(Arrays.asList(new Player[] { adminPlayer })));
            adminGroup.setCustomer(customer);
            adminGroupDAO.saveOrUpdate(adminGroup);
        }

        //create all.min.css.stylesheet for new customer
        htmlResourceUtil.updateCss(servletContext, customer);

        Mail mail = new Mail();
        mail.addRecipient(getDefaultContact());
        mail.setSubject("New Customer Registration");
        mail.setBody(customer.toString());
        mailUtils.send(mail, request);

        return new ModelAndView("redirect:/pro/operators/newaccount/" + customer.getId());
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        errorReporter.notify(e);
        bindingResult.addError(new ObjectError("id", e.getMessage()));
        return new ModelAndView("pro/newaccount", "Model", customerAccount);
    }
}

From source file:io.teak.sdk.Amazon.java

public JSONObject querySkuDetails(String sku) {
    try {//from   w  w w  .  j  a  v  a 2s .co  m
        Class<?> purchasingServiceClass = Class.forName("com.amazon.device.iap.PurchasingService");
        Method m = purchasingServiceClass.getMethod("getProductData", Set.class);
        HashSet<String> skus = new HashSet<>();
        skus.add(sku);
        Object requestId = m.invoke(null, skus);

        skuDetailsRequestMap.put(requestId.toString(), requestId);
        synchronized (requestId) {
            requestId.wait();
        }
        skuDetailsRequestMap.remove(requestId.toString());

        JSONObject ret = new JSONObject();
        ret.put("price_string", skuPriceMap.get(sku));
        return ret;
    } catch (Exception e) {
        Log.e(LOG_TAG, "Reflection error: " + Log.getStackTraceString(e));
        Teak.sdkRaven.reportException(e);
    }
    return null;
}

From source file:annis.security.ANNISRolePermissionResolver.java

@Override
public Collection<Permission> resolvePermissionsInRole(String roleString) {
    HashSet<Permission> perms = new HashSet<Permission>();

    if ("*".equals(roleString)) {
        perms.add(new WildcardPermission("query:*:*"));
    } else {//from   w  w  w.j  a va2  s  .  c o m
        if (roleString.equals(defaultUserRole)) {
            // every user can get/set its user configuration
            perms.add(new WildcardPermission("admin:*:userconfig"));
        } else if (roleString.equals(anonymousUserRole)) {
            // every anonymous user can get/set its user configuration
            perms.add(new WildcardPermission("admin:read:userconfig"));
        }
        checkConfiguration();

        lock.readLock().lock();
        try {
            String corporaRaw = groups.getProperty(roleString);
            if (corporaRaw != null) {
                String[] corpora = corporaRaw.split("\\s*,\\s*");
                for (String c : corpora) {
                    perms.add(new WildcardPermission("query:*:" + c.trim()));
                }
            }
        } finally {
            lock.readLock().unlock();
        }
    }

    return perms;
}