Example usage for com.google.common.collect SetMultimap containsEntry

List of usage examples for com.google.common.collect SetMultimap containsEntry

Introduction

In this page you can find the example usage for com.google.common.collect SetMultimap containsEntry.

Prototype

boolean containsEntry(@Nullable Object key, @Nullable Object value);

Source Link

Document

Returns true if this multimap contains at least one key-value pair with the key key and the value value .

Usage

From source file:com.palantir.atlasdb.keyvalue.rdbms.utils.AtlasSqlUtils.java

public static <K, V> SetMultimap<K, V> listToSetMultimap(List<Pair<K, V>> list) {
    SetMultimap<K, V> result = HashMultimap.create();
    for (Pair<K, V> p : list) {
        Preconditions.checkArgument(!result.containsEntry(p.lhSide, p.rhSide));
        result.put(p.lhSide, p.rhSide);//  www  . j a va 2 s .  c o  m
    }
    return result;
}

From source file:omero.cmd.graphs.SkipHeadPolicy.java

/**
 * Adjust an existing graph traversal policy so that for specific model objects permissions are not checked.
 * @param graphPolicy the graph policy to adjust
 * @param permissionsOverrides for which model objects permissions are not to be checked
 * @return the adjusted graph policy//  w w w  .  j av a2  s  . com
 */
public static GraphPolicy getSkipHeadPolicyPerform(final GraphPolicy graphPolicy,
        final SetMultimap<String, Long> permissionsOverrides) {
    return new BaseGraphPolicyAdjuster(graphPolicy) {
        @Override
        protected boolean isAdjustedBeforeReview(Details object) {
            if (object.isCheckPermissions && permissionsOverrides
                    .containsEntry(object.subject.getClass().getName(), object.subject.getId())) {
                object.isCheckPermissions = false;
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("preserving previous setting, making " + object);
                }
                return true;
            } else {
                return false;
            }
        }
    };
}

From source file:checkers.game_engine.game_rules.RuleManager.java

@Override
public boolean isLegal(Player activePlayer, Position startPosition, Position destPosition, Board board) {
    SetMultimap<Position, Position> allMoves = getAllAvailableMoves(activePlayer, board);
    return allMoves.containsEntry(startPosition, destPosition);
}

From source file:org.eclipse.gef4.mvc.parts.AbstractContentPart.java

/**
 * {@inheritDoc}//from ww  w.  j  a v  a 2 s  .  co m
 * <p>
 * Delegates to {@link #doAttachToContentAnchorage(Object, String)}, which
 * is to be overwritten by subclasses.
 */
@Override
public final void attachToContentAnchorage(Object contentAnchorage, String role) {
    SetMultimap<Object, String> oldContentAnchorages = HashMultimap.create(getContentAnchorages());
    if (oldContentAnchorages.containsEntry(contentAnchorage, role)) {
        throw new IllegalArgumentException(
                "Already attached to anchorage " + contentAnchorage + " in role '" + role + "'.");
    }
    doAttachToContentAnchorage(contentAnchorage, role);
    // check doAttachToContentAnchorage(Object, String) does not violate
    // postconditions
    if (!getContentAnchorages().containsEntry(contentAnchorage, role)) {
        throw new IllegalArgumentException("doAttachToContentAnchorage did not properly attach to "
                + contentAnchorage + " with role '" + role + "'.");
    }
    pcs.firePropertyChange(CONTENT_ANCHORAGES_PROPERTY, oldContentAnchorages,
            Multimaps.unmodifiableSetMultimap(getContentAnchorages()));
}

From source file:org.eclipse.gef4.mvc.parts.AbstractContentPart.java

/**
 * {@inheritDoc}//w  ww . j  av  a 2s . com
 * <p>
 * Delegates to {@link #doDetachFromContentAnchorage(Object, String)}, which
 * is to be overwritten by subclasses.
 */
@Override
public final void detachFromContentAnchorage(Object contentAnchorage, String role) {
    SetMultimap<Object, String> oldContentAnchorages = HashMultimap.create(getContentAnchorages());
    if (!oldContentAnchorages.containsEntry(contentAnchorage, role)) {
        throw new IllegalArgumentException(
                "Not attached to content anchorage " + contentAnchorage + " with role '" + role + "'.");
    }
    doDetachFromContentAnchorage(contentAnchorage, role);
    // check postconditions for doDetachFromContentAnchorage(Object, String)
    if (getContentAnchorages().containsEntry(contentAnchorage, role)) {
        throw new IllegalArgumentException("doDetachFromContentAnchorage did not properly detach from "
                + contentAnchorage + " with role '" + role + "'.");
    }
    pcs.firePropertyChange(CONTENT_ANCHORAGES_PROPERTY, oldContentAnchorages,
            Multimaps.unmodifiableSetMultimap(getContentAnchorages()));
}

From source file:com.android.tools.idea.res.LocalResourceRepository.java

protected void doMerge(@NotNull Set<LocalResourceRepository> visited, @NotNull ResourceType type,
        @NotNull SetMultimap<String, String> seenQualifiers,
        @NotNull ListMultimap<String, ResourceItem> result) {
    ListMultimap<String, ResourceItem> items = getMap(type, false);
    if (items == null) {
        return;/*from   www  . ja va  2 s .  c om*/
    }
    for (ResourceItem item : items.values()) {
        String name = item.getName();
        String qualifiers = item.getQualifiers();
        if (!result.containsKey(name) || type == ResourceType.ID
                || !seenQualifiers.containsEntry(name, qualifiers)) {
            // We only add a duplicate item if there isn't an item with the same qualifiers (and it's
            // not an id; id's are allowed to be defined in multiple places even with the same
            // qualifiers)
            result.put(name, item);
            seenQualifiers.put(name, qualifiers);
        }
    }
}

From source file:org.eclipse.gef4.mvc.parts.AbstractVisualPart.java

@Override
public void attachToAnchorage(IVisualPart<VR, ? extends VR> anchorage, String role) {
    if (anchorage == null) {
        throw new IllegalArgumentException("Anchorage may not be null.");
    }/*from   ww  w  . j a  v  a 2s . co m*/
    if (role == null) {
        throw new IllegalArgumentException("Role may not be null.");
    }

    // copy anchorages by role (required for the change notification)
    SetMultimap<IVisualPart<VR, ? extends VR>, String> oldAnchorages = anchorages == null
            ? HashMultimap.<IVisualPart<VR, ? extends VR>, String>create()
            : HashMultimap.create(anchorages);

    if (oldAnchorages.containsEntry(anchorage, role)) {
        throw new IllegalArgumentException(
                "Already attached to anchorage " + anchorage + " with role '" + role + "'.");
    }

    attachToAnchorageWithoutNotify(anchorage, role);
    anchorage.attachAnchored(this);

    anchorage.refreshVisual();
    attachToAnchorageVisual(anchorage, role);
    refreshVisual();

    pcs.firePropertyChange(ANCHORAGES_PROPERTY, oldAnchorages, getAnchorages());
}

From source file:org.eclipse.gef4.mvc.parts.AbstractVisualPart.java

@Override
public void detachFromAnchorage(IVisualPart<VR, ? extends VR> anchorage, String role) {
    if (anchorage == null) {
        throw new IllegalArgumentException("Anchorage may not be null.");
    }/*from  w w w  . j ava 2 s. com*/
    if (role == null) {
        throw new IllegalArgumentException("Role may not be null.");
    }

    // copy anchorages (required for the change notification)
    SetMultimap<IVisualPart<VR, ? extends VR>, String> oldAnchorages = anchorages == null
            ? HashMultimap.<IVisualPart<VR, ? extends VR>, String>create()
            : HashMultimap.create(anchorages);

    if (!oldAnchorages.containsEntry(anchorage, role)) {
        throw new IllegalArgumentException(
                "Not attached to anchorage " + anchorage + " with role '" + role + "'.");
    }

    detachFromAnchorageWithoutNotify(anchorage, role);

    anchorage.detachAnchored(this);
    detachFromAnchorageVisual(anchorage, role);

    // TODO: send MapChangeNotification or otherwise identify changed
    // anchorage and role
    pcs.firePropertyChange(ANCHORAGES_PROPERTY, oldAnchorages, getAnchorages());
}

From source file:org.eclipse.gef4.mvc.behaviors.ContentBehavior.java

/**
 * Updates the host {@link IVisualPart}'s {@link IContentPart} anchorages
 * (see {@link IVisualPart#getAnchorages()}) so that it is in sync with the
 * set of content anchorages that is passed in.
 *
 * @param contentAnchorages//from   w w w  .  j  a v  a 2s  .  c  o  m
 *            * The map of content anchorages with roles to be synchronized
 *            with the list of {@link IContentPart} anchorages (
 *            {@link IContentPart#getAnchorages()}).
 *
 * @see IContentPart#getContentAnchorages()
 * @see IContentPart#getAnchorages()
 */
public void synchronizeContentAnchorages(SetMultimap<? extends Object, String> contentAnchorages) {
    if (contentAnchorages == null) {
        throw new IllegalArgumentException("contentAnchorages may not be null");
    }
    SetMultimap<IVisualPart<VR, ? extends VR>, String> anchorages = getHost().getAnchorages();

    // find anchorages whose content vanished
    List<Entry<IVisualPart<VR, ? extends VR>, String>> toRemove = new ArrayList<>();
    Set<Entry<IVisualPart<VR, ? extends VR>, String>> entries = anchorages.entries();
    for (Entry<IVisualPart<VR, ? extends VR>, String> e : entries) {
        if (!(e.getKey() instanceof IContentPart)) {
            continue;
        }
        Object content = ((IContentPart<VR, ? extends VR>) e.getKey()).getContent();
        if (!contentAnchorages.containsEntry(content, e.getValue())) {
            toRemove.add(e);
        }
    }

    // Correspondingly remove the anchorages. This is done in a separate
    // step to prevent ConcurrentModificationException.
    for (Entry<IVisualPart<VR, ? extends VR>, String> e : toRemove) {
        getHost().detachFromAnchorage(e.getKey(), e.getValue());
        disposeIfObsolete((IContentPart<VR, ? extends VR>) e.getKey());
    }

    // find content for which no anchorages exist
    List<Entry<IVisualPart<VR, ? extends VR>, String>> toAdd = new ArrayList<>();
    for (Entry<? extends Object, String> e : contentAnchorages.entries()) {
        IContentPart<VR, ? extends VR> anchorage = findOrCreatePartFor(e.getKey());
        if (!anchorages.containsEntry(anchorage, e.getValue())) {
            toAdd.add(Maps.<IVisualPart<VR, ? extends VR>, String>immutableEntry(anchorage, e.getValue()));
        }
    }

    // Correspondingly add the anchorages. This is done in a separate step
    // to prevent ConcurrentModificationException.
    for (Entry<IVisualPart<VR, ? extends VR>, String> e : toAdd) {
        getHost().attachToAnchorage(e.getKey(), e.getValue());
    }
}

From source file:com.android.sdklib.repository.local.LocalPlatformPkgInfo.java

/**
 * Get all the system images supported by a platform target.
 * For a platform, we first look in the new sdk/system-images folders then we
 * look for sub-folders in the platform/images directory and/or the one legacy
 * folder.//from w  w  w.  j av  a 2s. c o  m
 * If any given API appears twice or more, the first occurrence wins.
 *
 * @param fileOp File operation wrapper.
 * @param platformDir Root of the platform target being loaded.
 * @param apiVersion API level + codename of platform being loaded.
 * @return an array of ISystemImage containing all the system images for the target.
 *              The list can be empty but not null.
 */
@NonNull
private ISystemImage[] getPlatformSystemImages(IFileOp fileOp, File platformDir, AndroidVersion apiVersion) {
    Set<ISystemImage> found = new TreeSet<ISystemImage>();
    SetMultimap<IdDisplay, String> tagToAbiFound = TreeMultimap.create();

    // Look in the SDK/system-image/platform-n/tag/abi folders.
    // Look in the SDK/system-image/platform-n/abi folders.
    // If we find multiple occurrences of the same platform/abi, the first one read wins.

    LocalPkgInfo[] sysImgInfos = getLocalSdk().getPkgsInfos(PkgType.PKG_SYS_IMAGE);
    for (LocalPkgInfo pkg : sysImgInfos) {
        IPkgDesc d = pkg.getDesc();
        if (pkg instanceof LocalSysImgPkgInfo && !d.hasVendor() && apiVersion.equals(d.getAndroidVersion())) {
            IdDisplay tag = d.getTag();
            String abi = d.getPath();
            if (tag != null && abi != null && !tagToAbiFound.containsEntry(tag, abi)) {
                found.add(((LocalSysImgPkgInfo) pkg).getSystemImage());
                tagToAbiFound.put(tag, abi);
            }
        }
    }

    // Look in either the platform/images/abi or the legacy folder
    File imgDir = new File(platformDir, SdkConstants.OS_IMAGES_FOLDER);
    File[] files = fileOp.listFiles(imgDir);
    boolean useLegacy = true;
    boolean hasImgFiles = false;
    final IdDisplay defaultTag = SystemImage.DEFAULT_TAG;

    // Look for sub-directories
    for (File file : files) {
        if (fileOp.isDirectory(file)) {
            useLegacy = false;
            String abi = file.getName();
            if (!tagToAbiFound.containsEntry(defaultTag, abi)) {
                found.add(new SystemImage(file, LocationType.IN_IMAGES_SUBFOLDER, defaultTag, abi,
                        FileOp.EMPTY_FILE_ARRAY));
                tagToAbiFound.put(defaultTag, abi);
            }
        } else if (!hasImgFiles && fileOp.isFile(file)) {
            if (file.getName().endsWith(".img")) { //$NON-NLS-1$
                hasImgFiles = true;
            }
        }
    }

    if (useLegacy && hasImgFiles && fileOp.isDirectory(imgDir)
            && !tagToAbiFound.containsEntry(defaultTag, SdkConstants.ABI_ARMEABI)) {
        // We found no sub-folder system images but it looks like the top directory
        // has some img files in it. It must be a legacy ARM EABI system image folder.
        found.add(new SystemImage(imgDir, LocationType.IN_LEGACY_FOLDER, defaultTag, SdkConstants.ABI_ARMEABI,
                FileOp.EMPTY_FILE_ARRAY));
    }

    return found.toArray(new ISystemImage[found.size()]);
}