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

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

Introduction

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

Prototype

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

Source Link

Document

Removes a single key-value pair with the key key and the value value from this multimap, if such exists.

Usage

From source file:io.usethesource.criterion.impl.immutable.guava.ImmutableGuavaSetMultimap.java

@Override
public JmhSetMultimap remove(JmhValue key, JmhValue value) {
    final SetMultimap<JmhValue, JmhValue> tmpContent = HashMultimap.create(content);
    tmpContent.remove(key, value);

    final ImmutableSetMultimap<JmhValue, JmhValue> newContent = ImmutableSetMultimap.copyOf(tmpContent);

    return new ImmutableGuavaSetMultimap(newContent);
}

From source file:org.sosy_lab.cpachecker.core.reachedset.PseudoPartitionedReachedSet.java

@Override
public void remove(AbstractState pState) {
    super.remove(pState);

    Object key = getPartitionKey(pState);
    Comparable<?> pseudoKey = getPseudoPartitionKey(pState);
    Object pseudoHash = getPseudoHashCode(pState);
    SetMultimap<Object, AbstractState> states = partitionedReached.get(key, pseudoKey);
    if (states != null) {
        states.remove(pseudoHash, pState);
        if (states.isEmpty()) {
            partitionedReached.remove(key, pseudoKey);
        }//  w w  w .  jav a2 s.  c  om
    }
}

From source file:org.terasology.entitySystem.event.internal.EventSystemImpl.java

@Override
public <T extends Event> void unregisterEventReceiver(EventReceiver<T> eventReceiver, Class<T> eventClass,
        Class<? extends Component>... componentTypes) {
    SetMultimap<Class<? extends Component>, EventHandlerInfo> eventHandlerMap = componentSpecificHandlers
            .get(eventClass);/*  ww w  .ja v  a2  s .c o  m*/
    if (eventHandlerMap != null) {
        ReceiverEventHandlerInfo testReceiver = new ReceiverEventHandlerInfo<T>(eventReceiver, 0,
                componentTypes);
        for (Class<? extends Component> c : componentTypes) {
            eventHandlerMap.remove(c, testReceiver);
            for (Class<? extends Event> childType : childEvents.get(eventClass)) {
                eventHandlerMap.remove(childType, testReceiver);
            }
        }
    }
}

From source file:ome.services.blitz.repo.path.FilePathRestrictions.java

/**
 * Combine sets of rules to form a set that satisfies them all.
 * @param rules at least one set of rules
 * @return the intersection of the given rules
 *///from ww  w  .  j  a v a  2s . co m
private static FilePathRestrictions combineRules(FilePathRestrictions... rules) {
    if (rules.length == 0) {
        throw new IllegalArgumentException("cannot combine an empty list of rules");
    }

    int index = 0;
    FilePathRestrictions product = rules[index++];

    while (index < rules.length) {
        final FilePathRestrictions toCombine = rules[index++];

        final Set<Character> safeCharacters = Sets.intersection(product.safeCharacters,
                toCombine.safeCharacters);

        if (safeCharacters.isEmpty()) {
            throw new IllegalArgumentException("cannot combine safe characters");
        }

        final Set<Integer> allKeys = Sets.union(product.transformationMatrix.keySet(),
                toCombine.transformationMatrix.keySet());
        final ImmutableMap<Integer, Collection<Integer>> productMatrixMap = product.transformationMatrix
                .asMap();
        final ImmutableMap<Integer, Collection<Integer>> toCombineMatrixMap = toCombine.transformationMatrix
                .asMap();
        final SetMultimap<Integer, Integer> newTransformationMatrix = HashMultimap.create();

        for (final Integer key : allKeys) {
            final Collection<Integer> values;
            if (!productMatrixMap.containsKey(key)) {
                values = toCombineMatrixMap.get(key);
            } else if (!toCombineMatrixMap.containsKey(key)) {
                values = productMatrixMap.get(key);
            } else {
                final Set<Integer> valuesSet = new HashSet<Integer>(productMatrixMap.get(key));
                valuesSet.retainAll(toCombineMatrixMap.get(key));
                if (valuesSet.isEmpty()) {
                    throw new IllegalArgumentException(
                            "cannot combine transformations for Unicode code point " + key);
                }
                values = valuesSet;
            }
            for (final Integer value : values) {
                newTransformationMatrix.put(key, value);
            }
        }

        final SetMultimap<Integer, Integer> entriesRemoved = HashMultimap.create();
        boolean transitiveClosing;
        do {
            transitiveClosing = false;
            for (final Entry<Integer, Integer> transformation : newTransformationMatrix.entries()) {
                final int to = transformation.getValue();
                if (newTransformationMatrix.containsKey(to)) {
                    final int from = transformation.getKey();
                    if (!entriesRemoved.put(from, to)) {
                        throw new IllegalArgumentException(
                                "cyclic transformation involving Unicode code point " + from);
                    }
                    newTransformationMatrix.remove(from, to);
                    newTransformationMatrix.putAll(from, newTransformationMatrix.get(to));
                    transitiveClosing = true;
                    break;
                }
            }
        } while (transitiveClosing);

        product = new FilePathRestrictions(newTransformationMatrix,
                Sets.union(product.unsafePrefixes, toCombine.unsafePrefixes),
                Sets.union(product.unsafeSuffixes, toCombine.unsafeSuffixes),
                Sets.union(product.unsafeNames, toCombine.unsafeNames), safeCharacters);
    }
    return product;
}

From source file:org.terasology.recording.EventSystemReplayImpl.java

@Override
public <T extends Event> void unregisterEventReceiver(EventReceiver<T> eventReceiver, Class<T> eventClass,
        Class<? extends Component>... componentTypes) {
    SetMultimap<Class<? extends Component>, EventSystemReplayImpl.EventHandlerInfo> eventHandlerMap = componentSpecificHandlers
            .get(eventClass);//from   w  w  w  .  j  a v  a  2 s .  c om
    if (eventHandlerMap != null) {
        EventSystemReplayImpl.ReceiverEventHandlerInfo testReceiver = new EventSystemReplayImpl.ReceiverEventHandlerInfo<>(
                eventReceiver, 0, componentTypes);
        for (Class<? extends Component> c : componentTypes) {
            eventHandlerMap.remove(c, testReceiver);
            for (Class<? extends Event> childType : childEvents.get(eventClass)) {
                eventHandlerMap.remove(childType, testReceiver);
            }
        }
    }

    if (0 == componentTypes.length) {
        Iterator<EventSystemReplayImpl.EventHandlerInfo> eventHandlerIterator = generalHandlers.values()
                .iterator();
        while (eventHandlerIterator.hasNext()) {
            EventSystemReplayImpl.EventHandlerInfo eventHandler = eventHandlerIterator.next();
            if (eventHandler.getHandler().equals(eventReceiver)) {
                eventHandlerIterator.remove();
            }
        }
    }
}

From source file:org.cytoscape.model.internal.CyTableImpl.java

private final void removeFromReverseMap(final String columnName, final Object key, final Object value) {
    final String normalizedColName = normalizeColumnName(columnName);
    final SetMultimap<Object, Object> valueTokeysMap = reverse.get(normalizedColName);
    valueTokeysMap.remove(key, value);
}

From source file:org.cytoscape.model.internal.CyTableImpl.java

private final void addToReverseMap(final String columnName, final Object key, final Object oldValue,
        final Object newValue) {
    final String normalizedColName = normalizeColumnName(columnName);
    final SetMultimap<Object, Object> valueTokeysMap = reverse.get(normalizedColName);
    valueTokeysMap.remove(oldValue, key);
    valueTokeysMap.put(newValue, key);/*from  www.  j  a  v a2  s  .  c  om*/
}

From source file:org.apromore.canoniser.pnml.internal.Canonical2PNML.java

private void simplify() {
    //LOGGER.info("Performing structural simplifications"); 

    SetMultimap<org.apromore.pnml.NodeType, ArcType> incomingArcMultimap = HashMultimap.create();
    SetMultimap<org.apromore.pnml.NodeType, ArcType> outgoingArcMultimap = HashMultimap.create();

    // Index graph connectivity
    for (ArcType arc : data.getNet().getArc()) {
        incomingArcMultimap.put((org.apromore.pnml.NodeType) arc.getTarget(), arc);
        outgoingArcMultimap.put((org.apromore.pnml.NodeType) arc.getSource(), arc);
    }/*  w  w  w  .ja v  a2 s  .c om*/

    // When a synthetic place occurs adjacent to a silent transition on a branch, collapse them
    for (PlaceType place : data.getSynthesizedPlaces()) {
        if (incomingArcMultimap.get(place).size() == 1 && outgoingArcMultimap.get(place).size() == 1) {

            // Assign: --incomingArc-> (place) --outgoingArc->
            ArcType incomingArc = incomingArcMultimap.get(place).iterator().next();
            ArcType outgoingArc = outgoingArcMultimap.get(place).iterator().next();

            TransitionType transition = (TransitionType) outgoingArc.getTarget();
            if (incomingArcMultimap.get(transition).size() == 1 && isSilent(transition)) {
                // Collapse synthesized place followed by silent transition

                // Delete: --incomingArc-> (place) --outgoingArc-> [transition]
                data.getNet().getArc().remove(incomingArc);
                data.getNet().getArc().remove(outgoingArc);
                data.getNet().getPlace().remove(place);
                data.getNet().getTransition().remove(transition);

                // Re-source transition's outgoing arcs to incomingArc.source;
                assert incomingArc.getSource() instanceof TransitionType;
                for (ArcType arc : new HashSet<>(outgoingArcMultimap.get(transition))) {
                    arc.setSource(incomingArc.getSource());
                    outgoingArcMultimap.remove(transition, arc);
                    outgoingArcMultimap.put((TransitionType) incomingArc.getSource(), arc);
                }
            } else {
                transition = (TransitionType) incomingArc.getSource();
                if (outgoingArcMultimap.get(transition).size() == 1 && isSilent(transition)) {
                    // Collapse silent transition followed by synthesized place

                    // Delete: [transition] --incomingArc-> (place) --outgoingArc->
                    data.getNet().getArc().remove(incomingArc);
                    data.getNet().getArc().remove(outgoingArc);
                    data.getNet().getPlace().remove(place);
                    data.getNet().getTransition().remove(transition);

                    // Re-target transition's incoming arcs to outgoingArc.target;
                    assert outgoingArc.getTarget() instanceof TransitionType;
                    for (ArcType arc : new HashSet<>(incomingArcMultimap.get(transition))) {
                        arc.setTarget(outgoingArc.getTarget());
                        incomingArcMultimap.remove(transition, arc);
                        incomingArcMultimap.put((TransitionType) outgoingArc.getTarget(), arc);
                    }
                }
            }
        }
    }
    data.getSynthesizedPlaces().clear();
    //LOGGER.info("Performed structural simplifications");      

    // Logic to correct position of process elements        
    PlaceType place = null;
    TransitionType transition = null;
    BigDecimal TranX, TranY, PlaceX, PlaceY;
    int offset1 = 0;
    int offset2 = 0;

    for (int i = 0; i < 2; i++) {
        for (ArcType arc : data.getNet().getArc()) {

            if (arc.getSource() instanceof PlaceType) {
                place = (PlaceType) arc.getSource();
                transition = (TransitionType) arc.getTarget();
                offset1 = -75;
                offset2 = +75;
            } else if (arc.getSource() instanceof TransitionType) {
                place = (PlaceType) arc.getTarget();
                transition = (TransitionType) arc.getSource();
                offset1 = +75;
                offset2 = -75;
            }

            TranX = transition.getGraphics().getPosition().getX();
            TranY = transition.getGraphics().getPosition().getY();
            PlaceX = place.getGraphics().getPosition().getX();
            PlaceY = place.getGraphics().getPosition().getY();

            if ((Double.parseDouble(String.valueOf(PlaceX)) == 100
                    && Double.parseDouble(String.valueOf(PlaceY)) == 400)
                    && (Double.parseDouble(String.valueOf(TranX)) == 100
                            && Double.parseDouble(String.valueOf(TranY)) == 400)) {
                ; // do nothing
            } else {

                if (Double.parseDouble(String.valueOf(PlaceX)) == 100
                        && Double.parseDouble(String.valueOf(PlaceY)) == 400) {
                    place.getGraphics().getPosition()
                            .setX(BigDecimal.valueOf(Double.parseDouble(String.valueOf(TranX)) + offset1));
                    place.getGraphics().getPosition().setY(TranY);
                } else if (Double.parseDouble(String.valueOf(TranX)) == 100
                        && Double.parseDouble(String.valueOf(TranY)) == 400) {
                    transition.getGraphics().getPosition()
                            .setX(BigDecimal.valueOf(Double.parseDouble(String.valueOf(PlaceX)) + offset2));
                    transition.getGraphics().getPosition().setY(PlaceY);
                }
            }

            if (arc.getGraphics() != null) {
                if (arc.getGraphics().getPosition() != null) {
                    arc.getGraphics().getPosition().clear();
                }
            }
        }
    }
}

From source file:dk.dma.nogoservice.service.NoGoResponseMerger.java

/**
 * Merge algorithm for multiple NoGoAreas.
 * <p>/* w w w. j  av a2  s  .  c  o  m*/
 * <ol>
 * <li>Find the exclusive zone for each area (the space that is not overlapped with other areas) </li>
 * <li>Find all the combinations of overlaps. </li>
 * <li>In the exclusive zone the nogo polygons (after the overlaps have been extracted) can be used directly</li>
 * <li>In the overlap zones the intersections of NoGo areas, will define the actual NoGo areas, because Go wins over NoGO (as foreign territory is nogo)</li>
 * </ol>
 *
 * @param areas the calculated NoGo areas
 * @return the response
 */
CalculatedNoGoArea merge(List<CalculatedNoGoArea> areas) {

    if (areas.size() == 1) {
        return areas.get(0);
    }

    SetMultimap<CalculatedNoGoArea, Geometry> unprocessed = HashMultimap.create();
    areas.forEach(a -> unprocessed.putAll(a, a.getNogoAreas()));

    List<Geometry> processedNogoAreas = new ArrayList<>();
    for (CalculatedNoGoArea area : areas) {
        List<CalculatedNoGoArea> copy = new ArrayList<>(areas);
        copy.remove(area);
        List<Geometry> otherAreas = copy.stream().map(CalculatedNoGoArea::getArea).collect(Collectors.toList());

        // we now have the exclusive zone for this area. Now find the polygons inside the exclusive zone, if a polygon intersects with the boundary of the
        // exclusive zone, then split it in two, the part inside the exclusive zone is done, the other part will be processed later inside the overlapped zone
        Set<Geometry> nogoAreas = new HashSet<>(unprocessed.get(area));

        // take all the nogo areas and calculate the intersection with the exclusive zone
        for (Geometry nogoArea : nogoAreas) {
            Geometry result = nogoArea;
            for (Geometry otherArea : otherAreas) {
                if (otherArea.intersects(nogoArea)) {
                    Geometry intersection = otherArea.intersection(nogoArea);
                    if (!intersection.isEmpty()) {
                        result = result.difference(otherArea);
                        // add the intersection pat of the NoGo area to the unprocessed set so we can process it during overlap handling
                        if (!result.isEmpty()) {
                            // if there was no difference, this nogo area is completely inside the other area
                            unprocessed.put(area, intersection);
                        }
                    }
                }
            }

            if (!result.isEmpty()) {
                processedNogoAreas.add(result);
                unprocessed.remove(area, nogoArea); // area has now been processed
            }
        }
    }

    // now process all combinations of overlaps
    Set<Overlap> overlapCombinations = calculateOverlapCombinations(areas);

    for (Overlap overlapCombination : overlapCombinations) {
        Geometry exclusiveOverlapArea = overlapCombination.getExclusiveArea();

        List<Geometry> nogoAreas = new ArrayList<>();
        overlapCombination.included.forEach(g -> nogoAreas.addAll(unprocessed.get(g)));
        List<Geometry> noGoLayers = overlapCombination.included.stream().map(unprocessed::get)
                .filter(g -> !g.isEmpty()).map(g -> iterativeOperation(g, Geometry::union))
                .collect(Collectors.toList());
        List<Geometry> goAreas = noGoLayers.stream().map(exclusiveOverlapArea::difference)
                .collect(Collectors.toList());
        if (!goAreas.isEmpty()) {
            // We need to join all the NoGo areas, in a way so Go wins over NoGo.
            Geometry totalGoArea = iterativeOperation(goAreas, Geometry::union);
            Geometry totalNoGoArea = exclusiveOverlapArea.difference(totalGoArea);
            if (!totalGoArea.isEmpty()) {
                processedNogoAreas.add(totalNoGoArea);
            }
        }
    }

    List<Geometry> collect = areas.stream().map(CalculatedNoGoArea::getArea).collect(Collectors.toList());
    Iterator<Geometry> iterator = collect.iterator();
    Geometry totalArea = iterator.next();
    while (iterator.hasNext()) {
        totalArea = totalArea.union(iterator.next());
    }

    TopologyPreservingSimplifier simplifier = new TopologyPreservingSimplifier(totalArea);
    totalArea = simplifier.getResultGeometry();

    // construct the result
    CalculatedNoGoArea result = new CalculatedNoGoArea();
    result.setArea(totalArea);
    result.setNogoAreas(processedNogoAreas);
    Optional<JSonWarning> optionalWarning = areas.stream().map(CalculatedNoGoArea::getWarning)
            .filter(Objects::nonNull).findFirst();
    optionalWarning.ifPresent(result::setWarning);

    return result;

}

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

/**
 * Adjust an existing graph traversal policy so that orphaned model objects will always or never be included,
 * according to their type.//from   w w  w.  j  av  a  2 s. c  om
 * @param graphPolicy the graph policy to adjust
 * @param graphPathBean the graph path bean, for converting class names to the actual classes
 * @param startFrom the model object types to from which to start inclusion, may not be empty or {@code null}
 * @param startAction the action associated with nodes qualifying as start objects
 * @param permissionsOverrides where to note for which {@code startFrom} objects permissions are not to be checked
 * @return the adjusted graph policy
 * @throws GraphException if no start classes are named
 */
public static GraphPolicy getSkipHeadPolicySkip(final GraphPolicy graphPolicy,
        final GraphPathBean graphPathBean, Collection<String> startFrom, final GraphPolicy.Action startAction,
        final SetMultimap<String, Long> permissionsOverrides) throws GraphException {
    if (CollectionUtils.isEmpty(startFrom)) {
        throw new GraphException(SkipHead.class.getSimpleName() + " requires the start classes to be named");
    }

    /* convert the class names to actual classes */

    final Function<String, Class<? extends IObject>> getClassFromName = new Function<String, Class<? extends IObject>>() {
        @Override
        public Class<? extends IObject> apply(String className) {
            final int lastDot = className.lastIndexOf('.');
            if (lastDot > 0) {
                className = className.substring(lastDot + 1);
            }
            return graphPathBean.getClassForSimpleName(className);
        }
    };

    final ImmutableSet<Class<? extends IObject>> startFromClasses = ImmutableSet
            .copyOf(Collections2.transform(startFrom, getClassFromName));

    final Predicate<IObject> isStartFrom = new Predicate<IObject>() {
        @Override
        public boolean apply(IObject subject) {
            final Class<? extends IObject> subjectClass = subject.getClass();
            for (final Class<? extends IObject> startFromClass : startFromClasses) {
                if (startFromClass.isAssignableFrom(subjectClass)) {
                    return true;
                }
            }
            return false;
        }
    };

    /* construct the function corresponding to the model graph descent truncation */

    return new GraphPolicy() {
        @Override
        public void registerPredicate(GraphPolicyRulePredicate predicate) {
            graphPolicy.registerPredicate(predicate);
        }

        @Override
        public GraphPolicy getCleanInstance() {
            throw new IllegalStateException("not expecting to provide a clean instance");
        }

        @Override
        public void setCondition(String name) {
            graphPolicy.setCondition(name);
        }

        @Override
        public boolean isCondition(String name) {
            return graphPolicy.isCondition(name);
        }

        @Override
        public void noteDetails(Session session, IObject object, String realClass, long id) {
            graphPolicy.noteDetails(session, object, realClass, id);
        }

        @Override
        public final Set<Details> review(Map<String, Set<Details>> linkedFrom, Details rootObject,
                Map<String, Set<Details>> linkedTo, Set<String> notNullable, boolean isErrorRules)
                throws GraphException {
            if (rootObject.action == startAction && isStartFrom.apply(rootObject.subject)) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("deferring review of " + rootObject);
                }
                /* note which permissions overrides to start from */
                final String className = rootObject.subject.getClass().getName();
                final Long id = rootObject.subject.getId();
                if (rootObject.isCheckPermissions) {
                    permissionsOverrides.remove(className, id);
                } else {
                    permissionsOverrides.put(className, id);
                }
                /* skip the review, start from this object in a later request */
                return Collections.emptySet();
            } else {
                /* do the review */
                return graphPolicy.review(linkedFrom, rootObject, linkedTo, notNullable, isErrorRules);
            }
        }
    };
}