Example usage for com.google.common.collect Sets filter

List of usage examples for com.google.common.collect Sets filter

Introduction

In this page you can find the example usage for com.google.common.collect Sets filter.

Prototype

@GwtIncompatible("NavigableSet")
@SuppressWarnings("unchecked")
@CheckReturnValue
public static <E> NavigableSet<E> filter(NavigableSet<E> unfiltered, Predicate<? super E> predicate) 

Source Link

Document

Returns the elements of a NavigableSet , unfiltered , that satisfy a predicate.

Usage

From source file:org.eclipse.sirius.diagram.ui.tools.internal.layout.PinnedElementsHandler.java

/**
 * Move the specified movable parts in the specified direction enough to
 * avoid overlaps with all the specified fixed parts while not creating any
 * new overlap with other fixed parts. All the movable parts are translated
 * of the same amount, as a group. More movable parts than the ones
 * specified explicitly may be move along as they are "pushed" aside to make
 * enough room./* ww w .jav  a 2s .c om*/
 * 
 * @param parts
 *            the parts to move.
 * @param fixedParts
 *            the fixed parts to avoid.
 * @param dir
 *            the general direction in which to move the movable parts.
 * @param previousMovedPositionsOfSameDir
 *            the list of original position of each edit parts that have
 *            previously moved in this direction
 * @return The positions done during this step (and previous steps) to
 *         eventually used it to restore the previous position.
 */
private Map<IGraphicalEditPart, Point> moveAside(final Set<IGraphicalEditPart> parts,
        final Set<IGraphicalEditPart> fixedParts, final Direction dir,
        Map<IGraphicalEditPart, Point> previousMovedPositionsOfSameDir) {
    /*
     * First try to move just enough to avoid the explicitly specified
     * obstacles.
     */
    addSavePositions(parts, previousMovedPositionsOfSameDir);
    tryMove(parts, fixedParts, dir);
    final Set<IGraphicalEditPart> overlaps = findOverlappingParts(parts);
    if (!overlaps.isEmpty()) {
        /*
         * We created new overlaps. Try a more aggressive change, taking
         * more parts into consideration and/or moving further.
         */
        Set<IGraphicalEditPart> newMovables = parts;
        Set<IGraphicalEditPart> newFixed = fixedParts;

        final Set<IGraphicalEditPart> movableOverlaps = Sets
                .newHashSet(Collections2.filter(overlaps, Predicates.not(isPinned)));
        if (!movableOverlaps.isEmpty()) {
            /*
             * If we created new overlaps with movable parts, simply re-try
             * with an extended set of movable parts including the ones we
             * need to push along.
             */
            newMovables = Sets.union(parts, movableOverlaps);
        }

        final Set<IGraphicalEditPart> fixedOverlaps = Sets.newHashSet(Collections2.filter(overlaps, isPinned));
        if (!fixedOverlaps.isEmpty()) {
            /*
             * If we created new overlaps with other fixed parts, re-try
             * with an extended set of fixed obstacles to avoid.
             */
            newFixed = Sets.union(fixedParts, fixedOverlaps);
        }

        /*
         * Retry with the new, extended sets of parts to consider.
         */
        assert newMovables.size() > parts.size() || newFixed.size() > fixedParts.size();
        moveParts(newMovables, previousMovedPositionsOfSameDir);
        moveAside(newMovables, newFixed, dir, previousMovedPositionsOfSameDir);
    }
    /*
     * Check that the specified movable parts no longer overlap with the
     * specified fixed parts.
     */
    assert Sets.intersection(Sets.filter(findOverlappingParts(fixedParts), Predicates.not(isPinned)), parts)
            .isEmpty();
    return previousMovedPositionsOfSameDir;
}

From source file:com.github.richardwilly98.esdms.services.DocumentProvider.java

public void deleteVersion(Document document, Version version) throws ServiceException {
    if (log.isTraceEnabled()) {
        log.trace(String.format("*** deleteVersion document: %s - version: %s ***", document, version));
    }/*from  w  ww  .j  a v a 2 s.  c  o  m*/
    checkNotNull(document);
    checkNotNull(version);
    if (document.getVersions().size() == 1) {
        throw new ServiceException("Cannot delete the last version of a document. Use DocumentService.delete");
    }
    SimpleDocument sd = getSimpleDocument(document);
    SimpleVersion sv;
    if (!version.isCurrent()) {
        versionService.delete(version);
    } else {
        if (version.getParentId() > 0) {
            String id = document.getVersion(version.getParentId()).getId();
            if (id != null) {
                Version lastVersion = versionService.get(id);
                sv = getSimpleVersion(lastVersion);
                sv.setCurrent(true);
                sv.setId(null);
                sd.updateVersion(sv);
                versionService.delete(lastVersion);
            }
        } else {
            throw new ServiceException(
                    String.format("Version %s is current but does not have parent", version));
        }
    }

    // Change parent of version where parent is the deleted version
    int parentId = version.getParentId();
    final int versionId = version.getVersionId();
    Set<Version> filteredVersions = Sets.filter(document.getVersions(), new Predicate<Version>() {
        @Override
        public boolean apply(Version version) {
            return (version.getParentId() == versionId);
        }
    });

    for (Version v : filteredVersions.toArray(new Version[0])) {
        sv = getSimpleVersion(v);
        sv.setParentId(parentId);
        sd.updateVersion(sv);
    }

    sd.deleteVersion(version);
    // updateVersions(sd);
    update(sd);
}

From source file:net.sourceforge.ganttproject.chart.ChartModelBase.java

private Set<Task> getMilestones() {
    return myTimelineMilestonesOption.getValue()
            ? Sets.filter(Sets.newHashSet(getTaskManager().getTasks()), MILESTONE_PREDICATE)
            : Collections.<Task>emptySet();
}

From source file:gov.nih.nci.firebird.data.InvestigatorProfile.java

/**
 * @return annual registrations awaiting renewal.
 *//*from  w w w  .j  a  va 2 s .  c o m*/
@Transient
public Set<AnnualRegistration> getAnnualRegistrationsAwaitingRenewal() {
    return Sets.filter(getAnnualRegistrations(), new Predicate<AnnualRegistration>() {
        @Override
        public boolean apply(AnnualRegistration registration) {
            return registration.isPendingRenewal();
        }
    });
}

From source file:org.eclipse.sirius.diagram.ui.tools.internal.layout.PinnedElementsHandler.java

/**
 * Translate all the given <code>parts</code> of the same amount in the
 * specified <code>direction</code> as far as required to avoid overlaps
 * with the specified <code>fixedParts</code>. The move may create new
 * overlaps with parts other than those in <code>fixedParts</code>.
 *///from   w w  w.j av a  2s  .  c  om
private void tryMove(final Set<IGraphicalEditPart> parts, final Set<IGraphicalEditPart> fixedParts,
        final Direction direction) {
    assert !Sets.intersection(Sets.filter(findOverlappingParts(fixedParts), Predicates.not(isPinned)), parts)
            .isEmpty();
    final Rectangle movablesBox = getBoundingBox(parts, EXCLUDE_PADDING);
    final Insets movablesPadding = getPadding(parts);
    final Rectangle fixedBox = getBoundingBox(fixedParts, EXCLUDE_PADDING);
    final Insets fixedPadding = getPadding(fixedParts);
    final Dimension move = computeMoveVector(movablesBox, movablesPadding, fixedBox, fixedPadding, direction);
    for (IGraphicalEditPart part : parts) {
        translate(part, move);
    }
    assert Sets.intersection(Sets.filter(findOverlappingParts(fixedParts), Predicates.not(isPinned)), parts)
            .isEmpty();
}

From source file:org.icgc.dcc.portal.resource.core.DownloadResource.java

@ApiOperation("Get archive based by type subject to the supplied filter condition(s)")
@GET/*from ww w  .jav  a 2s .c o m*/
@Timed
@Path("/{downloadId}/{dataType}")
public Response getIndividualTypeArchive(

        @Auth(required = false) User user,

        @PathParam("downloadId") String downloadId, @PathParam("dataType") final String dataType

) throws IOException {
    boolean isLogin = isLogin(user);
    ResponseBuilder rb = ok();
    StreamingOutput archiveStream = null;
    String filename = null;
    // dynamic download
    if (!downloader.isServiceAvailable() || downloader.isOverCapacity())
        throw new ServiceUnavailableException("Downloader is disabled");

    final Set<DataType> allowedDataTypes = isLogin ? AccessControl.FullAccessibleDataTypes
            : AccessControl.PublicAccessibleDataTypes;

    Map<String, JobStatus> jobStatus = downloader.getStatus(ImmutableSet.<String>of(downloadId));
    JobStatus status = jobStatus.get(downloadId);
    if (status == null || status.isExpired()) {

        throw new NotFoundException(downloadId, "download");
    }
    Map<DataType, JobProgress> typeProgressMap = status.getProgressMap();
    Set<DataType> downloadableTypes = Sets.intersection(typeProgressMap.keySet(), allowedDataTypes);

    Set<DataType> selectedType = Sets.filter(downloadableTypes, new Predicate<DataType>() {

        @Override
        public boolean apply(DataType input) {
            return input.name.equals(dataType);
        }

    });
    if (selectedType.isEmpty()) {
        log.error("permission denied for download type that needs access control: " + dataType
                + ", download id: " + downloadId);
        throw new NotFoundException(downloadId, "download");
    }

    List<DataType> downloadTypes = DataTypeGroupMap.get(selectedType.iterator().next());
    ImmutableList.Builder<DataType> actualDownloadTypes = ImmutableList.builder();
    for (DataType type : downloadTypes) {
        // to handle optional sub-type
        if (typeProgressMap.get(type) != null) {
            if (!typeProgressMap.get(type).isCompleted()) {
                log.error("Data type is not ready for download yet. Data Type: " + type + ", Dowload ID: "
                        + downloadId);
                throw new NotFoundException(downloadId, "download");
            } else {
                actualDownloadTypes.add(type);
            }
        }
    }
    String extension = INDIVIDUAL_TYPE_ARCHIVE_EXTENSION;
    downloadTypes = actualDownloadTypes.build();
    if (downloadTypes.size() == 1) {
        archiveStream = archiveStream(downloadId, downloadTypes.get(0));
    } else {
        archiveStream = archiveStream(downloadId, downloadTypes);
        extension = FULL_ARCHIVE_EXTENSION;
    }

    filename = fileName(extension);
    return rb.entity(archiveStream).type(getFileMimeType(filename))
            .header(CONTENT_DISPOSITION, type("attachment").fileName(filename).creationDate(new Date()).build())
            .build();
}

From source file:org.caleydo.core.util.color.ColorBrewer.java

public static Set<ColorBrewer> getSets(int size, EColorSchemeType type) {
    return Sets.filter(getSets(size), type.isOf());
}

From source file:org.caleydo.core.util.color.ColorBrewer.java

public static Set<ColorBrewer> getSets(EColorSchemeType type) {
    return Sets.filter(ImmutableSet.copyOf(values()), type.isOf());
}

From source file:org.sonatype.plugin.nexus.testenvironment.AbstractEnvironmentMojo.java

private Set<Artifact> filterOutSystemDependencies(Set<Artifact> artifacts) {
    return Sets.filter(artifacts, new Predicate<Artifact>() {
        @Override//  w w  w  .  j ava  2  s  .com
        public boolean apply(Artifact a) {
            return !"system".equals(a.getScope());
        }
    });
}

From source file:org.sonatype.plugin.nexus.testenvironment.AbstractEnvironmentMojo.java

private Set<MavenArtifact> filterOutExcludedPlugins(Collection<MavenArtifact> artifacts) {
    if (exclusions == null) {
        return Sets.newLinkedHashSet(artifacts);
    }/*from   w w  w.  j av a 2s .  co m*/

    return Sets.filter(Sets.newLinkedHashSet(artifacts), new Predicate<MavenArtifact>() {

        @Override
        public boolean apply(MavenArtifact a) {
            for (String exclusion : exclusions) {
                String[] pieces = exclusion.split(":");
                if (pieces.length != 2) {
                    throw new IllegalArgumentException("Invalid exclusion " + exclusion);
                }
                String groupId = pieces[0];
                String artifactId = pieces[1];

                if ("*".equals(groupId)) {
                    if (artifactId.equals(a.getArtifactId())) {
                        return false;
                    }
                } else {
                    if (groupId.equals(a.getGroupId()) && artifactId.equals(a.getArtifactId())) {
                        return false;
                    }
                }
            }

            return true;
        }
    });
}