Example usage for java.util List contains

List of usage examples for java.util List contains

Introduction

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

Prototype

boolean contains(Object o);

Source Link

Document

Returns true if this list contains the specified element.

Usage

From source file:com.redhat.rhtracking.persistance.services.Queries.java

public static <T extends Catalog, K extends Serializable> void initCatalog(List<String> catalogue,
        CrudRepository<T, K> repository, Class<T> type) {
    logger.info("Starting " + type.getSimpleName() + " catalog");
    Iterable<T> typeItr = repository.findAll();
    for (T t : typeItr) {
        if (catalogue.contains(t.toString())) {
            catalogue.remove(t.toString());
        }/*from w w  w  .ja v  a 2  s.  c  o m*/
    }
    if (!catalogue.isEmpty()) {
        try {
            for (String s : catalogue) {
                T missing = type.newInstance();
                missing.setType(s);
                repository.save(missing);
            }
        } catch (IllegalAccessException | InstantiationException ex) {
            logger.error(ex);
        }
    }
}

From source file:alfio.util.Validator.java

private static void validateRestrictedValue(String value, String fieldName, String errorCode,
        List<String> restrictedValues, Errors errors) {
    if (StringUtils.isNotBlank(value) && !restrictedValues.contains(value)) {
        errors.rejectValue(fieldName, errorCode);
    }/*from  www .j a va 2  s  .  c o m*/
}

From source file:AmazonKinesisFirehoseToRedshiftSample.java

/**
 * Method to create delivery stream with Redshift destination configuration.
 *
 * @throws Exception/*  ww w .java2 s.  c  o  m*/
 */
private static void createDeliveryStream() throws Exception {

    boolean deliveryStreamExists = false;

    LOG.info("Checking if " + deliveryStreamName + " already exits");
    List<String> deliveryStreamNames = listDeliveryStreams();
    if (deliveryStreamNames != null && deliveryStreamNames.contains(deliveryStreamName)) {
        deliveryStreamExists = true;
        LOG.info("DeliveryStream " + deliveryStreamName
                + " already exists. Not creating the new delivery stream");
    } else {
        LOG.info("DeliveryStream " + deliveryStreamName + " does not exist");
    }

    if (!deliveryStreamExists) {
        // Create DeliveryStream
        CreateDeliveryStreamRequest createDeliveryStreamRequest = new CreateDeliveryStreamRequest();
        createDeliveryStreamRequest.setDeliveryStreamName(deliveryStreamName);

        S3DestinationConfiguration redshiftS3Configuration = new S3DestinationConfiguration();
        redshiftS3Configuration.setBucketARN(s3BucketARN);
        redshiftS3Configuration.setPrefix(s3ObjectPrefix);

        BufferingHints bufferingHints = null;
        if (s3DestinationSizeInMBs != null || s3DestinationIntervalInSeconds != null) {
            bufferingHints = new BufferingHints();
            bufferingHints.setSizeInMBs(s3DestinationSizeInMBs);
            bufferingHints.setIntervalInSeconds(s3DestinationIntervalInSeconds);
        }
        redshiftS3Configuration.setBufferingHints(bufferingHints);

        // Create and set IAM role so that firehose service has access to the S3Buckets to put data. 
        // Please check the trustPolicyDocument.json and permissionsPolicyDocument.json files 
        // for the trust and permissions policies set for the role.
        String iamRoleArn = createIamRole(s3ObjectPrefix);
        redshiftS3Configuration.setRoleARN(iamRoleArn);

        CopyCommand copyCommand = new CopyCommand();
        copyCommand.withCopyOptions(copyOptions).withDataTableName(dataTableName);

        RedshiftDestinationConfiguration redshiftDestinationConfiguration = new RedshiftDestinationConfiguration();
        redshiftDestinationConfiguration.withClusterJDBCURL(clusterJDBCUrl).withRoleARN(iamRoleArn)
                .withUsername(username).withPassword(password).withCopyCommand(copyCommand)
                .withS3Configuration(redshiftS3Configuration);

        createDeliveryStreamRequest.setRedshiftDestinationConfiguration(redshiftDestinationConfiguration);

        firehoseClient.createDeliveryStream(createDeliveryStreamRequest);

        // The Delivery Stream is now being created.
        LOG.info("Creating DeliveryStream : " + deliveryStreamName);
        waitForDeliveryStreamToBecomeAvailable(deliveryStreamName);
    }
}

From source file:gr.abiss.calipso.util.UserUtils.java

public static List<User> filterUsersAbleToTransitionFrom(List<UserSpaceRole> userSpaceRoles, Space space,
        int state, boolean uniqueUsers) {
    Set<String> set = space.getMetadata().getRolesAbleToTransitionFrom(state);
    List<User> list = new ArrayList<User>(userSpaceRoles.size());
    for (UserSpaceRole userSpaceRole : userSpaceRoles) {
        if (set.contains(userSpaceRole.getSpaceRole().getRoleCode())) {
            if (!list.contains(userSpaceRole.getUser())) {//must use unique users so check if a user is in the list
                list.add(userSpaceRole.getUser());
            }//w w  w . j a  va 2  s . co  m
        }
    }
    return list;
}

From source file:Main.java

public static void removeListPrefItems(ListPreference listPref, String[] labels, String[] values,
        List<String> items) {

    List<String> labelsList = new ArrayList<String>(Arrays.asList(labels));
    List<String> valuesList = new ArrayList<String>(Arrays.asList(values));

    Iterator<String> it = valuesList.iterator();
    while (it.hasNext()) {
        String value = it.next();
        if (items.contains(value)) {
            labelsList.remove(valuesList.indexOf(value));
            it.remove();/*from  w w w .j  a  v  a2s  . co  m*/
        }
    }

    listPref.setEntries(labelsList.toArray(new String[1]));
    listPref.setEntryValues(valuesList.toArray(new String[1]));

}

From source file:org.imsglobal.lti.LTIUtil.java

public static Map<String, List<String>> setParameter(Map<String, List<String>> parameters, String name,
        String value) {// w  w w  .  j  ava  2s.c  o m
    if (parameters.containsKey(name)) {
        List<String> itemList = parameters.get(name);
        if (itemList.contains(value)) {
            //no-op
        } else {
            itemList.add(value);
            parameters.put(name, itemList);
        }
    } else {
        List<String> itemList = new ArrayList<String>();
        itemList.add(value);
        parameters.put(name, itemList);
    }
    return parameters;
}

From source file:org.samlsample.control.SecUtils.java

/**
 * Is the supplied permission in the wicket session cache?  Called by buttons.
 * if not found, button will be invisible.
 *
 * @param permission fortress perm requires {link @Permission#objName} and {link @Permission#opName} are set.
 * @param component needed to get handle on the wicket session object.
 * @return true if found, false otherwise
 *//*ww  w .j a  v  a2s  .co  m*/
static boolean isFound(Permission permission, Component component) {
    List<Permission> permissions = SecUtils.getPermissions(component);
    return CollectionUtils.isNotEmpty(permissions) && permissions.contains(permission);
}

From source file:Main.java

public static String[] getTrailers(Cursor data) {
    List<String> lista = new ArrayList<String>();
    lista.add("Select Trailer");

    data.moveToFirst();// w  w  w  .jav a2 s . c o  m
    if (!data.getString(COL_TRAILER_KEY).equalsIgnoreCase("No Trailer Available")) {
        //loop through cursor to get all trailers
        for (int i = 1; i < data.getCount() + 1; i++) {
            if (!lista.contains(data.getString(COL_TRAILER_KEY))) {
                lista.add(data.getString(COL_TRAILER_KEY));
                data.moveToNext();
            } else {
                data.moveToNext();
            }
        }
    }

    String[] ltrailer;
    if (lista.size() < 1) {
        ltrailer = new String[1];
        ltrailer[0] = "No Trailer Available";
    } else {
        ltrailer = lista.toArray(new String[lista.size()]);
    }

    return ltrailer;
}

From source file:com.doculibre.constellio.plugins.PluginFactory.java

private static void initPluginManager() {
    if (pm == null) {
        pm = PluginManagerFactory.createPluginManager();
        File classesDir = ClasspathUtils.getClassesDir();

        pm.addPluginsFrom(classesDir.toURI());

        File pluginsDir = getPluginsDir();
        File[] pluginDirs = pluginsDir.listFiles(new FileFilter() {
            @Override//from ww  w . j a v  a2 s .  c  o m
            public boolean accept(File pathname) {
                boolean accept;
                if (pathname.isFile()) {
                    accept = false;
                } else if (DefaultConstellioPlugin.NAME.equals(pathname)) {
                    accept = true;
                } else {
                    List<String> availablePluginNames = ConstellioSpringUtils.getAvailablePluginNames();
                    accept = availablePluginNames.contains(pathname.getName());
                }
                return accept;
            }
        });
        if (pluginDirs == null) {
            return;
        }
        for (File pluginDir : pluginDirs) {
            // Plugin root dir jars
            Collection<File> pluginJarFiles = FileUtils.listFiles(pluginDir, new String[] { "jar" }, false);
            // Accept only one root dir jar
            File pluginJarFile = pluginJarFiles.isEmpty() ? null : pluginJarFiles.iterator().next();
            if (pluginJarFile != null) {
                URI pluginJarFileURI = pluginJarFile.toURI();
                pm.addPluginsFrom(pluginJarFileURI);

                PluginManagerImpl pmImpl = (PluginManagerImpl) pm;
                ClassPathManager classPathManager = pmImpl.getClassPathManager();
                ClassLoader classLoader = ClassPathManagerUtils.getClassLoader(classPathManager, pluginJarFile);
                classLoaders.add(classLoader);

                File pluginLibDir = new File(pluginDir, "lib");
                if (pluginLibDir.exists() && pluginLibDir.isDirectory()) {
                    Collection<File> pluginDependencies = FileUtils.listFiles(pluginLibDir,
                            new String[] { "jar" }, false);
                    ClassPathManagerUtils.addJarDependencies(classPathManager, pluginJarFile,
                            pluginDependencies);
                }
            }
        }

        File webInfDir = ClasspathUtils.getWebinfDir();
        File libDir = new File(webInfDir, "lib");
        File[] contellioJarFiles = libDir.listFiles(new FileFilter() {
            @Override
            public boolean accept(File pathname) {
                boolean accept;
                if (pathname.isDirectory()) {
                    accept = false;
                } else {
                    List<String> availablePluginNames = ConstellioSpringUtils.getAvailablePluginNames();
                    String jarNameWoutExtension = FilenameUtils.removeExtension(pathname.getName());
                    accept = availablePluginNames.contains(jarNameWoutExtension);
                }
                return accept;
            }
        });
        for (File constellioJarFile : contellioJarFiles) {
            URI constellioJarFileURI = constellioJarFile.toURI();
            pm.addPluginsFrom(constellioJarFileURI);
        }
    }
}

From source file:com.asual.summer.core.util.ResourceUtils.java

@SuppressWarnings("unchecked")
private static <T> List<T> getResources(Class<T> clazz) {

    String[] names = BeanUtils.getBeanNames(clazz);

    if (names != null) {
        List<T> resources = new ArrayList<T>();
        for (String name : names) {
            T bean = (T) BeanUtils.getBean(name);
            if (!resources.contains(bean)) {
                resources.add(bean);/*from  ww w  .j  a  va  2 s.c o  m*/
            }
        }
        OrderComparator.sort(resources);
        return resources;
    }

    return null;
}