Example usage for java.util TreeSet addAll

List of usage examples for java.util TreeSet addAll

Introduction

In this page you can find the example usage for java.util TreeSet addAll.

Prototype

public boolean addAll(Collection<? extends E> c) 

Source Link

Document

Adds all of the elements in the specified collection to this set.

Usage

From source file:pt.ist.expenditureTrackingSystem.presentationTier.actions.acquisitions.SearchPaymentProcessesAction.java

private void fillXlsInfo(Set<PaymentProcess> processes, StyledExcelSpreadsheet spreadsheet,
        OutputStream outputStream) throws IOException {
    spreadsheet.newRow();/*from www  .  j  a v a  2s. c  o  m*/
    spreadsheet.addCell(processes.size() + " " + getAcquisitionResourceMessage("label.processes"));
    spreadsheet.newRow();

    setHeaders(spreadsheet);
    TreeSet<PaymentProcess> sortedProcesses = new TreeSet<PaymentProcess>(
            PaymentProcess.COMPARATOR_BY_YEAR_AND_ACQUISITION_PROCESS_NUMBER);
    sortedProcesses.addAll(processes);

    for (PaymentProcess process : sortedProcesses) {
        spreadsheet.newRow();

        spreadsheet.addCell(process.getAcquisitionProcessId());
        spreadsheet.addCell(process.getTypeShortDescription());
        AcquisitionItemClassification classification = process.getGoodsOrServiceClassification();
        spreadsheet.addCell(classification == null ? " " : classification.getLocalizedName());
        spreadsheet.addCell(process.getSuppliersDescription());
        spreadsheet.addCell(process.getRequest().getRequestItemsSet().size());
        spreadsheet.addCell(process.getProcessStateDescription());
        DateTime time = new DateTime();
        if (process.getPaymentProcessYear().getYear() != time.getYear()) {
            time = new DateTime(process.getPaymentProcessYear().getYear().intValue(), 12, 31, 23, 59, 59, 0);
        }
        spreadsheet.addCell(describeState(process, time));
        DateTime date = process.getDateFromLastActivity();
        spreadsheet.addCell((date == null) ? ""
                : date.getDayOfMonth() + "-" + date.getMonthOfYear() + "-" + date.getYear() + " "
                        + date.getHourOfDay() + ":" + date.getMinuteOfHour());
        spreadsheet.addCell(process.getRequest().getRequester().getFirstAndLastName());
        spreadsheet.addCell(process.getRequest().getRequestingUnit().getName());

        final StringBuilder builderAccountingUnit = new StringBuilder();
        final StringBuilder builderUnits = new StringBuilder();
        for (final Financer financer : process.getFinancersWithFundsAllocated()) {
            final AccountingUnit accountingUnit = financer.getAccountingUnit();
            if (accountingUnit != null) {
                if (builderAccountingUnit.length() > 0) {
                    builderAccountingUnit.append(", ");
                }
                builderAccountingUnit.append(accountingUnit.getName());
            }
            final Unit unit = financer.getUnit();
            if (unit != null) {
                if (builderUnits.length() > 0) {
                    builderUnits.append(", ");
                }
                builderUnits.append(unit.getUnit().getAcronym());
            }
        }
        spreadsheet.addCell(builderAccountingUnit.length() == 0 ? " " : builderAccountingUnit.toString());
        spreadsheet.addCell(builderUnits.length() == 0 ? " " : builderUnits.toString());

        final Money totalValue = process.getTotalValue();
        spreadsheet.addCell((totalValue == null ? Money.ZERO : totalValue).toFormatString());

        final StringBuilder fundAllocationNumbers = new StringBuilder();
        final StringBuilder commitmentNumbers = new StringBuilder();
        final StringBuilder efectiveFundAllocationNumbers = new StringBuilder();
        final StringBuilder requestOrderNumber = new StringBuilder();
        LocalDate invoiceDate = null;
        Money invoiceValue = Money.ZERO;

        if (process instanceof SimplifiedProcedureProcess) {
            SimplifiedProcedureProcess simplifiedProcedureProcess = (SimplifiedProcedureProcess) process;
            final AcquisitionRequest acquisitionRequest = simplifiedProcedureProcess.getAcquisitionRequest();
            for (PayingUnitTotalBean payingUnitTotal : acquisitionRequest.getTotalAmountsForEachPayingUnit()) {
                if ((simplifiedProcedureProcess.getFundAllocationPresent())
                        && (payingUnitTotal.getFinancer().isFundAllocationPresent())) {
                    if (fundAllocationNumbers.length() > 0) {
                        fundAllocationNumbers.append(", ");
                    }
                    fundAllocationNumbers.append(payingUnitTotal.getFinancer().getFundAllocationIds().trim());
                }

                if (commitmentNumbers.length() > 0) {
                    fundAllocationNumbers.append(", ");
                }
                String commitmentNumber = payingUnitTotal.getFinancer().getCommitmentNumber();
                if (commitmentNumber != null) {
                    commitmentNumber = commitmentNumber.trim();
                    if (commitmentNumber.length() > 0) {
                        commitmentNumbers.append(commitmentNumber);
                    }
                }

                if ((simplifiedProcedureProcess.getEffectiveFundAllocationPresent())
                        && (payingUnitTotal.getFinancer().isEffectiveFundAllocationPresent())) {
                    if (efectiveFundAllocationNumbers.length() > 0) {
                        efectiveFundAllocationNumbers.append(", ");
                    }
                    efectiveFundAllocationNumbers
                            .append(payingUnitTotal.getFinancer().getEffectiveFundAllocationIds().trim());
                }
            }

            boolean hasFullInvoice = false;
            for (final Invoice invoice : acquisitionRequest.getInvoices()) {
                //          final AcquisitionInvoice acquisitionInvoice = (AcquisitionInvoice) invoice;
                final LocalDate localDate = invoice.getInvoiceDate();
                if (invoiceDate == null || invoiceDate.isBefore(localDate)) {
                    invoiceDate = localDate;
                }

                hasFullInvoice = true;
                //          if (!hasFullInvoice) {
                //         final String confirmationReport = acquisitionInvoice.getConfirmationReport();
                //         if (confirmationReport == null) {
                //             hasFullInvoice = true;
                //         } else {
                //             for (int i = 0; i < confirmationReport.length(); ) {
                //            final int ulli = confirmationReport.indexOf("<ul><li>", i);
                //            final int q = confirmationReport.indexOf(" - Quantidade:", ulli);
                //            final int ulliClose = confirmationReport.indexOf("</li></ul>", q);
                //            final String itemDescription = confirmationReport.substring(i + "<ul><li>".length(), q);
                //            final int quantity = Integer.parseInt(confirmationReport.substring(q + " - Quantidade:".length(), ulliClose));
                //
                //            invoiceValue = invoiceValue.add(calculate(acquisitionRequest, itemDescription, quantity));
                //             }
                //         }
                //          }
            }

            if (hasFullInvoice) {
                invoiceValue = totalValue;
            }

            final PurchaseOrderDocument purchaseOrderDocument = simplifiedProcedureProcess
                    .getPurchaseOrderDocument();
            if (purchaseOrderDocument != null) {
                requestOrderNumber.append(purchaseOrderDocument.getRequestId());
            }
        }

        spreadsheet.addCell(fundAllocationNumbers.length() == 0 ? " " : fundAllocationNumbers.toString());
        spreadsheet.addCell(commitmentNumbers.length() == 0 ? " " : commitmentNumbers.toString());
        spreadsheet.addCell(requestOrderNumber.length() == 0 ? " " : requestOrderNumber.toString());
        spreadsheet.addCell(
                efectiveFundAllocationNumbers.length() == 0 ? " " : efectiveFundAllocationNumbers.toString());

        spreadsheet.addCell(invoiceDate == null ? " " : invoiceDate.toString("yyyy-MM-dd"));
        spreadsheet.addCell(invoiceValue.toFormatString());

        DateTime creationDate = process.getCreationDate();
        spreadsheet.addCell(creationDate == null ? " " : creationDate.toString("yyyy-MM-dd"));
        SortedSet<WorkflowLog> executionLogsSet = new TreeSet<WorkflowLog>(
                WorkflowLog.COMPARATOR_BY_WHEN_REVERSED);
        executionLogsSet.addAll(process.getExecutionLogsSet());
        DateTime approvalDate = getApprovalDate(process, executionLogsSet);
        spreadsheet.addCell(approvalDate == null ? " " : approvalDate.toString("yyyy-MM-dd"));
        DateTime authorizationDate = getAuthorizationDate(process, executionLogsSet);
        spreadsheet.addCell(authorizationDate == null ? " " : authorizationDate.toString("yyyy-MM-dd"));
    }
}

From source file:com.atlassian.jira.user.util.UserUtilImpl.java

public SortedSet<User> getAllUsersInGroupNames(final Collection<String> groupNames) {
    Set<User> allUsersUnsorted = getAllUsersInGroupNamesUnsorted(groupNames);
    TreeSet<User> allUsersSorted = Sets.newTreeSet(new UserCachingComparator());
    allUsersSorted.addAll(allUsersUnsorted);
    return allUsersSorted;
}

From source file:net.sourceforge.fenixedu.domain.degree.DegreeType.java

public TreeSet<CycleType> getOrderedCycleTypes() {
    TreeSet<CycleType> result = new TreeSet<CycleType>(CycleType.COMPARATOR_BY_LESS_WEIGHT);
    result.addAll(cycleTypes());
    return result;
}

From source file:com.turn.ttorrent.client.Client.java

/**
 * Unchoke connected peers./* w ww.ja v  a2  s .  com*/
 *
 * <p>
 * This is one of the "clever" places of the BitTorrent client. Every
 * OPTIMISTIC_UNCHOKING_FREQUENCY seconds, we decide which peers should be
 * unchocked and authorized to grab pieces from us.
 * </p>
 *
 * <p>
 * Reciprocation (tit-for-tat) and upload capping is implemented here by
 * carefully choosing which peers we unchoke, and which peers we choke.
 * </p>
 *
 * <p>
 * The four peers with the best download rate and are interested in us get
 * unchoked. This maximizes our download rate as we'll be able to get data
 * from there four "best" peers quickly, while allowing these peers to
 * download from us and thus reciprocate their generosity.
 * </p>
 *
 * <p>
 * Peers that have a better download rate than these four downloaders but
 * are not interested get unchoked too, we want to be able to download from
 * them to get more data more quickly. If one becomes interested, it takes
 * a downloader's place as one of the four top downloaders (i.e. we choke
 * the downloader with the worst upload rate).
 * </p>
 *
 * @param optimistic Whether to perform an optimistic unchoke as well.
 */
private synchronized void unchokePeers(boolean optimistic) {
    // Build a set of all connected peers, we don't care about peers we're
    // not connected to.
    TreeSet<SharingPeer> bound = new TreeSet<SharingPeer>(this.getPeerRateComparator());
    bound.addAll(this.connected.values());

    if (bound.size() == 0) {
        logger.trace("No connected peers, skipping unchoking.");
        return;
    } else {
        logger.trace("Running unchokePeers() on {} connected peers.", bound.size());
    }

    int downloaders = 0;
    Set<SharingPeer> choked = new HashSet<SharingPeer>();

    // We're interested in the top downloaders first, so use a descending
    // set.
    for (SharingPeer peer : bound.descendingSet()) {
        if (downloaders < Client.MAX_DOWNLOADERS_UNCHOKE) {
            // Unchoke up to MAX_DOWNLOADERS_UNCHOKE interested peers
            if (peer.isChoking()) {
                if (peer.isInterested()) {
                    downloaders++;
                }

                peer.unchoke();
            }
        } else {
            // Choke everybody else
            choked.add(peer);
        }
    }

    // Actually choke all chosen peers (if any), except the eventual
    // optimistic unchoke.
    if (choked.size() > 0) {
        SharingPeer randomPeer = choked.toArray(new SharingPeer[0])[this.random.nextInt(choked.size())];

        for (SharingPeer peer : choked) {
            if (optimistic && peer == randomPeer) {
                logger.debug("Optimistic unchoke of {}.", peer);
                continue;
            }

            peer.choke();
        }
    }
}

From source file:org.itracker.services.implementations.UserServiceImpl.java

/**
 * @param userId         - id of update-user
 * @param newPermissions - set of new permissions for this user
 *///from ww w.ja v  a 2s .  c om
@Override
public boolean setUserPermissions(final Integer userId, final List<Permission> newPermissions) {

    boolean hasChanges = false;
    // rewriting this method

    TreeSet<Permission> pSet = new TreeSet<Permission>(Permission.PERMISSION_PROPERTIES_COMPARATOR);
    pSet.addAll(newPermissions);

    User usermodel = this.getUser(userId);

    Set<Permission> current = new TreeSet<Permission>(Permission.PERMISSION_PROPERTIES_COMPARATOR);

    current.addAll(usermodel.getPermissions());

    // setup permissions to be removed
    Set<Permission> remove = new TreeSet<Permission>(Permission.PERMISSION_PROPERTIES_COMPARATOR);
    remove.addAll(current);
    remove.removeAll(pSet);
    // setup permissions to be added
    Set<Permission> add = new TreeSet<Permission>(Permission.PERMISSION_PROPERTIES_COMPARATOR);
    add.addAll(pSet);
    add.removeAll(current);

    // look permission
    Permission p;
    Iterator<Permission> pIt = remove.iterator();
    while (pIt.hasNext()) {
        p = find(usermodel.getPermissions(), (Permission) pIt.next());
        if (null == p) {
            continue;
        }
        if (usermodel.getPermissions().contains(p)) {
            usermodel.getPermissions().remove(p);
            permissionDAO.delete(p);
            hasChanges = true;
        }
    }

    pIt = add.iterator();
    while (pIt.hasNext()) {
        p = pIt.next();
        if (null == find(usermodel.getPermissions(), p) && !usermodel.getPermissions().contains(p)) {
            p.setUser(usermodel);
            usermodel.getPermissions().add(p);
            permissionDAO.save(p);
            hasChanges = true;
        }
    }

    if (hasChanges) {
        userDAO.saveOrUpdate(usermodel);
    }

    return hasChanges;
}

From source file:org.apache.hadoop.hbase.crosssite.CrossSiteZNodes.java

/**
 * Gets the map of the hierarchy./* w ww.j  a va2  s .  com*/
 * 
 * @return
 * @throws KeeperException
 */
public Map<String, Set<String>> getHierarchyMap() throws KeeperException {
    Map<String, Set<String>> hierarchy = new TreeMap<String, Set<String>>();
    List<String> parents = ZKUtil.listChildrenNoWatch(this.zkw, this.hierarchyZNode);
    if (parents != null) {
        for (String parent : parents) {
            List<String> children = ZKUtil.listChildrenNoWatch(this.zkw,
                    ZKUtil.joinZNode(this.hierarchyZNode, parent));
            if (children != null) {
                TreeSet<String> childrenSet = new TreeSet<String>();
                childrenSet.addAll(children);
                hierarchy.put(parent, childrenSet);
            }
        }
    }
    return hierarchy;
}

From source file:com.joliciel.jochre.graphics.RowOfShapesImpl.java

@Override
public void reorderShapes() {
    Comparator<Shape> comparator = null;

    if (this.isLeftToRight())
        comparator = new ShapeLeftToRightComparator();
    else/*from ww w .  j  av  a 2  s. c  o m*/
        comparator = new ShapeRightToLeftComparator();

    TreeSet<Shape> shapeSet = new TreeSet<Shape>(comparator);
    shapeSet.addAll(this.getShapes());

    this.getShapes().clear();
    this.getShapes().addAll(shapeSet);
}

From source file:com.ecyrd.jspwiki.ReferenceManager.java

/**
 *  Does a full reference update.  Does not sync; assumes that you do it afterwards.
 *///from   ww w  .j  av  a 2 s . c o  m
@SuppressWarnings("unchecked")
private void updatePageReferences(WikiPage page) throws ProviderException {
    String content = m_engine.getPageManager().getPageText(page.getName(), WikiPageProvider.LATEST_VERSION);

    TreeSet<String> res = new TreeSet<String>();
    Collection<String> links = m_engine.scanWikiLinks(page, content);

    res.addAll(links);
    Collection attachments = m_engine.getAttachmentManager().listAttachments(page);

    for (Iterator atti = attachments.iterator(); atti.hasNext();) {
        res.add(((Attachment) (atti.next())).getName());
    }

    internalUpdateReferences(page.getName(), res);
}

From source file:com.houghtonassociates.bamboo.plugins.dao.GerritService.java

public GerritChangeVO getLastChange() throws RepositoryException {
    log.debug("getLastChange()...");

    Set<GerritChangeVO> changes = getGerritChangeInfo();

    TreeSet<GerritChangeVO> treeSet = new TreeSet<GerritChangeVO>(new SortByLastUpdate());
    treeSet.addAll(changes);

    if (treeSet.size() > 0)
        return treeSet.first();

    return null;/* w ww  . ja  v  a2 s.  c o  m*/
}

From source file:com.houghtonassociates.bamboo.plugins.dao.GerritService.java

public GerritChangeVO getLastChange(String project) throws RepositoryException {
    log.debug(String.format("getLastChange(project=%s)...", project));

    Set<GerritChangeVO> changes = getGerritChangeInfo(project);

    TreeSet<GerritChangeVO> treeSet = new TreeSet<GerritChangeVO>(new SortByLastUpdate());
    treeSet.addAll(changes);

    if (treeSet.size() > 0)
        return treeSet.first();

    return null;/*from w w  w  . j a v  a  2s .  c  o m*/
}