Example usage for java.util List containsAll

List of usage examples for java.util List containsAll

Introduction

In this page you can find the example usage for java.util List containsAll.

Prototype

boolean containsAll(Collection<?> c);

Source Link

Document

Returns true if this list contains all of the elements of the specified collection.

Usage

From source file:cz.swi2.mendeluis.dataaccesslayer.domain.UserFavouriteItemTest.java

@org.testng.annotations.Test
public void testGetAllByUser() {
    // Create entities
    User u = new User("michal", "michal", "pw123456");
    FavouriteItem f1 = new FavouriteItem("Food menu xx");
    FavouriteItem f2 = new FavouriteItem("Food menu x2");
    UserFavouriteItem uf1 = new UserFavouriteItem(u, f1, 0);
    UserFavouriteItem uf2 = new UserFavouriteItem(u, f2, 0);

    // Insert /* w w w  .  jav  a 2 s. c  o m*/
    this.userRepository.insert(u);
    this.favouriteItemRepository.insert(f1);
    this.favouriteItemRepository.insert(f2);
    this.userFavouriteItemRepository.insert(uf1);
    this.userFavouriteItemRepository.insert(uf2);

    // Fetch all user userFavouriteItems
    List<UserFavouriteItem> results = this.userFavouriteItemRepository.getAllByUser(u);

    // Prepare a list to be compared
    List<UserFavouriteItem> favi = new ArrayList();
    favi.add(uf1);
    favi.add(uf2);

    // We do not use a different db for testing. Thefore we must test only matching items, not all. 
    assertTrue(results.containsAll(favi));
}

From source file:org.spring.data.gemfire.cache.SpringGemfireTemplateTests.java

@Test
public void query() {
    String query;//from  w ww  . j a v a 2s . c om

    // METHOD 1 - the following OQL query syntax absolutely does not work for a peer application cache scenario;
    // developer must use METHOD 2
    if (System.getProperty("spring.profiles.active").contains("client")) {
        query = String.format(
                "SELECT * FROM %1$s c WHERE c.birthDate >= DATE '%2$s' and c.birthDate <= DATE '%3$s'",
                customersTemplate.getRegion().getFullPath(), format(createDate(1980, Calendar.JULY, 1)),
                format(createDate(1995, Calendar.JUNE, 30)));

        assertEquals(
                "SELECT * FROM /Customers c WHERE c.birthDate >= DATE '1980-07-01' and c.birthDate <= DATE '1995-06-30'",
                query);

    }
    // METHOD 2 use for peer application cache
    else {
        query = String.format("birthDate >= DATE '%1$s' and birthDate <= DATE '%2$s'",
                format(createDate(1980, Calendar.JULY, 1)), format(createDate(1995, Calendar.JUNE, 30)));

        assertEquals("birthDate >= DATE '1980-07-01' and birthDate <= DATE '1995-06-30'", query);

    }

    System.out.printf("GemFire OQL Query is (%1$s)", query);

    SelectResults<Customer> customerResults = customersTemplate.query(query);

    assertNotNull(customerResults);

    List<Customer> actualCustomers = customerResults.asList();

    assertNotNull(actualCustomers);
    assertFalse(actualCustomers.isEmpty());
    assertEquals(expectedCustomers.size(), actualCustomers.size());
    assertTrue(String.format("Expected (%1$s); But was (%2$s)", expectedCustomers, actualCustomers),
            actualCustomers.containsAll(expectedCustomers));
}

From source file:cz.swi2.mendeluis.dataaccesslayer.domain.UserPortletTest.java

@org.testng.annotations.Test
public void testGetAll() {
    // Create entities
    User u = new User("ivo", "ivo", "pw123456");
    Portlet p = new Portlet("Food menu xx");
    Portlet p2 = new Portlet("Food menu xx 2");
    UserPortlet up = new UserPortlet(u, p, Placement.LEFT, 0);
    UserPortlet up2 = new UserPortlet(u, p2, Placement.RIGHT, 0);

    // Insert //from  w  w w. j  ava 2s. com
    this.userRepository.insert(u);
    this.portletRepository.insert(p);
    this.portletRepository.insert(p2);
    this.userPortletRepository.insert(up);
    this.userPortletRepository.insert(up2);

    // Fetch all user portlets
    List<UserPortlet> results = this.userPortletRepository.getAll();

    // Prepare a list to be compared
    List<UserPortlet> portlets = new ArrayList();
    portlets.add(up);
    portlets.add(up2);

    // We do not use a different db for testing. Thefore we must test only matching items, not all. 
    assertTrue(results.containsAll(portlets));
}

From source file:at.ac.tuwien.infosys.jcloudscale.test.unit.TestReflectionUtil.java

@Test
public void testGetClassesFromNames() throws ClassNotFoundException {
    Set<Class<?>> types = new HashSet<>(Primitives.allPrimitiveTypes());
    types.addAll(Primitives.allWrapperTypes());
    Collection<String> typeNames = transform(types, new Function<Class<?>, String>() {
        @Override//ww w.  j  a v a 2s  .com
        public String apply(Class<?> input) {
            return input.getName();
        }
    });

    List<Class<?>> classes = Arrays.asList(
            getClassesFromNames(typeNames.toArray(new String[typeNames.size()]), getSystemClassLoader()));
    assertEquals(types.size(), classes.size());
    assertEquals(true, classes.containsAll(Primitives.allPrimitiveTypes()));
    assertEquals(true, classes.containsAll(Primitives.allWrapperTypes()));
}

From source file:org.sonar.server.user.UserUpdater.java

private boolean updateScmAccounts(DbSession dbSession, UpdateUser updateUser, UserDto userDto,
        List<String> messages) {
    String email = updateUser.email();
    List<String> scmAccounts = sanitizeScmAccounts(updateUser.scmAccounts());
    List<String> existingScmAccounts = userDto.getScmAccountsAsList();
    if (updateUser.isScmAccountsChanged() && !(existingScmAccounts.containsAll(scmAccounts)
            && scmAccounts.containsAll(existingScmAccounts))) {
        if (!scmAccounts.isEmpty()) {
            String newOrOldEmail = email != null ? email : userDto.getEmail();
            if (validateScmAccounts(dbSession, scmAccounts, userDto.getLogin(), newOrOldEmail, userDto,
                    messages)) {/*from   w w w.  ja  va  2  s  .  c  om*/
                userDto.setScmAccounts(scmAccounts);
            }
        } else {
            userDto.setScmAccounts((String) null);
        }
        return true;
    }
    return false;
}

From source file:org.apache.lens.ml.impl.TableTestingSpec.java

/**
 * Validate.// www  .j  ava2s.co  m
 *
 * @return true, if successful
 */
public boolean validate() {
    List<FieldSchema> columns;
    try {
        Hive metastoreClient = Hive.get(conf);
        Table tbl = (db == null) ? metastoreClient.getTable(inputTable)
                : metastoreClient.getTable(db, inputTable);
        columns = tbl.getAllCols();
        columnNameToFieldSchema = new HashMap<String, FieldSchema>();

        for (FieldSchema fieldSchema : columns) {
            columnNameToFieldSchema.put(fieldSchema.getName(), fieldSchema);
        }

        // Check if output table exists
        Table outTbl = metastoreClient.getTable(db == null ? "default" : db, outputTable, false);
        outputTableExists = (outTbl != null);
    } catch (HiveException exc) {
        log.error("Error getting table info {}", toString(), exc);
        return false;
    }

    // Check if labeled column and feature columns are contained in the table
    List<String> testTableColumns = new ArrayList<String>(columns.size());
    for (FieldSchema column : columns) {
        testTableColumns.add(column.getName());
    }

    if (!testTableColumns.containsAll(featureColumns)) {
        log.info("Invalid feature columns: {}. Actual columns in table:{}", featureColumns, testTableColumns);
        return false;
    }

    if (!testTableColumns.contains(labelColumn)) {
        log.info("Invalid label column: {}. Actual columns in table:{}", labelColumn, testTableColumns);
        return false;
    }

    if (StringUtils.isBlank(outputColumn)) {
        log.info("Output column is required");
        return false;
    }

    if (StringUtils.isBlank(outputTable)) {
        log.info("Output table is required");
        return false;
    }
    return true;
}

From source file:org.jtalks.poulpe.model.dao.hibernate.UserHibernateDaoTest.java

@Test
public void returnsUsersFoundUsingCaseInsensitiveSearch() throws Exception {
    String username = english(USERNAME_MAX_LENGTH);
    String password = alphanumeric(PASSWORD_MAX_LENGTH);
    List<PoulpeUser> expectedUserList = Arrays.asList(saveAndEvictUser(username, password),
            saveAndEvictUser(username.toLowerCase(), password),
            saveAndEvictUser(StringUtils.capitalize(username.toLowerCase()), password),
            saveAndEvictUser(username.toUpperCase(), password));
    List<PoulpeUser> poulpeUsers = dao.findUsersByUsernameAndPasswordHash(username, password);
    assertEquals(poulpeUsers.size(), expectedUserList.size());
    assertTrue(poulpeUsers.containsAll(expectedUserList));
}

From source file:hudson.tasks.BuildTrigger.java

/**
 * Checks if this trigger has the exact same set of children as the given list.
 *//*  w  w  w.j a v a  2  s .c o m*/
public boolean hasSame(AbstractProject owner, Collection<? extends AbstractProject> projects) {
    List<AbstractProject> children = getChildProjects(owner);
    return children.size() == projects.size() && children.containsAll(projects);
}

From source file:org.apache.lens.ml.TableTestingSpec.java

/**
 * Validate./*from  w w  w .  j  a va  2s . co m*/
 *
 * @return true, if successful
 */
public boolean validate() {
    List<FieldSchema> columns;
    try {
        Hive metastoreClient = Hive.get(conf);
        Table tbl = (db == null) ? metastoreClient.getTable(inputTable)
                : metastoreClient.getTable(db, inputTable);
        columns = tbl.getAllCols();
        columnNameToFieldSchema = new HashMap<String, FieldSchema>();

        for (FieldSchema fieldSchema : columns) {
            columnNameToFieldSchema.put(fieldSchema.getName(), fieldSchema);
        }

        // Check if output table exists
        Table outTbl = metastoreClient.getTable(db == null ? "default" : db, outputTable, false);
        outputTableExists = (outTbl != null);
    } catch (HiveException exc) {
        LOG.error("Error getting table info " + toString(), exc);
        return false;
    }

    // Check if labeled column and feature columns are contained in the table
    List<String> testTableColumns = new ArrayList<String>(columns.size());
    for (FieldSchema column : columns) {
        testTableColumns.add(column.getName());
    }

    if (!testTableColumns.containsAll(featureColumns)) {
        LOG.info(
                "Invalid feature columns: " + featureColumns + ". Actual columns in table:" + testTableColumns);
        return false;
    }

    if (!testTableColumns.contains(labelColumn)) {
        LOG.info("Invalid label column: " + labelColumn + ". Actual columns in table:" + testTableColumns);
        return false;
    }

    if (StringUtils.isBlank(outputColumn)) {
        LOG.info("Output column is required");
        return false;
    }

    if (StringUtils.isBlank(outputTable)) {
        LOG.info("Output table is required");
        return false;
    }
    return true;
}

From source file:org.obiba.mica.study.service.HarmonizationStudyService.java

private List<String> populationsAffected(HarmonizationStudy study, HarmonizationStudy oldStudy) {
    if (oldStudy != null) {
        List<String> newPopIDs = study.getPopulations().stream().map(Population::getId).collect(toList());
        List<String> oldPopIDs = oldStudy.getPopulations().stream().map(Population::getId).collect(toList());

        boolean isChangeSignificant = newPopIDs.size() <= oldPopIDs.size() && !newPopIDs.containsAll(oldPopIDs);
        if (isChangeSignificant) {
            oldPopIDs.removeAll(newPopIDs);
            return oldPopIDs;
        } else//from  w  w  w .ja v  a2 s .  c om
            return null;
    } else
        return null;
}