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.motechproject.mobile.omi.service.OMIServiceImpl.java

public MessageStatus saveCHPSMessageRequest(String messageId, NameValuePair[] personalInfo, String workerNumber,
        Patient[] patientList, String langCode, MediaType messageType, Long notificationType, Date startDate,
        Date endDate) {/*from  ww  w  .  j a  va  2 s.co  m*/
    logger.info("Constructing MessageDetails object...");

    if (workerNumber == null || workerNumber.isEmpty()) {
        return MessageStatus.REJECTED;
    }

    MessageRequest messageRequest = coreManager.createMessageRequest();

    NotificationType noteType = getNotificationType(notificationType);

    Language langObject = coreManager.createLanguageDAO().getByCode(langCode);

    HashSet<NameValuePair> details = new HashSet<NameValuePair>();
    if (personalInfo != null) {
        details.addAll(Arrays.asList(personalInfo));
    }
    if (patientList != null) {
        for (Patient p : patientList) {
            if (p.getPreferredName() != null) {
                details.add(new NameValuePair("PreferredName", p.getPreferredName()));
            }
            if (p.getLastName() != null) {
                details.add(new NameValuePair("LastName", p.getLastName()));
            }
            if (p.getCommunity() != null) {
                details.add(new NameValuePair("Community", p.getCommunity()));
            }
            if (p.getFirstName() != null) {
                details.add(new NameValuePair("FirstName", p.getFirstName()));
            }
            if (p.getMotechId() != null) {
                details.add(new NameValuePair("MotechId", p.getMotechId()));
            }
            if (p.getPhoneNumber() != null) {
                details.add(new NameValuePair("PhoneNumber", p.getPhoneNumber()));
            }
        }
    }
    messageRequest.setPersInfos(details);

    messageRequest.setTryNumber(1);
    messageRequest.setRequestId(messageId);
    messageRequest.setDateFrom(startDate);
    messageRequest.setDateTo(endDate);
    messageRequest.setRecipientNumber(workerNumber);
    messageRequest.setNotificationType(noteType);
    messageRequest.setMessageType(MessageType.valueOf(messageType.toString()));
    messageRequest.setLanguage(langObject);
    messageRequest.setStatus(MStatus.QUEUED);
    messageRequest.setDateCreated(new Date());

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

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

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

    msgReqDao.save(messageRequest);

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

From source file:com.fstx.stdlib.author.old.AuthorizationBeanBuilder.java

public AuthorizationBean buildAuthorizationBean(String user) throws DAOException {

    HashSet rightsSet = new HashSet();
    HashSet rightsStringSet = new HashSet();
    GroupRightsDAO grDAO = GroupRightsDAO.factory.build();
    //Get user groups
    UserGroupDAO dao = UserGroupDAO.factory.build();

    List l = dao.find(UserGroupDAO.SELECT_BY_USER, user);

    //for each group
    Iterator i = l.iterator();//from w ww.j  av  a 2  s. c om
    UserGroup g3 = null;
    List rightsList = null;
    while (i.hasNext()) {
        g3 = (UserGroup) i.next();
        //get list of rights for group
        rightsList = grDAO.find(GroupRightsDAO.SELECT_BY_GROUP, g3.getName());

        //         add groups rights to the users list
        rightsSet.addAll(rightsList);

        //log.info("\n\nI just queried this group for rights: "+
        // g3.getGroupname());
    }
    //We only want to deal with strings, not GroupRights objs. This makes
    // the
    // seach of the hash eazily.
    //Convert GroupRights to Strings.
    Iterator i2 = rightsSet.iterator();
    GroupRights grTemp = null;
    while (i2.hasNext()) {
        grTemp = (GroupRights) i2.next();
        //log.info("\n\nAdding the right" + grTemp.getRightCode());
        rightsStringSet.add(grTemp.getRightCode());
    }

    //      add composite to the bean.
    AuthorizationBean ab = new AuthorizationBean(rightsStringSet);

    //      Return bean.
    return ab;
}

From source file:org.apache.james.smtpserver.fastfail.URIRBLHandler.java

/**
 * Recursively scans all MimeParts of an email for domain strings. Domain
 * strings that are found are added to the supplied HashSet.
 * //from   ww  w  . j  av  a  2 s  .c  o  m
 * @param part
 *            MimePart to scan
 * @param session
 *            not null
 * @return domains The HashSet that contains the domains which were
 *         extracted
 */
private HashSet<String> scanMailForDomains(MimePart part, SMTPSession session)
        throws MessagingException, IOException {
    HashSet<String> domains = new HashSet<String>();
    session.getLogger().debug("mime type is: \"" + part.getContentType() + "\"");

    if (part.isMimeType("text/plain") || part.isMimeType("text/html")) {
        session.getLogger().debug("scanning: \"" + part.getContent().toString() + "\"");
        HashSet<String> newDom = URIScanner.scanContentForDomains(domains, part.getContent().toString());

        // Check if new domains are found and add the domains
        if (newDom != null && newDom.size() > 0) {
            domains.addAll(newDom);
        }
    } else if (part.isMimeType("multipart/*")) {
        MimeMultipart multipart = (MimeMultipart) part.getContent();
        int count = multipart.getCount();
        session.getLogger().debug("multipart count is: " + count);

        for (int index = 0; index < count; index++) {
            session.getLogger().debug("recursing index: " + index);
            MimeBodyPart mimeBodyPart = (MimeBodyPart) multipart.getBodyPart(index);
            HashSet<String> newDomains = scanMailForDomains(mimeBodyPart, session);

            // Check if new domains are found and add the domains
            if (newDomains != null && newDomains.size() > 0) {
                domains.addAll(newDomains);
            }
        }
    }
    return domains;
}

From source file:op.care.sysfiles.PnlFiles.java

void reloadTable() {
    HashSet<SYSFiles> filesSet = new HashSet<>();

    EntityManager em = OPDE.createEM();//from w  w w .j  a v  a2s. c o  m

    Query query0 = em.createQuery(
            "SELECT s FROM SYSFiles s JOIN s.residentAssignCollection res WHERE res.resident = :resident");
    query0.setParameter("resident", resident);
    filesSet.addAll(query0.getResultList());

    Query query1 = em.createQuery(
            "SELECT s FROM SYSFiles s JOIN s.nrAssignCollection nr WHERE nr.nReport.resident = :resident");
    query1.setParameter("resident", resident);
    filesSet.addAll(query1.getResultList());

    Query query2 = em.createQuery(
            "SELECT s FROM SYSFiles s JOIN s.bwiAssignCollection bwi WHERE bwi.bwinfo.resident = :resident");
    query2.setParameter("resident", resident);
    filesSet.addAll(query2.getResultList());

    Query query3 = em.createQuery(
            "SELECT s FROM SYSFiles s JOIN s.preAssignCollection pre WHERE pre.prescription.resident = :resident");
    query3.setParameter("resident", resident);
    filesSet.addAll(query3.getResultList());

    Query query4 = em.createQuery(
            "SELECT s FROM SYSFiles s JOIN s.valAssignCollection val WHERE val.value.resident = :resident");
    query4.setParameter("resident", resident);
    filesSet.addAll(query4.getResultList());

    Query query5 = em.createQuery(
            "SELECT s FROM SYSFiles s JOIN s.npAssignCollection np WHERE np.nursingProcess.resident = :resident");
    query5.setParameter("resident", resident);
    filesSet.addAll(query5.getResultList());

    em.close();

    ArrayList<SYSFiles> listFiles = new ArrayList<>(filesSet);

    Collections.sort(listFiles);

    //        createFilters();
    tmSYSFiles = new TMSYSFiles(listFiles);
    tblFiles.setModel(tmSYSFiles);

    sorter = new TableRowSorter(tmSYSFiles);
    sorter.setSortsOnUpdates(true);
    tblFiles.setRowSorter(sorter);

    //        sorter.setComparator(TMSYSFiles.COL_PIT, new Comparator<Date>() {
    //            @Override
    //            public int compare(Date o1, Date o2) {
    //                return o1.compareTo(o2);
    //            }
    //        });

    //        sorter.setRowFilter(textFilter);

    tblFiles.getColumnModel().getColumn(0).setCellRenderer(new DefaultTableCellRenderer() {
        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {
            SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd.MM.yyyy HH:mm");
            return super.getTableCellRendererComponent(table, sdf.format((Date) value), isSelected, hasFocus,
                    row, column);
        }
    });
    tblFiles.getColumnModel().getColumn(1).setCellRenderer(new RNDHTML());
    tblFiles.getColumnModel().getColumn(2).setCellRenderer(new RNDHTML());
    tblFiles.getColumnModel().getColumn(3).setCellRenderer(new RNDHTML());

    tblFiles.getColumnModel().getColumn(0).setHeaderValue(SYSTools.xx("nursingrecords.files.tabheader1"));
    tblFiles.getColumnModel().getColumn(1).setHeaderValue(SYSTools.xx("nursingrecords.files.tabheader2"));
    tblFiles.getColumnModel().getColumn(2).setHeaderValue(SYSTools.xx("nursingrecords.files.tabheader3"));
    tblFiles.getColumnModel().getColumn(3).setHeaderValue(SYSTools.xx("nursingrecords.files.tabheader4"));

    jspFiles.dispatchEvent(new ComponentEvent(jspFiles, ComponentEvent.COMPONENT_RESIZED));
}

From source file:edu.tum.cs.conqat.quamoco.qiesl.QIESLEngine.java

/** Returns the declared variables in the AST */
private HashSet<String> getDeclaredVariables(Node node) throws QIESLException {
    HashSet<String> identifiers = new HashSet<String>();
    if (node instanceof ASTIdentifier) {
        if (node.jjtGetParent() instanceof ASTMethodNode) {
            // ignore
        } else if (isLeftHandSideOfAssignment((ASTIdentifier) node)) {
            identifiers.add(((ASTIdentifier) node).image);
        }//from   w w  w  . j  a v a  2s.  c o m
    }
    for (int i = 0; i < node.jjtGetNumChildren(); i++) {
        identifiers.addAll(getDeclaredVariables(node.jjtGetChild(i)));
    }
    return identifiers;
}

From source file:de.ingrid.iplug.scheduler.FileJobStore.java

public Set getPausedTriggerGroups(SchedulingContext ctxt) throws JobPersistenceException {
    HashSet set = new HashSet();
    set.addAll(this.fPausedTriggerGroups);

    return set;//from  www .  j a  v  a 2 s.  c o m
}

From source file:com.ggvaidya.scinames.summary.NameStabilityView.java

private Set<TaxonConcept> getBinomialTaxonConceptsUnion(Project p, Dataset ds1, Dataset ds2) {
    Set<TaxonConcept> clusters1 = getTaxonConceptsForDataset(p, ds1);
    Set<TaxonConcept> clusters2 = getTaxonConceptsForDataset(p, ds2);

    HashSet<TaxonConcept> combined = new HashSet<>(clusters1);
    combined.addAll(clusters2);

    return combined;
}

From source file:org.broadleafcommerce.core.offer.service.OfferServiceImpl.java

@Override
@SuppressWarnings("unchecked")
public Set<Offer> getUniqueOffersFromOrder(Order order) {
    HashSet<Offer> result = new HashSet<Offer>();

    Transformer adjustmentToOfferTransformer = new Transformer() {

        @Override/*w ww  .  jav a2s .  c  om*/
        public Object transform(Object input) {
            return ((Adjustment) input).getOffer();
        }
    };

    result.addAll(CollectionUtils.collect(order.getOrderAdjustments(), adjustmentToOfferTransformer));

    if (order.getOrderItems() != null) {
        for (OrderItem item : order.getOrderItems()) {
            result.addAll(
                    CollectionUtils.collect(item.getOrderItemAdjustments(), adjustmentToOfferTransformer));

            //record usage for price details on the item as well
            if (item.getOrderItemPriceDetails() != null) {
                for (OrderItemPriceDetail detail : item.getOrderItemPriceDetails()) {
                    result.addAll(CollectionUtils.collect(detail.getOrderItemPriceDetailAdjustments(),
                            adjustmentToOfferTransformer));
                }
            }
        }
    }

    if (order.getFulfillmentGroups() != null) {
        for (FulfillmentGroup fg : order.getFulfillmentGroups()) {
            result.addAll(
                    CollectionUtils.collect(fg.getFulfillmentGroupAdjustments(), adjustmentToOfferTransformer));
        }
    }
    return result;
}

From source file:de.da_sense.moses.client.FormFragment.java

/**
 * Displays a multiple choice question to the user.
 * @param question the question to be displayed
 * @param linearLayoutInsideAScrollView the view to add the question to
 * @param ordinal the ordinal number of the question i.e. 1, 2, 3, 4 or 5
 *//*from   w ww  .  j a  v a  2  s.c o  m*/
private void makeMultipleChoice(final Question question, LinearLayout linearLayoutInsideAScrollView,
        int ordinal) {
    LinearLayout questionContainer = generateQuestionContainer(linearLayoutInsideAScrollView);
    String questionText = question.getTitle();
    List<PossibleAnswer> possibleAnswers = question.getPossibleAnswers();
    Collections.sort(possibleAnswers);

    TextView questionView = new TextView(getActivity());
    questionView.setText(ordinal + ". " + questionText);
    if (question.isMandatory())
        questionView.setTextAppearance(getActivity(), R.style.QuestionTextStyleMandatory);
    else
        questionView.setTextAppearance(getActivity(), R.style.QuestionTextStyle);
    questionContainer.addView(questionView);
    mQuestionTitleMappings.put(question, questionView);

    Log.i(LOG_TAG, "questionView = " + questionView.getText());

    final HashSet<String> madeAnswers = new HashSet<String>();
    madeAnswers.addAll(Arrays.asList(question.getAnswer().split(",")));
    madeAnswers.remove(""); // paranoia

    final CheckBox[] checkBoxs = new CheckBox[possibleAnswers.size()];
    for (int i = 0; i < checkBoxs.length; i++) {
        final PossibleAnswer possibleAnswer = possibleAnswers.get(i);
        final String possibleAnswerId = String.valueOf(possibleAnswer.getId());
        checkBoxs[i] = new CheckBox(getActivity());
        if (i % 2 == 0)
            checkBoxs[i].setBackgroundColor(getActivity().getResources().getColor(R.color.light_gray));
        checkBoxs[i].setText(possibleAnswer.getTitle());
        checkBoxs[i].setTextAppearance(getActivity(), R.style.PossibleAnswerTextStyle);
        if (madeAnswers.contains(possibleAnswerId))
            checkBoxs[i].setChecked(true);

        // click handling
        checkBoxs[i].setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked)
                    madeAnswers.add(possibleAnswerId);
                else
                    madeAnswers.remove(possibleAnswerId);
                String newAnswer = "";
                for (String madeAnswer1 : madeAnswers)
                    newAnswer = newAnswer + "," + madeAnswer1;
                if (!newAnswer.isEmpty())
                    newAnswer = newAnswer.substring(1); // remove the leading ","
                question.setAnswer(newAnswer);
            }
        });

        checkBoxs[i].setVisibility(View.VISIBLE);
        if (mBelongsTo == WelcomeActivityPagerAdapter.TAB_HISTORY)
            checkBoxs[i].setEnabled(false);
        questionContainer.addView(checkBoxs[i]);
    }
}

From source file:gedi.riboseq.inference.codon.ReadsXCodonMatrix.java

public void computeExpectedCodons(Codon codon) {
    HashSet<Codon> codons = new HashSet<Codon>();
    for (Read r : M.get(codon).keySet()) {
        codons.addAll(I.get(r).keySet());
    }//  ww w .  j av  a 2 s  .com
    for (Codon c : codons) {
        double prev = c.totalActivity;
        c.totalActivity = 0;
        for (double[] s : M.get(c).values())
            c.totalActivity += s[1];
    }
}