Example usage for java.util Collection equals

List of usage examples for java.util Collection equals

Introduction

In this page you can find the example usage for java.util Collection equals.

Prototype

boolean equals(Object o);

Source Link

Document

Compares the specified object with this collection for equality.

Usage

From source file:org.dspace.test.content.CollectionTest.java

/**
 * Test of findAll method, of class Collection.
 *//*from w  ww  .  jav  a  2 s.  c om*/
@Test
public void testFindAll() throws Exception {
    List<Collection> all = collectionService.findAll(context);
    assertThat("testFindAll 0", all, notNullValue());
    assertTrue("testFindAll 1", all.size() >= 1);

    boolean added = false;
    for (Collection cl : all) {
        if (cl.equals(collection)) {
            added = true;
        }
    }
    assertTrue("testFindAll 2", added);
}

From source file:org.fcrepo.apix.loader.impl.LoaderService.java

private URI findMatchingExtension(final Model model) {
    final Collection<URI> exposesServices = objectResourcesOf(null, PROP_EXPOSES_SERVICE, model);
    final Collection<URI> consumesServices = objectResourcesOf(null, PROP_CONSUMES_SERVICE, model);
    final Collection<String> exposesAt = objectLiteralsOf(null, PROP_EXPOSES_SERVICE_AT, model);
    final boolean isExposing = exposesServices.size() > 0;

    for (final Extension e : extensionRegistry.getExtensions()) {
        if (isExposing && e.isExposing() && exposesAt.contains(e.exposed().exposedAt().toString())) {
            return e.uri();
        } else if (!isExposing && consumesServices.equals(e.intercepted().consumed())) {
            return e.uri();
        }//from w w w.ja va2 s .  c  om
    }

    return null;
}

From source file:org.sakaiproject.assignment.tool.AssignmentAction.java

private void integrateWithAnnouncement(SessionState state, String aOldTitle, AssignmentEdit a, String title,
        Time openTime, String checkAutoAnnounce, String valueOpenDateNotification, Time oldOpenTime) {
    if (checkAutoAnnounce.equalsIgnoreCase(Boolean.TRUE.toString())) {
        AnnouncementChannel channel = (AnnouncementChannel) state.getAttribute(ANNOUNCEMENT_CHANNEL);
        if (channel != null) {
            // whether the assignment's title or open date has been updated
            boolean updatedTitle = false;
            boolean updatedOpenDate = false;
            boolean updateAccess = false;

            String openDateAnnounced = StringUtils
                    .trimToNull(a.getProperties().getProperty(NEW_ASSIGNMENT_OPEN_DATE_ANNOUNCED));
            String openDateAnnouncementId = StringUtils.trimToNull(a.getPropertiesEdit()
                    .getProperty(ResourceProperties.PROP_ASSIGNMENT_OPENDATE_ANNOUNCEMENT_MESSAGE_ID));
            if (openDateAnnounced != null && openDateAnnouncementId != null) {
                AnnouncementMessage message = null;

                try {
                    message = channel.getAnnouncementMessage(openDateAnnouncementId);
                    if (!message.getAnnouncementHeader().getSubject()
                            .contains(title))/*whether title has been changed*/
                    {//  w w  w .ja  v a 2 s .c  o m
                        updatedTitle = true;
                    }
                    if (!message.getBody()
                            .contains(openTime.toStringLocalFull())) /*whether open date has been changed*/
                    {
                        updatedOpenDate = true;
                    }
                    if ((message.getAnnouncementHeader().getAccess().equals(MessageHeader.MessageAccess.CHANNEL)
                            && !a.getAccess().equals(AssignmentAccess.SITE))
                            || (!message.getAnnouncementHeader().getAccess()
                                    .equals(MessageHeader.MessageAccess.CHANNEL)
                                    && a.getAccess().equals(AssignmentAccess.SITE))) {
                        updateAccess = true;
                    } else if (a.getAccess() == Assignment.AssignmentAccess.GROUPED) {
                        Collection<String> assnGroups = a.getGroups();
                        Collection<String> anncGroups = message.getAnnouncementHeader().getGroups();
                        if (!assnGroups.equals(anncGroups)) {
                            updateAccess = true;
                        }
                    }
                } catch (IdUnusedException e) {
                    M_log.warn(this + ":integrateWithAnnouncement " + e.getMessage());
                } catch (PermissionException e) {
                    M_log.warn(this + ":integrateWithAnnouncement " + e.getMessage());
                }

                if (updateAccess && message != null) {
                    try {
                        // if the access level has changed in assignment, remove the original announcement
                        channel.removeAnnouncementMessage(message.getId());
                    } catch (PermissionException e) {
                        M_log.warn(this
                                + ":integrateWithAnnouncement PermissionException for remove message id="
                                + message.getId() + " for assignment id=" + a.getId() + " " + e.getMessage());
                    }
                }
            }

            // need to create announcement message if assignment is added or assignment has been updated
            if (openDateAnnounced == null || updatedTitle || updatedOpenDate || updateAccess) {
                try {
                    AnnouncementMessageEdit message = channel.addAnnouncementMessage();
                    if (message != null) {
                        AnnouncementMessageHeaderEdit header = message.getAnnouncementHeaderEdit();

                        // add assignment id into property, to facilitate assignment lookup in Annoucement tool
                        message.getPropertiesEdit().addProperty("assignmentReference", a.getReference());

                        header.setDraft(/* draft */false);
                        header.replaceAttachments(/* attachment */EntityManager.newReferenceList());

                        if (openDateAnnounced == null) {
                            // making new announcement
                            header.setSubject(
                                    /* subject */rb.getFormattedMessage("assig6", new Object[] { title }));
                        } else {
                            // updated title
                            header.setSubject(
                                    /* subject */rb.getFormattedMessage("assig5", new Object[] { title }));
                        }

                        if (updatedOpenDate) {
                            // revised assignment open date
                            message.setBody(/* body */rb.getFormattedMessage("newope",
                                    new Object[] { FormattedText.convertPlaintextToFormattedText(title),
                                            openTime.toStringLocalFull() }));
                        } else {
                            // assignment open date
                            message.setBody(/* body */rb.getFormattedMessage("opedat",
                                    new Object[] { FormattedText.convertPlaintextToFormattedText(title),
                                            openTime.toStringLocalFull() }));
                        }

                        // group information
                        if (a.getAccess().equals(Assignment.AssignmentAccess.GROUPED)) {
                            try {
                                // get the group ids selected
                                Collection groupRefs = a.getGroups();

                                // make a collection of Group objects
                                Collection groups = new ArrayList();

                                //make a collection of Group objects from the collection of group ref strings
                                Site site = SiteService
                                        .getSite((String) state.getAttribute(STATE_CONTEXT_STRING));
                                for (Iterator iGroupRefs = groupRefs.iterator(); iGroupRefs.hasNext();) {
                                    String groupRef = (String) iGroupRefs.next();
                                    groups.add(site.getGroup(groupRef));
                                }

                                // set access
                                header.setGroupAccess(groups);
                            } catch (Exception exception) {
                                // log
                                M_log.warn(this + ":integrateWithAnnouncement " + exception.getMessage());
                            }
                        } else {
                            // site announcement
                            header.clearGroupAccess();
                        }

                        // save notification level if this is a future notification message
                        int notiLevel = NotificationService.NOTI_NONE;
                        String notification = "n";
                        if (Assignment.ASSIGNMENT_OPENDATE_NOTIFICATION_LOW.equals(valueOpenDateNotification)) {
                            notiLevel = NotificationService.NOTI_OPTIONAL;
                            notification = "o";
                        } else if (Assignment.ASSIGNMENT_OPENDATE_NOTIFICATION_HIGH
                                .equals(valueOpenDateNotification)) {
                            notiLevel = NotificationService.NOTI_REQUIRED;
                            notification = "r";
                        }

                        Time now = TimeService.newTime();
                        if (openDateAnnounced != null && now.before(oldOpenTime)) {
                            message.getPropertiesEdit().addProperty("notificationLevel", notification);
                            message.getPropertiesEdit().addPropertyToList("noti_history",
                                    now.toStringLocalFull() + "_" + notiLevel + "_" + openDateAnnounced);
                        } else {
                            message.getPropertiesEdit().addPropertyToList("noti_history",
                                    now.toStringLocalFull() + "_" + notiLevel);
                        }

                        channel.commitMessage(message, notiLevel,
                                "org.sakaiproject.announcement.impl.SiteEmailNotificationAnnc");
                    }

                    // commit related properties into Assignment object
                    AssignmentEdit aEdit = editAssignment(a.getReference(), "integrateWithAnnouncement", state,
                            false);
                    if (aEdit != null) {
                        aEdit.getPropertiesEdit().addProperty(NEW_ASSIGNMENT_OPEN_DATE_ANNOUNCED,
                                Boolean.TRUE.toString());
                        if (message != null) {
                            aEdit.getPropertiesEdit().addProperty(
                                    ResourceProperties.PROP_ASSIGNMENT_OPENDATE_ANNOUNCEMENT_MESSAGE_ID,
                                    message.getId());
                        }
                        AssignmentService.commitEdit(aEdit);
                    }

                } catch (PermissionException ee) {
                    M_log.warn(this + ":IntegrateWithAnnouncement " + rb.getString("cannotmak"));
                }
            }
        }
    } // if
}

From source file:org.zanata.action.VersionHome.java

public boolean isValidationsSameAsProject() {
    Collection<ValidationAction> versionValidations = validationServiceImpl
            .getValidationActions(getProjectSlug(), getSlug());
    Collection<ValidationAction> projectValidations = validationServiceImpl
            .getValidationActions(getProjectSlug());
    return versionValidations.equals(projectValidations);
}

From source file:qupath.lib.gui.tma.TMASummaryViewer.java

void setTMAEntries(final Collection<TMAEntry> newEntries) {

    //      boolean containsSummaries = newEntries.stream().anyMatch(e -> e instanceof TMASummaryEntry);

    // Turn off use-selected - can be crashy when replacing entries
    if (!newEntries.equals(entriesBase)) {
        useSelectedProperty.set(false);/*from   ww  w .j  av  a 2  s. c om*/

        // Reset the cache
        imageCache.clear();

        // Try to load small images in a background thread
        List<TMAEntry> duplicateEntries = new ArrayList<>(newEntries);
        ExecutorService service = Executors.newSingleThreadExecutor();
        service.submit(() -> {
            duplicateEntries.parallelStream().forEach(entry -> {
                imageCache.getImage(entry, maxSmallWidth.get());
                imageCache.getOverlay(entry, maxSmallWidth.get());
            });
        });
        service.shutdown();

    }
    this.entriesBase.setAll(newEntries);

    // Store the names of any currently hidden columns
    lastHiddenColumns = table.getColumns().stream().filter(c -> !c.isVisible()).map(c -> c.getText())
            .collect(Collectors.toSet());

    //      this.table.getColumns().clear();

    //      // Useful for a paper, but not generally...
    //      int count = 0;
    //      int nCells = 0;
    //      int nTumor = 0;
    //      for (TMAEntry entry : entriesBase) {
    //         if (!entry.isMissing() && (predicate.get() == null || predicate.get().test(entry))) {
    //            count++;
    //            nCells += (int)(entry.getMeasurement("Num Tumor").doubleValue() + entry.getMeasurement("Num Stroma").doubleValue());
    //            nTumor += (int)(entry.getMeasurement("Num Tumor").doubleValue());
    //         }
    //      }
    //      System.err.println(String.format("Num entries:\t%d\tNum tumor:\t%d\tNum cells:\t%d", count, nTumor, nCells));

    // Update measurement names
    Set<String> namesMeasurements = new LinkedHashSet<>();
    Set<String> namesMetadata = new LinkedHashSet<>();
    //      boolean containsSummaries = false;
    for (TMAEntry entry : newEntries) {
        namesMeasurements.addAll(entry.getMeasurementNames());
        namesMetadata.addAll(entry.getMetadataNames());
        //         containsSummaries = containsSummaries || entry instanceof TMASummaryEntry;
    }

    // Get the available survival columns
    String currentSurvival = getSurvivalColumn();
    survivalColumns.clear();
    if (namesMeasurements.contains(TMACoreObject.KEY_OVERALL_SURVIVAL))
        survivalColumns.add(TMACoreObject.KEY_OVERALL_SURVIVAL);
    if (namesMeasurements.contains(TMACoreObject.KEY_RECURRENCE_FREE_SURVIVAL))
        survivalColumns.add(TMACoreObject.KEY_RECURRENCE_FREE_SURVIVAL);
    if (currentSurvival != null && survivalColumns.contains(currentSurvival))
        comboSurvival.getSelectionModel().select(currentSurvival);
    else if (!survivalColumns.isEmpty())
        comboSurvival.getSelectionModel().select(survivalColumns.get(0));

    //      // Add the count of non-missing cores if we are working with summaries
    //      if (containsSummaries)
    namesMeasurements.add("Available cores");

    // Make sure there are no nulls or other unusable values
    namesMeasurements.remove(null);
    namesMeasurements.remove("");
    //      measurementNames.clear();
    String selectedMainMeasurement = comboMainMeasurement.getSelectionModel().getSelectedItem();
    measurementNames.setAll(namesMeasurements);
    if (namesMeasurements.contains(selectedMainMeasurement))
        comboMainMeasurement.getSelectionModel().select(selectedMainMeasurement);
    else {
        namesMeasurements.remove(TMACoreObject.KEY_UNIQUE_ID);
        namesMeasurements.remove(TMACoreObject.KEY_OVERALL_SURVIVAL);
        namesMeasurements.remove(TMACoreObject.KEY_RECURRENCE_FREE_SURVIVAL);
        namesMeasurements.remove(TMACoreObject.KEY_OS_CENSORED);
        namesMeasurements.remove(TMACoreObject.KEY_RFS_CENSORED);
        namesMeasurements.remove("Censored"); // For historical reasons when there was only one censored column supported...
        if (!namesMeasurements.isEmpty())
            comboMainMeasurement.getSelectionModel().select(0);
    }
    metadataNames.clear();
    metadataNames.addAll(namesMetadata);

    refreshTableData();

    // The next time the table is empty, show a different placeholder 
    // from the original (which is for loading/import)
    table.setPlaceholder(new Text("No data"));
}

From source file:relationalFramework.RelationalRule.java

/**
 * Sets the conditions of this guided rule, if the conditions are valid.
 * /*from   ww w . j a v a 2  s.  com*/
 * @param conditions
 *            The conditions for the guided rule.
 * @return True if the newly set conditions are different from the old.
 */
public boolean setConditions(Collection<RelationalPredicate> conditions) {
    // If the conditions are the same, return true.
    if (conditions.equals(rawConditions_)) {
        return false;
    }

    // Reset the states seen, as the rule has changed.
    hasSpawned_ = null;
    rawConditions_ = new ArrayList<RelationalPredicate>(conditions);
    expandConditions(null);
    findConstantsAndRanges();
    return true;
}