Example usage for java.util Collection contains

List of usage examples for java.util Collection contains

Introduction

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

Prototype

boolean contains(Object o);

Source Link

Document

Returns true if this collection contains the specified element.

Usage

From source file:at.ac.tuwien.qse.sepm.dao.repo.PhotoProviderTest.java

@Test
public void readAll_someExisting_returnsPhotos() throws DAOException {
    PhotoProvider object = getObject();//  www  . j  a  va  2s  .c  o  m
    Photo photo1 = getContext().getPhoto1();
    Photo photo2 = getContext().getPhoto2();
    add(object, photo1);
    add(object, photo2);

    Collection<Photo> photos = object.readAll();
    assertEquals(2, photos.size());
    assertTrue(photos.contains(photo1));
    assertTrue(photos.contains(photo2));
}

From source file:com.adaptris.core.runtime.AdapterComponentCheckerTest.java

public void testRegistered() throws Exception {
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName, 2, 2);
    List<BaseComponentMBean> mBeans = createJmxManagers(adapter);
    ObjectName objectName = createComponentCheckerObjectName(adapterName);
    register(mBeans);//from  w ww. j  a v a2  s.c o m
    ObjectName adapterObj = createAdapterObjectName(adapterName);
    AdapterManagerMBean manager = JMX.newMBeanProxy(mBeanServer, adapterObj, AdapterManagerMBean.class);
    Collection<ObjectName> names = manager.getChildRuntimeInfoComponents();
    assertTrue(names.contains(objectName));
}

From source file:io.github.brinman2002.pipeline.NaiveBayesianClassifierTest.java

@Test
public void train() {
    final PTable<Long, Attribute> attributes = MemPipeline.typedTableOf(TABLE_OF_ATTRIBUTES, attributes());
    final PTable<Long, Outcome> outcomes = MemPipeline.typedTableOf(TABLE_OF_OUTCOMES, outcomes());

    final Pair<PTable<Attribute, Pair<Outcome, Double>>, PTable<Outcome, Double>> trained = NaiveBayesianClassifier
            .train(attributes, outcomes);
    System.out.println(trained.first());
    // System.out.println(trained.second());
    // TODO assert expected values

    final Collection<Pair<Outcome, Double>> outcomeProbabilities = trained.second().asCollection().getValue();

    assertEquals(4, outcomeProbabilities.size());
    assertTrue(outcomeProbabilities.contains(Pair.of(outcome("a"), Double.valueOf(0.5))));
    assertTrue(outcomeProbabilities.contains(Pair.of(outcome("b"), Double.valueOf(0.25))));
    assertTrue(outcomeProbabilities.contains(Pair.of(outcome("c"), Double.valueOf(0.125))));
    assertTrue(outcomeProbabilities.contains(Pair.of(outcome("d"), Double.valueOf(0.125))));
}

From source file:io.github.moosbusch.lumpi.gui.form.editor.io.spi.ListButtonStoreValueDelegate.java

@SuppressWarnings("unchecked")
@Override//from w w w  . j a v a  2  s . c  om
public void storeValue(Object context) {
    if (context != null) {
        ListButton listButton = getFormEditor().getComponent();
        String propertyName = listButton.getListDataKey();
        ListView.ListDataBindMapping bindMapping = listButton.getListDataBindMapping();
        Object newPropertyValue = bindMapping.valueOf(listButton.getListData());

        if (PropertyUtils.isWriteable(context, propertyName)) {
            listButton.store(context);
        } else {
            Object oldPropertyValue = null;

            try {
                oldPropertyValue = PropertyUtils.getProperty(context, propertyName);
            } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) {
                Logger.getLogger(AbstractDynamicForm.class.getName()).log(Level.SEVERE, null, ex);
            } finally {
                if ((newPropertyValue != null) && (oldPropertyValue != null)) {
                    if ((newPropertyValue instanceof java.util.Collection)
                            && (oldPropertyValue instanceof java.util.Collection)) {
                        java.util.Collection<Object> newColl = (java.util.Collection<Object>) newPropertyValue;
                        java.util.Collection<Object> oldColl = (java.util.Collection<Object>) oldPropertyValue;

                        newColl.stream().filter((obj) -> (!oldColl.contains(obj))).forEach((obj) -> {
                            oldColl.add(obj);
                        });
                    } else if ((newPropertyValue instanceof Sequence)
                            && (oldPropertyValue instanceof Sequence)) {
                        Sequence<Object> newSeq = (Sequence<Object>) newPropertyValue;
                        Sequence<Object> oldSeq = (Sequence<Object>) oldPropertyValue;

                        for (int cnt = 0; cnt < newSeq.getLength(); cnt++) {
                            Object obj = newSeq.get(cnt);

                            if (oldSeq.indexOf(obj) == -1) {
                                oldSeq.add(obj);
                            }
                        }
                    } else if ((newPropertyValue instanceof org.apache.pivot.collections.Set)
                            && (oldPropertyValue instanceof org.apache.pivot.collections.Set)) {
                        org.apache.pivot.collections.Set<Object> newColl = (org.apache.pivot.collections.Set<Object>) newPropertyValue;
                        org.apache.pivot.collections.Set<Object> oldColl = (org.apache.pivot.collections.Set<Object>) oldPropertyValue;

                        for (Object obj : newColl) {
                            if (!oldColl.contains(obj)) {
                                oldColl.add(obj);
                            }
                        }
                    } else if ((ObjectUtils.isArray(newPropertyValue))
                            && (ObjectUtils.isArray(oldPropertyValue))) {
                        Object[] newArray = (Object[]) newPropertyValue;
                        Object[] oldArray = (Object[]) oldPropertyValue;

                        for (Object obj : newArray) {
                            if (!ArrayUtils.contains(oldArray, obj)) {
                                oldArray = ArrayUtils.add(oldArray, obj);
                            }
                        }
                    }
                }
            }
        }
    }
}

From source file:com.samsung.sjs.theorysolver.TheorySolverTest.java

/**
 * This tests the {@link TheorySolver} using a theory which has a random set of
 * blacklisted objects. We verify that the TheorySolver always finds the entire
 * set of non-blacklisted objects./*from  www  .j  a v a  2 s. c  o m*/
 */
@Test
public void testBasics() {

    List<Object> all = Arrays.asList("a", "b", "c", "d", "e", "f", "g", "h");

    for (int i = 0; i < 100; ++i) {
        Random r = new Random(SEED + i);

        Collection<Object> truthy = all.stream().filter(x -> r.nextBoolean()).collect(Collectors.toSet());

        Theory<Object, Void> theory = positive -> {
            Collection<Object> bad = positive.stream().filter(x -> !truthy.contains(x))
                    .collect(Collectors.toSet());
            if (bad.size() > 0) {
                // Construct a random, nonempty unsat core.
                Collection<Object> unsat = new HashSet<>();
                unsat.add(bad.iterator().next());
                bad.stream().filter(x -> r.nextBoolean()).forEach(unsat::add);
                return Either.right(unsat);
            } else {
                return Either.left(null);
            }
        };

        Pair<Void, Collection<Object>> result = TheorySolver.solve(theory,
                new SatFixingSetFinder<>(new Sat4J()), Collections.emptyList(), all);

        Assert.assertEquals(all.size() - truthy.size(), result.getRight().size());
        Assert.assertEquals(truthy,
                all.stream().filter(x -> !result.getRight().contains(x)).collect(Collectors.toSet()));
    }

}

From source file:bjerne.gallery.service.impl.GalleryAuthorizationServiceSSImpl.java

private Map<String, File> getRootPathsForRoles(Collection<String> roles, Collection<GalleryRootDir> rootDirs) {
    Map<String, File> rootPathsForRoles = rootDirs.stream().filter(r -> roles.contains(r.getRole()))
            .collect(Collectors.toMap(GalleryRootDir::getName, GalleryRootDir::getDir));
    LOG.debug("Root paths for roles {}: {}", roles, rootPathsForRoles);
    return rootPathsForRoles;
}

From source file:com.drazzib.neo4j.PubServiceTest.java

@Test
public void testGetAllBeers() {
    Collection<Beer> madeBeers = service.populateData();
    Iterable<Beer> foundBeers = service.getAllBeers();

    int founds = 0;
    for (Beer foundBeer : foundBeers) {
        assertTrue(madeBeers.contains(foundBeer));
        founds++;/* ww  w .j  av  a 2  s  . c o m*/
    }

    assertEquals(madeBeers.size(), founds);
}

From source file:com.yahoo.sshd.authentication.file.TestPKUpdating.java

private void checkExist(TestContext testContext, User[] users) {
    Collection<String> authenticatedUsers = testContext.publickeyAuthenticator.getUsers();

    for (User user : users) {
        Assert.assertTrue(authenticatedUsers.contains(user.name), "expected " + user + " to be authenticated");
    }/*from w w  w  . ja  va 2  s.  c om*/
}

From source file:de.costache.calendar.util.IndexedEventCollection.java

@Override
@SuppressWarnings("unchecked")
public void remove(final CalendarEvent calendarEvent) {
    calendarEvent.deleteObserver(this);
    selectedEvents.remove(calendarEvent);

    for (final Object key : new HashSet<Object>(indexedEvents.keySet())) {
        final Collection<CalendarEvent> events = indexedEvents.getCollection(key);
        if (events.contains(calendarEvent))
            indexedEvents.remove(key, calendarEvent);
    }//from   w w  w.  ja  va  2  s .c om

    notifyObservers();

    final ModelChangedEvent event = new ModelChangedEvent(parent, calendarEvent);
    for (final ModelChangedListener listener : collectionChangedListeners) {
        listener.eventRemoved(event);
    }
}

From source file:org.socialsignin.springsocial.security.signin.SpringSocialSecurityAuthenticationFactory.java

private Collection<? extends GrantedAuthority> addAuthority(Authentication authentication,
        GrantedAuthority newAuthority) {
    Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
    authorities.addAll(authentication.getAuthorities());
    if (newAuthority != null) {
        if (!authorities.contains(newAuthority)) {
            authorities.add(newAuthority);
        }/* ww w . j  av a  2  s.  c  om*/
    }

    return authorities;
}