Example usage for org.apache.commons.collections Predicate Predicate

List of usage examples for org.apache.commons.collections Predicate Predicate

Introduction

In this page you can find the example usage for org.apache.commons.collections Predicate Predicate.

Prototype

Predicate

Source Link

Usage

From source file:org.andromda.maven.plugin.bootstrap.install.BootstrapInstallMojo.java

/**
 * Clears the POM's model of its parent or any dependencies
 * it may have so that we can write a POM that isn't dependent on anything
 * (which we need for bootstrap artifacts).
 *
 * @param bootstrapPomFile the bootstrap POM file to write.
 *///  w w w .j av a2  s  .c  o  m
private void writeMinimalPom(final File bootstrapPomFile) throws IOException {
    final Model model = this.project.getModel();

    final MavenProject minimalProject = new MavenProject();
    final Model minModel = minimalProject.getModel();

    minModel.setGroupId(getBootstrapGroupId(this.project.getArtifact()));
    minModel.setArtifactId(model.getArtifactId());
    minModel.setVersion(model.getVersion());
    minModel.setName(model.getName());
    minModel.setPackaging("jar");
    minModel.setDescription(model.getDescription());
    minModel.setModelEncoding(model.getModelEncoding());
    minModel.setModelVersion(model.getModelVersion());
    minModel.setUrl(model.getUrl());
    minModel.setScm(model.getScm());
    minModel.setDevelopers(model.getDevelopers());
    minModel.setCiManagement(model.getCiManagement());
    minModel.setIssueManagement(model.getIssueManagement());

    minModel.setPrerequisites(model.getPrerequisites());
    minModel.setOrganization(model.getOrganization());
    minModel.setInceptionYear(model.getInceptionYear());
    minModel.setLicenses(model.getLicenses());

    final List<Dependency> dependencies = new ArrayList<Dependency>(model.getDependencies());
    // filter all of andromda dependencies away
    CollectionUtils.filter(dependencies, new Predicate() {
        public boolean evaluate(Object object) {
            Dependency dependency = (Dependency) object;
            final String lGroupId = dependency.getGroupId();
            return !lGroupId.startsWith("org.andromda") || lGroupId.startsWith("org.andromda.thirdparty");
        }
    });
    minModel.setDependencies(dependencies);

    final FileWriter fileWriter = new FileWriter(bootstrapPomFile);
    minimalProject.writeModel(fileWriter);
    fileWriter.flush();
}

From source file:org.apache.ambari.server.controller.ganglia.GangliaPropertyProviderTest.java

private boolean isUrlParamsEquals(URIBuilder actualUri, URIBuilder expectedUri) {
    for (final NameValuePair expectedParam : expectedUri.getQueryParams()) {
        NameValuePair actualParam = (NameValuePair) CollectionUtils.find(actualUri.getQueryParams(),
                new Predicate() {

                    @Override/* w  ww .  ja  v  a2s  . c o m*/
                    public boolean evaluate(Object arg0) {
                        if (!(arg0 instanceof NameValuePair))
                            return false;

                        NameValuePair otherObj = (NameValuePair) arg0;
                        return otherObj.getName().equals(expectedParam.getName());
                    }
                });

        List<String> actualParamList = new ArrayList<String>(Arrays.asList(actualParam.getValue().split(",")));
        List<String> expectedParamList = new ArrayList<String>(
                Arrays.asList(expectedParam.getValue().split(",")));

        Collections.sort(actualParamList);
        Collections.sort(expectedParamList);

        if (!actualParamList.equals(expectedParamList))
            return false;
    }

    return true;
}

From source file:org.apache.ambari.server.controller.RootServiceResponseFactory.java

@Override
public Set<RootServiceHostComponentResponse> getRootServiceHostComponent(
        RootServiceHostComponentRequest request, Set<HostResponse> hosts) throws AmbariException {
    Set<RootServiceHostComponentResponse> response = new HashSet<RootServiceHostComponentResponse>();

    Set<RootServiceComponentResponse> rootServiceComponents = getRootServiceComponents(
            new RootServiceComponentRequest(request.getServiceName(), request.getComponentName()));

    //Cartesian product with hosts and components
    for (RootServiceComponentResponse component : rootServiceComponents) {

        Set<HostResponse> filteredHosts = new HashSet<HostResponse>(hosts);

        //Make some filtering of hosts if need
        if (component.getComponentName().equals(Components.AMBARI_SERVER.name()))
            CollectionUtils.filter(filteredHosts, new Predicate() {
                @Override//  w  w  w  .j  a v a2 s. c  o  m
                public boolean evaluate(Object arg0) {
                    HostResponse hostResponse = (HostResponse) arg0;
                    return hostResponse.getHostname().equals(StageUtils.getHostName());
                }
            });

        for (HostResponse host : filteredHosts) {

            if (component.getComponentName().equals(Components.AMBARI_SERVER.name()))
                response.add(new RootServiceHostComponentResponse(host.getHostname(),
                        component.getComponentName(), RUNNING_STATE,
                        getComponentVersion(component.getComponentName(), host), component.getProperties()));
            else
                response.add(new RootServiceHostComponentResponse(host.getHostname(),
                        component.getComponentName(), host.getHostState(),
                        getComponentVersion(component.getComponentName(), host), component.getProperties()));
        }
    }

    return response;
}

From source file:org.apache.ambari.server.orm.dao.ConfigGroupHostMappingDAO.java

@RequiresSession
public Set<ConfigGroupHostMapping> findByGroup(final Long groupId) {

    populateCache();//from   w  ww.  java  2  s.  co  m

    Set<ConfigGroupHostMapping> result = new HashSet<ConfigGroupHostMapping>();

    for (Set<ConfigGroupHostMapping> item : configGroupHostMappingByHost.values()) {

        Set<ConfigGroupHostMapping> setByHost = new HashSet<ConfigGroupHostMapping>(item);

        CollectionUtils.filter(setByHost, new Predicate() {

            @Override
            public boolean evaluate(Object arg0) {
                return ((ConfigGroupHostMapping) arg0).getConfigGroupId().equals(groupId);
            }
        });

        result.addAll(setByHost);

    }

    return result;

}

From source file:org.apache.ambari.server.orm.dao.ConfigGroupHostMappingDAO.java

@Transactional
public void remove(final ConfigGroupHostMappingEntity configGroupHostMappingEntity) {

    populateCache();/*from  ww w  . ja v a  2 s  .  com*/

    entityManagerProvider.get().remove(merge(configGroupHostMappingEntity));

    Set<ConfigGroupHostMapping> setByHost = configGroupHostMappingByHost
            .get(configGroupHostMappingEntity.getHostname());

    if (setByHost != null) {
        CollectionUtils.filter(setByHost, new Predicate() {

            @Override
            public boolean evaluate(Object arg0) {
                return !((ConfigGroupHostMapping) arg0).getConfigGroupId()
                        .equals(configGroupHostMappingEntity.getConfigGroupId());
            }
        });
    }
}

From source file:org.apache.ambari.server.orm.dao.ConfigGroupHostMappingDAO.java

@Transactional
public void removeByPK(final ConfigGroupHostMappingEntityPK configGroupHostMappingEntityPK) {
    populateCache();/*  ww  w.  j av  a  2s . c om*/

    entityManagerProvider.get().remove(findByPK(configGroupHostMappingEntityPK));

    Set<ConfigGroupHostMapping> setByHost = configGroupHostMappingByHost
            .get(configGroupHostMappingEntityPK.getHostname());

    if (setByHost != null) {
        CollectionUtils.filter(setByHost, new Predicate() {

            @Override
            public boolean evaluate(Object arg0) {
                return !((ConfigGroupHostMapping) arg0).getConfigGroupId()
                        .equals(configGroupHostMappingEntityPK.getConfigGroupId());
            }
        });
    }

}

From source file:org.apache.ambari.server.orm.dao.ConfigGroupHostMappingDAO.java

@Transactional
public void removeAllByGroup(final Long groupId) {
    populateCache();// www. j ava2s.  c  om

    TypedQuery<Long> query = entityManagerProvider.get().createQuery(
            "DELETE FROM ConfigGroupHostMappingEntity confighosts WHERE " + "confighosts.configGroupId = ?1",
            Long.class);

    daoUtils.executeUpdate(query, groupId);
    // Flush to current transaction required in order to avoid Eclipse link
    // from re-ordering delete
    entityManagerProvider.get().flush();

    for (Set<ConfigGroupHostMapping> setByHost : configGroupHostMappingByHost.values()) {

        CollectionUtils.filter(setByHost, new Predicate() {

            @Override
            public boolean evaluate(Object arg0) {
                return !((ConfigGroupHostMapping) arg0).getConfigGroupId().equals(groupId);
            }
        });
    }

}

From source file:org.apache.ambari.server.orm.dao.HostConfigMappingDAO.java

@RequiresSession
public Set<HostConfigMapping> findByType(final long clusterId, String hostName, final String type) {

    populateCache();/*from  ww w .  j a  v  a  2  s.co m*/

    if (!hostConfigMappingByHost.containsKey(hostName))
        return Collections.emptySet();

    Set<HostConfigMapping> set = new HashSet<HostConfigMapping>(hostConfigMappingByHost.get(hostName));

    CollectionUtils.filter(set, new Predicate() {

        @Override
        public boolean evaluate(Object arg0) {

            return ((HostConfigMapping) arg0).getClusterId().equals(clusterId)
                    && ((HostConfigMapping) arg0).getType().equals(type);
        }
    });

    return set;
}

From source file:org.apache.ambari.server.orm.dao.HostConfigMappingDAO.java

@RequiresSession
public HostConfigMapping findSelectedByType(final long clusterId, String hostName, final String type) {

    populateCache();//  ww w . j a v a  2s. c om

    if (!hostConfigMappingByHost.containsKey(hostName))
        return null;

    Set<HostConfigMapping> set = new HashSet<HostConfigMapping>(hostConfigMappingByHost.get(hostName));

    HostConfigMapping result = (HostConfigMapping) CollectionUtils.find(set, new Predicate() {

        @Override
        public boolean evaluate(Object arg0) {

            return ((HostConfigMapping) arg0).getClusterId().equals(clusterId)
                    && ((HostConfigMapping) arg0).getType().equals(type)
                    && ((HostConfigMapping) arg0).getSelected() > 0;
        }
    });

    return result;

}

From source file:org.apache.ambari.server.orm.dao.HostConfigMappingDAO.java

@RequiresSession
public Set<HostConfigMapping> findSelected(final long clusterId, String hostName) {

    populateCache();/* ww w .  j a va  2  s .co  m*/

    if (!hostConfigMappingByHost.containsKey(hostName))
        return Collections.emptySet();

    Set<HostConfigMapping> set = new HashSet<HostConfigMapping>(hostConfigMappingByHost.get(hostName));

    CollectionUtils.filter(set, new Predicate() {

        @Override
        public boolean evaluate(Object arg0) {
            return ((HostConfigMapping) arg0).getClusterId().equals(clusterId)
                    && ((HostConfigMapping) arg0).getSelected() > 0;
        }
    });

    return set;
}