Java Code Examples for org.gradle.util.CollectionUtils#filter()

The following examples show how to use org.gradle.util.CollectionUtils#filter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NamedElementSelector.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Return the matching elements: never returns an empty list (at this stage this class chooses the default).
 */
public List<T> transform(NamedDomainObjectContainer<? super T> ts) { //TODO freekh: consider changing to select
    NamedDomainObjectSet<T> allWithType = ts.withType(type);

    if (names.isEmpty()) {
        return Lists.newArrayList(allWithType);
    }

    List<T> matching = Lists.newArrayList();
    final List<String> notFound = Lists.newArrayList(names);
    CollectionUtils.filter(allWithType, matching, new Spec<T>() {
        public boolean isSatisfiedBy(T element) {
            return notFound.remove(element.getName());
        }
    });

    if (notFound.size() == 1) {
        throw new InvalidUserDataException(String.format("Invalid %s: %s", type.getSimpleName(), notFound.get(0)));
    } else if (notFound.size() > 1) {
        throw new InvalidUserDataException(String.format("Invalid %ss: %s", type.getSimpleName(), notFound));
    }
    return matching;
}
 
Example 2
Source File: DefaultOsgiManifest.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private Map<String, List<String>> getModelledInstructions() {
    Map<String, List<String>> modelledInstructions = new HashMap<String, List<String>>();
    modelledInstructions.put(Analyzer.BUNDLE_SYMBOLICNAME, createListFromPropertyString(symbolicName));
    modelledInstructions.put(Analyzer.BUNDLE_NAME, createListFromPropertyString(name));
    modelledInstructions.put(Analyzer.BUNDLE_VERSION, createListFromPropertyString(version));
    modelledInstructions.put(Analyzer.BUNDLE_DESCRIPTION, createListFromPropertyString(description));
    modelledInstructions.put(Analyzer.BUNDLE_LICENSE, createListFromPropertyString(description));
    modelledInstructions.put(Analyzer.BUNDLE_VENDOR, createListFromPropertyString(vendor));
    modelledInstructions.put(Analyzer.BUNDLE_DOCURL, createListFromPropertyString(docURL));

    return CollectionUtils.filter(modelledInstructions, new Spec<Map.Entry<String, List<String>>>() {
        public boolean isSatisfiedBy(Map.Entry<String, List<String>> element) {
            return element.getValue() != null;
        }
    });
}
 
Example 3
Source File: MethodModelRuleDescriptor.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static ModelRuleDescriptor of(Class<?> clazz, final String methodName) {
    List<Method> methodsOfName = CollectionUtils.filter(clazz.getDeclaredMethods(), new Spec<Method>() {
        public boolean isSatisfiedBy(Method element) {
            return element.getName().equals(methodName);
        }
    });

    if (methodsOfName.isEmpty()) {
        throw new IllegalStateException("Class " + clazz.getName() + " has no method named '" + methodName + "'");
    }

    if (methodsOfName.size() > 1) {
        throw new IllegalStateException("Class " + clazz.getName() + " has more than one method named '" + methodName + "'");
    }

    return new MethodModelRuleDescriptor(methodsOfName.get(0));
}
 
Example 4
Source File: NamedElementSelector.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Return the matching elements: never returns an empty list (at this stage this class chooses the default).
 */
public List<T> transform(NamedDomainObjectContainer<? super T> ts) { //TODO freekh: consider changing to select
    NamedDomainObjectSet<T> allWithType = ts.withType(type);

    if (names.isEmpty()) {
        return Lists.newArrayList(allWithType);
    }

    List<T> matching = Lists.newArrayList();
    final List<String> notFound = Lists.newArrayList(names);
    CollectionUtils.filter(allWithType, matching, new Spec<T>() {
        public boolean isSatisfiedBy(T element) {
            return notFound.remove(element.getName());
        }
    });

    if (notFound.size() == 1) {
        throw new InvalidUserDataException(String.format("Invalid %s: %s", type.getSimpleName(), notFound.get(0)));
    } else if (notFound.size() > 1) {
        throw new InvalidUserDataException(String.format("Invalid %ss: %s", type.getSimpleName(), notFound));
    }
    return matching;
}
 
Example 5
Source File: CollectionBuilderBasedRule.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private ImmutableList<ModelReference<?>> calculateInputs(List<ModelReference<?>> modelReferences) {
    final List<ModelReference<?>> references = this.ruleDefinition.getReferences().subList(1, this.ruleDefinition.getReferences().size());
    final List<ModelReference<?>> filteredReferences = CollectionUtils.filter(references, new Spec<ModelReference<?>>() {
        public boolean isSatisfiedBy(ModelReference<?> element) {
            if (element.getType().equals(ModelType.of(baseType))) {
                baseTypeParameterIndex = references.indexOf(element) + 1;
                return false;
            }
            return true;
        }
    });

    ImmutableList.Builder<ModelReference<?>> allInputs = ImmutableList.builder();
    allInputs.addAll(modelReferences);
    allInputs.addAll(filteredReferences);
    return allInputs.build();
}
 
Example 6
Source File: AbstractFileCollection.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public FileCollection filter(final Spec<? super File> filterSpec) {
    return new AbstractFileCollection() {
        @Override
        public String getDisplayName() {
            return AbstractFileCollection.this.getDisplayName();
        }

        @Override
        public TaskDependency getBuildDependencies() {
            return AbstractFileCollection.this.getBuildDependencies();
        }

        public Set<File> getFiles() {
            return CollectionUtils.filter(AbstractFileCollection.this, new LinkedHashSet<File>(), filterSpec);
        }
    };
}
 
Example 7
Source File: DefaultOsgiManifest.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private Map<String, List<String>> getModelledInstructions() {
    Map<String, List<String>> modelledInstructions = new HashMap<String, List<String>>();
    modelledInstructions.put(Analyzer.BUNDLE_SYMBOLICNAME, createListFromPropertyString(symbolicName));
    modelledInstructions.put(Analyzer.BUNDLE_NAME, createListFromPropertyString(name));
    modelledInstructions.put(Analyzer.BUNDLE_VERSION, createListFromPropertyString(version));
    modelledInstructions.put(Analyzer.BUNDLE_DESCRIPTION, createListFromPropertyString(description));
    modelledInstructions.put(Analyzer.BUNDLE_LICENSE, createListFromPropertyString(description));
    modelledInstructions.put(Analyzer.BUNDLE_VENDOR, createListFromPropertyString(vendor));
    modelledInstructions.put(Analyzer.BUNDLE_DOCURL, createListFromPropertyString(docURL));

    return CollectionUtils.filter(modelledInstructions, new Spec<Map.Entry<String, List<String>>>() {
        public boolean isSatisfiedBy(Map.Entry<String, List<String>> element) {
            return element.getValue() != null;
        }
    });
}
 
Example 8
Source File: AbstractFileCollection.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public FileCollection filter(final Spec<? super File> filterSpec) {
    return new AbstractFileCollection() {
        @Override
        public String getDisplayName() {
            return AbstractFileCollection.this.getDisplayName();
        }

        @Override
        public TaskDependency getBuildDependencies() {
            return AbstractFileCollection.this.getBuildDependencies();
        }

        public Set<File> getFiles() {
            return CollectionUtils.filter(AbstractFileCollection.this, new LinkedHashSet<File>(), filterSpec);
        }
    };
}
 
Example 9
Source File: DefaultOsgiManifest.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private Map<String, List<String>> getModelledInstructions() {
    Map<String, List<String>> modelledInstructions = new HashMap<String, List<String>>();
    modelledInstructions.put(Analyzer.BUNDLE_SYMBOLICNAME, createListFromPropertyString(symbolicName));
    modelledInstructions.put(Analyzer.BUNDLE_NAME, createListFromPropertyString(name));
    modelledInstructions.put(Analyzer.BUNDLE_VERSION, createListFromPropertyString(version));
    modelledInstructions.put(Analyzer.BUNDLE_DESCRIPTION, createListFromPropertyString(description));
    modelledInstructions.put(Analyzer.BUNDLE_LICENSE, createListFromPropertyString(description));
    modelledInstructions.put(Analyzer.BUNDLE_VENDOR, createListFromPropertyString(vendor));
    modelledInstructions.put(Analyzer.BUNDLE_DOCURL, createListFromPropertyString(docURL));

    return CollectionUtils.filter(modelledInstructions, new Spec<Map.Entry<String, List<String>>>() {
        public boolean isSatisfiedBy(Map.Entry<String, List<String>> element) {
            return element.getValue() != null;
        }
    });
}
 
Example 10
Source File: MethodModelRuleDescriptor.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static ModelRuleDescriptor of(Class<?> clazz, final String methodName) {
    List<Method> methodsOfName = CollectionUtils.filter(clazz.getDeclaredMethods(), new Spec<Method>() {
        public boolean isSatisfiedBy(Method element) {
            return element.getName().equals(methodName);
        }
    });

    if (methodsOfName.isEmpty()) {
        throw new IllegalStateException("Class " + clazz.getName() + " has no method named '" + methodName + "'");
    }

    if (methodsOfName.size() > 1) {
        throw new IllegalStateException("Class " + clazz.getName() + " has more than one method named '" + methodName + "'");
    }

    return new MethodModelRuleDescriptor(methodsOfName.get(0));
}
 
Example 11
Source File: CollectionBuilderBasedRule.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private ImmutableList<ModelReference<?>> calculateInputs(List<ModelReference<?>> modelReferences) {
    final List<ModelReference<?>> references = this.ruleDefinition.getReferences().subList(1, this.ruleDefinition.getReferences().size());
    final List<ModelReference<?>> filteredReferences = CollectionUtils.filter(references, new Spec<ModelReference<?>>() {
        public boolean isSatisfiedBy(ModelReference<?> element) {
            if (element.getType().equals(ModelType.of(baseType))) {
                baseTypeParameterIndex = references.indexOf(element) + 1;
                return false;
            }
            return true;
        }
    });

    ImmutableList.Builder<ModelReference<?>> allInputs = ImmutableList.builder();
    allInputs.addAll(modelReferences);
    allInputs.addAll(filteredReferences);
    return allInputs.build();
}
 
Example 12
Source File: SelfResolvingDependencyResolver.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
Set<File> getFiles(Spec<? super Dependency> dependencySpec) {
    Set<Dependency> selectedDependencies = CollectionUtils.filter(dependencies, dependencySpec);
    for (Dependency dependency : selectedDependencies) {
        resolveContext.add(dependency);
    }
    return resolveContext.resolve().getFiles();
}
 
Example 13
Source File: AbstractAntTaskBackedMavenPublisher.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private MavenArtifact determineMainArtifact(String publicationName, Set<MavenArtifact> mavenArtifacts) {
    Set<MavenArtifact> candidateMainArtifacts = CollectionUtils.filter(mavenArtifacts, new Spec<MavenArtifact>() {
        public boolean isSatisfiedBy(MavenArtifact element) {
            return element.getClassifier() == null || element.getClassifier().length() == 0;
        }
    });
    if (candidateMainArtifacts.isEmpty()) {
        return null;
    }
    if (candidateMainArtifacts.size() > 1) {
        throw new InvalidMavenPublicationException(publicationName, "Cannot determine main artifact - multiple artifacts found with empty classifier.");
    }
    return candidateMainArtifacts.iterator().next();
}
 
Example 14
Source File: NativeBinaryResolveResult.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public List<NativeBinaryRequirementResolveResult> getPendingResolutions() {
    return CollectionUtils.filter(resolutions, new Spec<NativeBinaryRequirementResolveResult>() {
        public boolean isSatisfiedBy(NativeBinaryRequirementResolveResult element) {
            return !element.isComplete();
        }
    });
}
 
Example 15
Source File: SelfResolvingDependencyResolver.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
Set<File> getFiles(Spec<? super Dependency> dependencySpec) {
    Set<Dependency> selectedDependencies = CollectionUtils.filter(dependencies, dependencySpec);
    for (Dependency dependency : selectedDependencies) {
        resolveContext.add(dependency);
    }
    return resolveContext.resolve().getFiles();
}
 
Example 16
Source File: SelfResolvingDependencyResolver.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
Set<File> getFiles(Spec<? super Dependency> dependencySpec) {
    Set<Dependency> selectedDependencies = CollectionUtils.filter(dependencies, dependencySpec);
    for (Dependency dependency : selectedDependencies) {
        resolveContext.add(dependency);
    }
    return resolveContext.resolve().getFiles();
}
 
Example 17
Source File: AvailableJavaHomes.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public List<JvmInstallation> findJvms() {
    List<JvmInstallation> jvms = new ArrayList<JvmInstallation>();
    if (OperatingSystem.current().isLinux()) {
        jvms = addJvm(jvms, JavaVersion.VERSION_1_5, "1.5.0", new File("/opt/jdk/sun-jdk-5"), true, JvmInstallation.Arch.i386);
        jvms = addJvm(jvms, JavaVersion.VERSION_1_6, "1.6.0", new File("/opt/jdk/sun-jdk-6"), true, JvmInstallation.Arch.x86_64);
        jvms = addJvm(jvms, JavaVersion.VERSION_1_6, "1.6.0", new File("/opt/jdk/ibm-jdk-6"), true, JvmInstallation.Arch.x86_64);
        jvms = addJvm(jvms, JavaVersion.VERSION_1_7, "1.7.0", new File("/opt/jdk/oracle-jdk-7"), true, JvmInstallation.Arch.x86_64);
        jvms = addJvm(jvms, JavaVersion.VERSION_1_8, "1.8.0", new File("/opt/jdk/oracle-jdk-8"), true, JvmInstallation.Arch.x86_64);
    }
    return CollectionUtils.filter(jvms, new Spec<JvmInstallation>() {
        public boolean isSatisfiedBy(JvmInstallation element) {
            return element.getJavaHome().isDirectory();
        }
    });
}
 
Example 18
Source File: AbstractAntTaskBackedMavenPublisher.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private MavenArtifact determineMainArtifact(String publicationName, Set<MavenArtifact> mavenArtifacts) {
    Set<MavenArtifact> candidateMainArtifacts = CollectionUtils.filter(mavenArtifacts, new Spec<MavenArtifact>() {
        public boolean isSatisfiedBy(MavenArtifact element) {
            return element.getClassifier() == null || element.getClassifier().length() == 0;
        }
    });
    if (candidateMainArtifacts.isEmpty()) {
        return null;
    }
    if (candidateMainArtifacts.size() > 1) {
        throw new InvalidMavenPublicationException(publicationName, "Cannot determine main artifact - multiple artifacts found with empty classifier.");
    }
    return candidateMainArtifacts.iterator().next();
}
 
Example 19
Source File: SelfResolvingDependencyResolver.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
Set<File> getFiles(Spec<? super Dependency> dependencySpec) {
    Set<Dependency> selectedDependencies = CollectionUtils.filter(dependencies, dependencySpec);
    for (Dependency dependency : selectedDependencies) {
        resolveContext.add(dependency);
    }
    return resolveContext.resolve().getFiles();
}
 
Example 20
Source File: AvailableJavaHomes.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public List<JvmInstallation> findJvms() {
    List<JvmInstallation> jvms = new ArrayList<JvmInstallation>();
    if (OperatingSystem.current().isLinux()) {
        jvms = addJvm(jvms, JavaVersion.VERSION_1_5, "1.5.0", new File("/opt/jdk/sun-jdk-5"), true, JvmInstallation.Arch.i386);
        jvms = addJvm(jvms, JavaVersion.VERSION_1_6, "1.6.0", new File("/opt/jdk/sun-jdk-6"), true, JvmInstallation.Arch.x86_64);
        jvms = addJvm(jvms, JavaVersion.VERSION_1_6, "1.6.0", new File("/opt/jdk/ibm-jdk-6"), true, JvmInstallation.Arch.x86_64);
        jvms = addJvm(jvms, JavaVersion.VERSION_1_7, "1.7.0", new File("/opt/jdk/oracle-jdk-7"), true, JvmInstallation.Arch.x86_64);
        jvms = addJvm(jvms, JavaVersion.VERSION_1_8, "1.8.0", new File("/opt/jdk/oracle-jdk-8"), true, JvmInstallation.Arch.x86_64);
    }
    return CollectionUtils.filter(jvms, new Spec<JvmInstallation>() {
        public boolean isSatisfiedBy(JvmInstallation element) {
            return element.getJavaHome().isDirectory();
        }
    });
}