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:com.googlecode.fightinglayoutbugs.DetectElementsWithInvisibleFocus.java

@Nullable
private FocusedElement focusNextElement(FocusedElement focusedElement, WebPage webPage,
        Collection<WebElement> visitedElements) {
    focusedElement.element.sendKeys(Keys.TAB);
    final WebElement focusedWebElement = getFocusedWebElement(webPage);
    if (focusedWebElement != null && !visitedElements.contains(focusedWebElement)
            && !"body".equals(focusedWebElement.getTagName().toLowerCase())) {
        visitedElements.add(focusedWebElement);
        return toFocusedElement(focusedWebElement, webPage);
    } else {//  w  w w  .ja va2s. c  o  m
        return null;
    }
}

From source file:AccomManagerImplTest.java

/**
 * Test of getAllAccoms method, of class AccomManagerImpl.
 *//*  w  w w.  j av a 2 s  .  c  o m*/
@Test
public void testGetAllAccoms() {
    Guest guest = newGuest("Pavel", "1234");
    Room room = newRoom(10, 3);
    guestManager.createGuest(guest);
    roomManager.createRoom(room);
    Long guestID = guest.getGuestID();
    Long roomID = room.getRoomID();

    Date startDate = date("2010-1-1");
    Date endDate = date("2012-1-1");
    Accomodation accom = newAccom(guestID, roomID, startDate, endDate);
    accomManager.createAccom(accom);
    Long accomId = accom.getAccomId();

    Room room2 = newRoom(5, 5);
    roomManager.createRoom(room2);
    Accomodation accom2 = newAccom(guestID, room2.getRoomID(), startDate, endDate);
    accomManager.createAccom(accom2);
    Collection result = accomManager.getAllAccoms();
    assertTrue(result.contains(accom));
    assertTrue(result.contains(accom2));
    assertEquals(result.size(), 2);
}

From source file:com.cloudera.oryx.kmeans.computation.local.Standarize.java

@Override
public List<List<RealVector>> call() throws IOException {
    File[] inputFiles = inputDir.listFiles(IOUtils.CSV_COMPRESSED_FILTER);
    if (inputFiles == null || inputFiles.length == 0) {
        log.info("No .csv input files in {}", inputDir);
        return null;
    }//from w  ww.j  av  a 2  s . c o  m

    Config config = ConfigUtils.getDefaultConfig();
    InboundSettings inboundSettings = InboundSettings.create(config);
    int numFeatures = inboundSettings.getColumnNames().size();
    NormalizeSettings settings = NormalizeSettings.create(config);
    Crossfold crossfold = new Crossfold(config.getInt("model.cross-folds"));
    RandomGenerator rand = crossfold.getRandomGenerator();

    Collection<Integer> ignoredColumns = inboundSettings.getIgnoredColumns();
    Collection<Integer> idColumns = inboundSettings.getIdColumns();
    int expansion = -ignoredColumns.size() + summary.getNetLevels()
            - (!idColumns.isEmpty() && !ignoredColumns.contains(idColumns.iterator().next()) ? 1 : 0);
    boolean sparse = settings.getSparse() != null ? settings.getSparse()
            : expansion > 2 * (summary.getFieldCount() - ignoredColumns.size());

    List<List<RealVector>> ret = Lists.newArrayList();
    for (int i = 0; i < crossfold.getNumFolds(); i++) {
        ret.add(Lists.<RealVector>newLinkedList());
    }
    for (File inputFile : inputFiles) {
        log.info("Standardizing input from {}", inputFile.getName());
        for (String line : new FileLineIterable(inputFile)) {
            if (line.isEmpty()) {
                continue;
            }
            String[] tokens = DelimitedDataUtils.decode(line);
            RealVector v = sparse ? Vectors.sparse(tokens.length + expansion)
                    : Vectors.dense(tokens.length + expansion);
            int offset = 0;
            for (int i = 0; i < numFeatures; i++) {
                if (inboundSettings.isIgnored(i)) {
                    // Do nothing
                } else if (inboundSettings.isNumeric(i)) {
                    SummaryStats ss = summary.getStats(i);
                    Transform t = settings.getTransform(i);
                    double raw = asDouble(tokens[i]);
                    if (!Double.isNaN(raw)) {
                        double n = t.apply(raw, ss) * settings.getScale(i);
                        v.setEntry(offset, n);
                    }
                    offset++;
                } else if (inboundSettings.isCategorical(i)) {
                    SummaryStats ss = summary.getStats(i);
                    int index = ss.index(tokens[i]);
                    if (index >= 0) {
                        v.setEntry(offset + index, settings.getScale(i));
                        offset += ss.numLevels();
                    } else {
                        log.warn("Unrecognized value for category {}: {}", i, tokens[i]);
                    }
                }
            }
            if (!inboundSettings.getIdColumns().isEmpty()) {
                // TODO: multiple ID columns
                v = new NamedRealVector(v, tokens[inboundSettings.getIdColumns().iterator().next()]);
            }
            // Assign the vector to a fold
            int fold = rand.nextInt(crossfold.getNumFolds());
            ret.get(fold).add(v);
        }
    }
    return ret;
}

From source file:com.cloudera.oryx.kmeans.computation.local.Standardize.java

@Override
public List<List<RealVector>> call() throws IOException {
    File[] inputFiles = inputDir.listFiles(IOUtils.NOT_HIDDEN);
    if (inputFiles == null || inputFiles.length == 0) {
        log.info("No input files in {}", inputDir);
        return null;
    }//from  w w  w  .j  av a  2 s . c o m

    Config config = ConfigUtils.getDefaultConfig();
    InboundSettings inboundSettings = InboundSettings.create(config);
    int numFeatures = inboundSettings.getColumnNames().size();
    NormalizeSettings settings = NormalizeSettings.create(config);
    Crossfold crossfold = new Crossfold(config.getInt("model.cross-folds"));
    RandomGenerator rand = crossfold.getRandomGenerator();

    Collection<Integer> ignoredColumns = inboundSettings.getIgnoredColumns();
    Collection<Integer> idColumns = inboundSettings.getIdColumns();
    int expansion = -ignoredColumns.size() + summary.getNetLevels()
            - (!idColumns.isEmpty() && !ignoredColumns.contains(idColumns.iterator().next()) ? 1 : 0);
    boolean sparse = settings.getSparse() != null ? settings.getSparse()
            : expansion > 2 * (summary.getFieldCount() - ignoredColumns.size());

    List<List<RealVector>> ret = new ArrayList<>();
    for (int i = 0; i < crossfold.getNumFolds(); i++) {
        ret.add(new LinkedList<RealVector>());
    }
    for (File inputFile : inputFiles) {
        log.info("Standardizing input from {}", inputFile.getName());
        for (String line : new FileLineIterable(inputFile)) {
            if (line.isEmpty()) {
                continue;
            }
            String[] tokens = DelimitedDataUtils.decode(line);
            RealVector v = sparse ? Vectors.sparse(tokens.length + expansion)
                    : Vectors.dense(tokens.length + expansion);
            int offset = 0;
            for (int i = 0; i < numFeatures; i++) {
                if (!inboundSettings.isIgnored(i)) {
                    if (inboundSettings.isNumeric(i)) {
                        SummaryStats ss = summary.getStats(i);
                        Transform t = settings.getTransform(i);
                        double raw = asDouble(tokens[i]);
                        if (!Double.isNaN(raw)) {
                            double n = t.apply(raw, ss) * settings.getScale(i);
                            v.setEntry(offset, n);
                        }
                        offset++;
                    } else if (inboundSettings.isCategorical(i)) {
                        SummaryStats ss = summary.getStats(i);
                        int index = ss.index(tokens[i]);
                        if (index >= 0) {
                            v.setEntry(offset + index, settings.getScale(i));
                            offset += ss.numLevels();
                        } else {
                            log.warn("Unrecognized value for category {}: {}", i, tokens[i]);
                        }
                    }
                }
            }
            if (!inboundSettings.getIdColumns().isEmpty()) {
                // TODO: multiple ID columns
                v = new NamedRealVector(v, tokens[inboundSettings.getIdColumns().iterator().next()]);
            }
            // Assign the vector to a fold
            int fold = rand.nextInt(crossfold.getNumFolds());
            ret.get(fold).add(v);
        }
    }
    return ret;
}

From source file:de.hybris.platform.core.RestartSlaveTenantTest.java

@Test
public void testAssignSlaveDataSourceParamsFromMaster() throws Exception {
    final String fromJndi = StringUtils.isBlank(
            Registry.getMasterTenant().getConfig().getParameter(SystemSpecificParams.DB_POOL_FROMJNDI)) ? null
                    : Registry.getMasterTenant().getConfig()
                            .getParameter(SystemSpecificParams.DB_POOL_FROMJNDI);
    //      final String prefix = Registry.getMasterTenant().getConfig().getParameter(SystemSpecificParams.DB_TABLEPREFIX);
    final String url = Registry.getMasterTenant().getConfig().getParameter(SystemSpecificParams.DB_URL);
    final String user = Registry.getMasterTenant().getConfig().getParameter(SystemSpecificParams.DB_USERNAME);

    try {//from  ww  w  . j  a  va 2  s. c  o  m
        //this might throw some exception 

        final Collection<String> loadedAltIds = fooTenant.getAllAlternativeMasterDataSourceIDs();

        Assert.assertTrue(loadedAltIds.contains("alt1"));
        Assert.assertTrue(loadedAltIds.contains("alt2"));

        for (final HybrisDataSource slaveDataSource : fooTenant.getAllAlternativeMasterDataSources()) {
            LOG.info(slaveDataSource.getID());
            Assert.assertEquals(fromJndi, slaveDataSource.getJNDIName());
            LOG.info(slaveDataSource.getDatabaseName());
            Assert.assertEquals(url, slaveDataSource.getDatabaseURL());
            //db user is highly db provider dependent
            if (Config.isHSQLDBUsed()) {
                Assert.assertTrue(user.equalsIgnoreCase(slaveDataSource.getDatabaseUser()));
            } else {
                Assert.assertTrue(slaveDataSource.getDatabaseUser().startsWith(user));
            }
            LOG.info(slaveDataSource.getDatabaseVersion());
        }

        final Collection<String> loadedSlaveIds = fooTenant.getAllSlaveDataSourceIDs();

        Assert.assertEquals(3, loadedSlaveIds.size());
        Assert.assertTrue(loadedSlaveIds.contains("a"));
        Assert.assertTrue(loadedSlaveIds.contains("b"));
        Assert.assertTrue(loadedSlaveIds.contains("c"));

        for (final HybrisDataSource altDataSource : fooTenant.getAllSlaveDataSources()) {
            LOG.info(altDataSource.getID());
            Assert.assertEquals(fromJndi, altDataSource.getJNDIName());
            LOG.info(altDataSource.getDatabaseName());
            Assert.assertEquals(url, altDataSource.getDatabaseURL());
            //db user is highly db provider dependent
            if (Config.isHSQLDBUsed()) {
                Assert.assertTrue(user.equalsIgnoreCase(altDataSource.getDatabaseUser()));
            } else {
                Assert.assertTrue(altDataSource.getDatabaseUser().startsWith(user));
            }
            LOG.info(altDataSource.getDatabaseVersion());
        }
    } finally {
        //
    }
}

From source file:org.opendatakit.persistence.table.UserGrantedAuthority.java

/**
 * Asserts that the given group has exactly the list of desired members and no additional members.
 * /*  www  . ja v  a  2  s  .  c o  m*/
 * @param group
 * @param desiredMembers
 * @param cc
 * @throws ODKDatastoreException
 */
public static final void assertGrantedAuthorityMembers(GrantedAuthority group,
        Collection<String> desiredMembers, CallingContext cc) throws ODKDatastoreException {

    Datastore ds = cc.getDatastore();
    User user = cc.getCurrentUser();
    boolean hasNotChanged = true;

    try {
        UserGrantedAuthority relation = UserGrantedAuthority.assertRelation(ds, user);

        // get the members as currently defined for this group
        List<? extends CommonFieldsBase> membersList;
        Query query = ds.createQuery(relation, "UserGrantedAuthority.assertGrantedAuthorityMembers", user);
        query.addFilter(UserGrantedAuthority.GRANTED_AUTHORITY, FilterOperation.EQUAL, group.getAuthority());
        membersList = query.executeQuery();

        // OK we have the desired and actual members lists for this groupname.
        // find the set of members to remove...
        List<EntityKey> deleted = new ArrayList<EntityKey>();
        for (CommonFieldsBase b : membersList) {
            UserGrantedAuthority t = (UserGrantedAuthority) b;
            String uriUser = t.getUser();
            if (desiredMembers.contains(uriUser)) {
                desiredMembers.remove(uriUser);
            } else {
                deleted.add(t.getEntityKey());
            }
        }
        // we now have the list of desiredMembers to insert, and the list of
        // existing records to delete...
        List<UserGrantedAuthority> added = new ArrayList<UserGrantedAuthority>();
        for (String uriUser : desiredMembers) {
            UserGrantedAuthority t = ds.createEntityUsingRelation(relation, user);
            t.setUser(uriUser);
            t.setGrantedAuthority(group);
            added.add(t);
        }

        // we have no changes if there are no adds and no deletes
        hasNotChanged = added.isEmpty() && deleted.isEmpty();

        // we now have the list of EntityKeys to delete, and the list of records to add -- do it.
        ds.putEntities(added, user);
        ds.deleteEntities(deleted, user);
    } finally {
        if (!hasNotChanged) {
            // we've changed -- reload the permissions tree...
            cc.getUserService().reloadPermissions();
        }
    }
}

From source file:com.vrem.util.EnumUtilsTest.java

private void validate(Collection<TestObject> expected, final Collection<TestObject> actual) {
    assertEquals(expected.size(), actual.size());
    IterableUtils.forEach(expected, new Closure<TestObject>() {
        @Override/*from  w  ww .  ja v  a2s  .c o  m*/
        public void execute(TestObject input) {
            assertTrue(actual.contains(input));
        }
    });
}

From source file:com.xpn.xwiki.internal.doc.XWikiAttachmentList.java

@Override
public boolean retainAll(Collection<?> c) {
    boolean changed = false;
    Collection<XWikiAttachment> values = this.map.values();
    for (XWikiAttachment x : values) {
        if (!c.contains(x)) {
            this.map.remove(x.getFilename());
            changed = true;/* www . ja va2  s  .c  om*/
        }
    }

    if (changed) {
        updateList();
    }

    return changed;
}

From source file:org.opendatakit.persistence.table.UserGrantedAuthority.java

public static final void assertUserGrantedAuthorities(String uriUser, Collection<String> desiredGroups,
        CallingContext cc) throws ODKDatastoreException {

    Datastore ds = cc.getDatastore();/*from ww w .  jav  a2s .  c  o m*/
    User user = cc.getCurrentUser();

    boolean hasNotChanged = true;

    try {
        UserGrantedAuthority relation = UserGrantedAuthority.assertRelation(ds, user);

        // get the members as currently defined for this group
        List<? extends CommonFieldsBase> groupsList;
        Query query = ds.createQuery(relation, "UserGrantedAuthority.assertUserGrantedAuthorities", user);
        query.addFilter(UserGrantedAuthority.USER, FilterOperation.EQUAL, uriUser);
        groupsList = query.executeQuery();

        // OK we have the desired and actual groups lists for this username.
        // find the set of groups to remove...
        List<EntityKey> deleted = new ArrayList<EntityKey>();
        for (CommonFieldsBase b : groupsList) {
            UserGrantedAuthority t = (UserGrantedAuthority) b;
            String groupName = t.getGrantedAuthority().getAuthority();
            if (desiredGroups.contains(groupName)) {
                desiredGroups.remove(groupName);
            } else {
                deleted.add(t.getEntityKey());
            }
        }
        // we now have the list of desiredGroups to insert, and the list of
        // existing records to delete...
        List<UserGrantedAuthority> added = new ArrayList<UserGrantedAuthority>();
        for (String group : desiredGroups) {
            UserGrantedAuthority t = ds.createEntityUsingRelation(relation, user);
            t.setUser(uriUser);
            t.setGrantedAuthority(new SimpleGrantedAuthority(group));
            added.add(t);
        }

        // nothing has changed if there are no adds and no deletes.
        hasNotChanged = added.isEmpty() && deleted.isEmpty();

        // we now have the list of EntityKeys to delete, and the list of records to add -- do it.
        ds.putEntities(added, user);
        ds.deleteEntities(deleted, user);
    } finally {
        if (!hasNotChanged) {
            // we've changed, so we need to reload permissions tree
            cc.getUserService().reloadPermissions();
        }
    }
}

From source file:org.jtheque.movies.services.impl.FilesServiceTest.java

@Test
public void testGetMovieFiles() {
    FileUnit.addFile("Movie 1.avi");
    FileUnit.addFile("Movie 2.avi");
    FileUnit.addFile("Test 2.jpg");
    FileUnit.addFolder("Folder 1");
    FileUnit.addFile("Folder 1", "Movie 3.avi");
    FileUnit.addFile("Folder 1", "Test 2.jpg");
    FileUnit.addFolder("Folder 2");
    FileUnit.addFile("Folder 2", "Movie 4.avi");
    FileUnit.addFile("Folder 2", "Test 2.jpg");
    FileUnit.addFile("Folder 2", "Movie 5.avi");

    Collection<File> files = filesService.getMovieFiles(FileUnit.getFile("Movie 1.avi"));

    assertTrue(files.isEmpty());// w  w w .  j a va  2  s .  c o  m

    files = filesService.getMovieFiles(FileUnit.getFile("Folder 1"));

    assertEquals(1, files.size());

    assertTrue(files.contains(FileUnit.getFile("Folder 1", "Movie 3.avi")));

    files = filesService.getMovieFiles(FileUnit.getFile("Folder 2"));

    assertEquals(2, files.size());

    assertTrue(files.contains(FileUnit.getFile("Folder 2", "Movie 4.avi")));
    assertTrue(files.contains(FileUnit.getFile("Folder 2", "Movie 5.avi")));

    files = filesService.getMovieFiles(new File(FileUnit.getRootFolder()));

    assertEquals(5, files.size());

    assertTrue(files.contains(FileUnit.getFile("Movie 1.avi")));
    assertTrue(files.contains(FileUnit.getFile("Movie 2.avi")));
    assertTrue(files.contains(FileUnit.getFile("Folder 1", "Movie 3.avi")));
    assertTrue(files.contains(FileUnit.getFile("Folder 2", "Movie 4.avi")));
    assertTrue(files.contains(FileUnit.getFile("Folder 2", "Movie 5.avi")));
}