/** * Sort the contained elements. * @return a Collection of Resources. */ @Override protected synchronized Collection<Resource> getCollection() { return getResourceCollection().stream().map(Resource.class::cast) .sorted(comp).collect(Collectors.toList()); }
private Stream<File> directories(ResourceCollection rc) { return rc.stream().map(r -> r.as(FileProvider.class)) .filter(Objects::nonNull).map(FileProvider::getFile) .filter(File::isDirectory); } }
/** * Take the first <code>count</code> elements. * @return a Collection of Resources. */ @Override protected Collection<Resource> getCollection() { return getResourceCollection().stream().limit(getValidCount()) .collect(Collectors.toList()); }
/** * Take all elements except for the first <code>count</code> elements. * @return a Collection of Resources. */ @Override protected Collection<Resource> getCollection() { return getResourceCollection().stream().skip(getValidCount()) .collect(Collectors.toList()); }
/** * Calculate the intersection of the nested ResourceCollections. * @return a Collection of Resources. */ @Override protected Collection<Resource> getCollection() { List<ResourceCollection> rcs = getResourceCollections(); int size = rcs.size(); if (size < 2) { throw new BuildException( "The intersection of %d resource %s is undefined.", size, size == 1 ? "collection" : "collections"); } final Function<ResourceCollection, Set<Resource>> toSet = c -> c.stream().collect(Collectors.toSet()); Iterator<ResourceCollection> rc = rcs.iterator(); Set<Resource> s = new LinkedHashSet<>(toSet.apply(rc.next())); rc.forEachRemaining(c -> s.retainAll(toSet.apply(c))); return s; }
private boolean isUpToDate(ResourceCollection c) { return dest != null && !forceOverwrite && c.stream().noneMatch(r -> SelectorUtils.isOutOfDate(r, dest, FILE_UTILS.getFileTimestampGranularity())); }
private Collection<Resource> getCollection() { FileNameMapper m = mapper == null ? new IdentityMapper() : mapper.getImplementation(); Stream<MappedResource> stream; if (enableMultipleMappings) { stream = nested.stream() .flatMap(r -> Stream.of(m.mapFileName(r.getName())) .filter(Objects::nonNull) .map(MergingMapper::new) .map(mm -> new MappedResource(r, mm))); } else { stream = nested.stream().map(r -> new MappedResource(r, m)); } return stream.collect(Collectors.toList()); }
/** * Take all elements except for the last <code>count</code> elements. * @return a Collection of Resources. */ @Override protected Collection<Resource> getCollection() { int ct = getValidCount(); ResourceCollection nested = getResourceCollection(); if (ct > nested.size()) { return Collections.emptyList(); } return nested.stream().limit((long) nested.size() - ct) .collect(Collectors.toList()); }
/** * Take the last <code>count</code> elements. * @return a Collection of Resources. */ @Override protected Collection<Resource> getCollection() { int count = getValidCount(); ResourceCollection rc = getResourceCollection(); int size = rc.size(); int skip = Math.max(0, size - count); List<Resource> result = rc.stream().skip(skip).collect(Collectors.toList()); int found = result.size(); if (found == count || (size < count && found == size)) { return result; } //mismatch: String msg = String.format( "Resource collection %s reports size %d but returns %d elements.", rc, size, found + skip); //size was understated -> too many results; warn and continue: if (found > count) { log(msg, Project.MSG_WARN); return result.subList(found - count, found); } //size was overstated; we missed some and are now in error-land: throw new BuildException(msg); }