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:org.jdbcluster.privilege.PrivilegeCheckerImpl.java

/**
 * intersects required privileges against given privileges
 * /*from  w  w w  . j a va  2s . c om*/
 * @param calledMethod the method called
 * @param clusterObject cluster object instance
 * @return true if the privileges are sufficient
 */
public boolean userPrivilegeIntersect(IUser user, PrivilegedCluster clusterObject, Method calledMethod,
        Object... args) {

    Assert.notNull(clusterObject, "clusterObject may not be null");
    Assert.notNull(calledMethod, "calledMethod may not be null");

    HashSet<String> privileges = getStaticPrivilegesCluster(calledMethod, clusterObject);
    privileges.addAll(getDynamicPrivilegesCluster(clusterObject, calledMethod, args));
    return userPrivilegeIntersect(user, privileges);
}

From source file:org.jdbcluster.privilege.PrivilegeCheckerImpl.java

/**
 * intersects required privileges against given privileges
 * /*from  w  ww .ja  v a 2 s.  co m*/
 * @param calledMethod the method called
 * @param serviceObject service object instance
 * @return true if the privileges are sufficient
 */
public boolean userPrivilegeIntersect(IUser user, PrivilegedService serviceObject, Method calledMethod,
        Object... args) {

    Assert.notNull(serviceObject, "serviceObject may not be null");
    Assert.notNull(calledMethod, "calledMethod may not be null");

    HashSet<String> privileges = getStaticPrivilegesService(calledMethod, serviceObject);
    privileges.addAll(getServiceMethodParameterPrivileges(calledMethod, args));
    return userPrivilegeIntersect(user, privileges);
}

From source file:org.eurekastreams.server.action.execution.settings.PersonSourceLDAP.java

/**
 * {@inheritDoc}/*ww w.  ja v a  2s.  co  m*/
 */
@Override
public Set<Person> getPeople() {
    List<MembershipCriteriaDTO> membershipCriteria = membershipCriteriaDAO.execute(null);

    HashSet<Person> results = new HashSet<Person>();

    PersonLookupStrategy lookupStrategy = null;
    for (MembershipCriteriaDTO criterion : membershipCriteria) {
        String ldapQuery = criterion.getCriteria();
        log.info("Processing criteria: " + ldapQuery);

        if (ldapQuery.contains("=")) {
            lookupStrategy = attributeLookupStrategy;
        } else {
            lookupStrategy = groupLookupStrategy;
        }

        List<Person> people = lookupStrategy.findPeople(ldapQuery, new Integer(Integer.MAX_VALUE));
        log.info(people.size() + " people found for criteria.");
        results.addAll(people);
    }
    return results;
}

From source file:org.motechproject.mobile.omi.service.OMIServiceImpl.java

public MessageStatus savePatientMessageRequest(String messageId, NameValuePair[] personalInfo,
        String patientNumber, ContactNumberType patientNumberType, String langCode, MediaType mediaType,
        Long notificationType, Date startDate, Date endDate, String recipientId) {
    logger.debug("Constructing MessageRequest object...");

    boolean textMessageToAPublicNumber = (patientNumberType == ContactNumberType.PUBLIC
            && mediaType == MediaType.TEXT);
    if (textMessageToAPublicNumber) {
        return MessageStatus.REJECTED;
    }//from w w w .j a  v  a  2s  . com

    boolean patientPhoneNumberAndPublicPhoneNumberNotAvailable = ((patientNumber == null
            || patientNumber.isEmpty()) && patientNumberType != ContactNumberType.PUBLIC);
    if (patientPhoneNumberAndPublicPhoneNumberNotAvailable) {
        return MessageStatus.REJECTED;
    }

    NotificationType noteType = getNotificationType(notificationType);
    Language langObject = coreManager.createLanguageDAO().getByCode(langCode);

    MessageRequest messageRequest = coreManager.createMessageRequest();
    if (personalInfo != null) {
        HashSet<NameValuePair> details = new HashSet<NameValuePair>();
        details.addAll(Arrays.asList(personalInfo));
        messageRequest.setPersInfos(details);
    }

    messageRequest.setTryNumber(1);
    messageRequest.setRequestId(messageId);
    //VOICE messages need to have a start date to accommodate replaying DELIVERED messages
    messageRequest.setDateFrom(startDate == null && mediaType == MediaType.VOICE ? new Date() : startDate);
    messageRequest.setDateTo(endDate);
    messageRequest.setRecipientNumber(patientNumber);
    messageRequest.setPhoneNumberType(patientNumberType.toString());
    messageRequest.setRecipientId(recipientId);
    messageRequest.setNotificationType(noteType);
    messageRequest.setMessageType(MessageType.valueOf(mediaType.toString()));
    messageRequest.setLanguage(langObject);
    messageRequest.setStatus(MStatus.QUEUED);
    messageRequest.setDateCreated(new Date());

    logger.debug("MessageRequest object successfully constructed");
    logger.debug(messageRequest);

    if (messageRequest.getDateFrom() == null && messageRequest.getDateTo() == null) {
        return sendMessage(messageRequest);
    }

    logger.info("Saving MessageRequest...");
    MessageRequestDAO messageRequestDAO = coreManager.createMessageRequestDAO();

    messageRequestDAO.save(messageRequest);
    return MessageStatus.valueOf(messageRequest.getStatus().toString());
}

From source file:afest.datastructures.tree.decision.erts.grower.AERTGrower.java

/**
 * Return k random attributes (non-constant) picked without replacement unless less then k attributes are non-constant.
 * @param constantAttributes attributes that are constant.
 * @param attributeList list of all attributes present in each point in the set.
 * @return k random attributes (non-constant) picked without replacement unless less then k attributes are non-constant.
 *///from   www. j a  v  a 2s  .com
private ArrayList<R> getKRandomAttributes(ArrayList<R> constantAttributes, ArrayList<R> attributeList) {
    ArrayList<R> kRandomAttributes = new ArrayList<R>();

    HashSet<R> pickedAttributes = new HashSet<R>(constantAttributes);
    for (int k = 0; k < fK; k++) {
        // If all non-constant attributes have been picked and k is not reached yet, start resampling the non-constant attributes.
        if (pickedAttributes.size() == attributeList.size()) {
            pickedAttributes.clear();
            pickedAttributes.addAll(constantAttributes);
        }

        // Count the number of attributes that are available for a pick
        int numNotPicked = attributeList.size() - pickedAttributes.size();
        // get a random attribute
        int randomAttribute = fRandom.nextInt(numNotPicked);
        int count = 0;
        for (R aR : attributeList) {
            // If the attribute is not picked
            if (!pickedAttributes.contains(aR)) {
                // verify if it is the one corresponding to the random pick
                if (count == randomAttribute) {
                    kRandomAttributes.add(aR);
                    pickedAttributes.add(aR);
                    break;
                } else
                // increase the count
                {
                    count++;
                }
            }
        }
    }
    return kRandomAttributes;
}

From source file:au.org.ala.delta.intkey.ui.TaxonKeywordSelectionDialog.java

@Override
protected void okBtnPressed() {
    _selectedTaxa = new ArrayList<Item>();
    HashSet<Item> selectedTaxaSet = new HashSet<Item>();
    for (Object o : _list.getSelectedValues()) {
        String keyword = (String) o;

        _selectedKeywords.add(keyword);/*www . j  a  va  2  s .c  o m*/

        if (keyword.equals(IntkeyContext.SPECIMEN_KEYWORD)) {
            _specimenSelectedReturnValue.setValue(true);
        } else {
            List<Item> taxa = _context.getTaxaForKeyword(keyword);

            if (_selectFromIncluded) {
                taxa.retainAll(_includedTaxa);
            }

            selectedTaxaSet.addAll(taxa);
        }
    }
    _selectedTaxa.addAll(selectedTaxaSet);
    Collections.sort(_selectedTaxa);
    this.setVisible(false);
}

From source file:org.compass.core.lucene.engine.store.DefaultLuceneSearchEngineStore.java

public String[] calcSubIndexes(String[] subIndexes, String[] aliases) {
    if (aliases == null) {
        if (subIndexes == null) {
            return getSubIndexes();
        }//w w  w. j a v a  2 s. c  o  m
        // filter out any duplicates
        HashSet<String> ret = new HashSet<String>();
        ret.addAll(Arrays.asList(subIndexes));
        return ret.toArray(new String[ret.size()]);
    }
    HashSet<String> ret = new HashSet<String>();
    for (String aliase : aliases) {
        List<String> subIndexesList = subIndexesByAlias.get(aliase);
        if (subIndexesList == null) {
            throw new IllegalArgumentException("No sub-index is mapped to alias [" + aliase + "]");
        }
        for (String subIndex : subIndexesList) {
            ret.add(subIndex);
        }
    }
    if (subIndexes != null) {
        ret.addAll(Arrays.asList(subIndexes));
    }
    return ret.toArray(new String[ret.size()]);
}

From source file:org.gcaldaemon.core.file.OnlineFileListener.java

private final long saveDir(byte[] iCalBytes, int fileIndex) throws Exception {

    // Mac OS X Leopard (one calendar = multiple iCal files)
    // Get original/old iCalendar files
    File dir = iCalFiles[fileIndex];
    HashSet oldFiles = new HashSet();
    oldFiles.addAll(Arrays.asList(dir.list()));

    // Get component array
    Calendar container = ICalUtilities.parseCalendar(iCalBytes);
    ComponentList list = container.getComponents();
    Component[] array = new Component[list.size()];
    list.toArray(array);//from  w w  w .j a v  a 2  s .  co m

    // Save component
    String fileName;
    for (int i = 0; i < array.length; i++) {
        fileName = saveComponent(dir, array[i], fileIndex);
        oldFiles.remove(fileName);
    }

    // Remove deleted events
    Iterator removedNames = oldFiles.iterator();
    File file;
    while (removedNames.hasNext()) {
        fileName = (String) removedNames.next();
        if (!fileName.endsWith(".ics")) {
            continue;
        }
        try {
            file = new File(dir, fileName);
            file.delete();
            if (log.isDebugEnabled()) {
                log.debug("File deleted (" + file.getCanonicalPath().replace('\\', '/') + ").");
            }
        } catch (Exception ignored) {
        }
    }

    // Return the last modified file's timestamp
    return lastModified(dir);
}

From source file:com.cloudant.sync.replication.PullStrategy.java

public Iterable<DocumentRevsList> createTask(List<String> ids, Map<String, Collection<String>> revisions) {

    List<BulkGetRequest> requests = new ArrayList<BulkGetRequest>();

    for (String id : ids) {
        //skip any document with an empty id
        if (id.isEmpty()) {
            logger.info("Found document with empty ID in change feed, skipping");
            continue;
        }//from   w w w  . j av  a2s .  c  om
        // get list for atts_since (these are possible ancestors we have, it's ok to be eager

        // and get all revision IDs higher up in the tree even if they're not our
        // ancestors and
        // belong to a different subtree)
        HashSet<String> possibleAncestors = new HashSet<String>();
        for (String revId : revisions.get(id)) {
            List<String> thesePossibleAncestors = targetDb.getDbCore().getPossibleAncestorRevisionIDs(id, revId,
                    50);
            if (thesePossibleAncestors != null) {
                possibleAncestors.addAll(thesePossibleAncestors);
            }
        }
        requests.add(new BulkGetRequest(id, new ArrayList<String>(revisions.get(id)),
                new ArrayList<String>(possibleAncestors)));
    }

    if (useBulkGet) {
        return new GetRevisionTaskBulk(this.sourceDb, requests, this.pullAttachmentsInline);
    } else {
        return new GetRevisionTaskThreaded(this.sourceDb, requests, this.pullAttachmentsInline);
    }
}

From source file:org.apache.accumulo.server.util.VerifyTabletAssignments.java

private static void checkTable(final String user, final String pass, String table, HashSet<KeyExtent> check,
        boolean verbose)
        throws AccumuloException, AccumuloSecurityException, TableNotFoundException, InterruptedException {

    if (check == null)
        System.out.println("Checking table " + table);
    else/*from   w  ww .j a v a 2s  .co  m*/
        System.out.println("Checking table " + table + " again, failures " + check.size());

    Map<KeyExtent, String> locations = new TreeMap<KeyExtent, String>();
    SortedSet<KeyExtent> tablets = new TreeSet<KeyExtent>();

    MetadataTable.getEntries(HdfsZooInstance.getInstance(),
            new AuthInfo(user, ByteBuffer.wrap(pass.getBytes()), HdfsZooInstance.getInstance().getInstanceID()),
            table, false, locations, tablets);

    final HashSet<KeyExtent> failures = new HashSet<KeyExtent>();

    for (KeyExtent keyExtent : tablets)
        if (!locations.containsKey(keyExtent))
            System.out.println(" Tablet " + keyExtent + " has no location");
        else if (verbose)
            System.out.println(" Tablet " + keyExtent + " is located at " + locations.get(keyExtent));

    Map<String, List<KeyExtent>> extentsPerServer = new TreeMap<String, List<KeyExtent>>();

    for (Entry<KeyExtent, String> entry : locations.entrySet()) {
        List<KeyExtent> extentList = extentsPerServer.get(entry.getValue());
        if (extentList == null) {
            extentList = new ArrayList<KeyExtent>();
            extentsPerServer.put(entry.getValue(), extentList);
        }

        if (check == null || check.contains(entry.getKey()))
            extentList.add(entry.getKey());
    }

    ExecutorService tp = Executors.newFixedThreadPool(20);

    for (final Entry<String, List<KeyExtent>> entry : extentsPerServer.entrySet()) {
        Runnable r = new Runnable() {

            @Override
            public void run() {
                try {
                    checkTabletServer(user, ByteBuffer.wrap(pass.getBytes()), entry, failures);
                } catch (Exception e) {
                    System.err.println("Failure on ts " + entry.getKey() + " " + e.getMessage());
                    e.printStackTrace();
                    failures.addAll(entry.getValue());
                }
            }

        };

        tp.execute(r);
    }

    tp.shutdown();

    while (!tp.awaitTermination(1, TimeUnit.HOURS)) {
    }

    if (failures.size() > 0)
        checkTable(user, pass, table, failures, verbose);
}