List of usage examples for com.google.common.collect Multimap containsEntry
boolean containsEntry(@Nullable Object key, @Nullable Object value);
From source file:org.hudsonci.maven.plugin.dependencymonitor.internal.ProjectArtifactCacheImpl.java
private boolean projectsContain(final Multimap<AbstractProject, MavenCoordinatesDTO> source, final MavenCoordinatesDTO artifact) { assert source != null; assert artifact != null; for (AbstractProject project : source.keySet()) { if (source.containsEntry(project, artifact)) { return true; }//w w w .j a va 2 s. c o m } return false; }
From source file:org.hudsonci.maven.plugin.dependencymonitor.internal.ProjectArtifactCacheImpl.java
private Collection<AbstractProject> projectsContaining( final Multimap<AbstractProject, MavenCoordinatesDTO> source, final MavenCoordinatesDTO artifact) { assert source != null; assert artifact != null; Set<AbstractProject> projects = Sets.newHashSet(); for (AbstractProject project : source.keySet()) { if (source.containsEntry(project, artifact)) { projects.add(project);// w w w. j a v a 2 s . c o m } } return projects; }
From source file:com.dmdirc.plugins.PluginMetaDataValidator.java
/** * Check if the services required by this plugin are available. * * @param knownServices A map of known services * @param services Required services *///from w w w .j a v a 2s . c o m private void checkServices(final Multimap<String, String> knownServices, final Collection<String> services) { if (services == null || services.isEmpty()) { return; } for (String requirement : services) { final String[] bits = requirement.split(" ", 2); final String name = bits[0]; final String type = bits[1]; if (!knownServices.containsKey(type) || !"any".equalsIgnoreCase(name) && !knownServices.containsEntry(type, name)) { errors.add("Service " + name + " of type " + type + " not available"); } } }
From source file:net.sourceforge.cilib.type.types.container.StandardGraph.java
@Override public boolean equals(Object obj) { if (this == obj) { return true; }// w w w . j a va2 s . co m if ((obj == null) || (this.getClass() != obj.getClass())) { return false; } StandardGraph<E> graph = (StandardGraph<E>) obj; if (this.adjacencyMap.size() != graph.adjacencyMap.size()) { return false; } if (this.edgeCount() != graph.edgeCount()) { return false; } if (!adjacencyMap.keySet().containsAll(graph.adjacencyMap.keySet())) { return false; } // Set up the edge sets. Multimap<E, E> currentEdgeSet = this.getEdgeSet(); Multimap<E, E> otherEdgeSet = graph.getEdgeSet(); for (Map.Entry<E, E> entry : currentEdgeSet.entries()) { if (!otherEdgeSet.containsEntry(entry.getKey(), entry.getValue())) { return false; } } for (Map.Entry<E, E> entry : otherEdgeSet.entries()) { if (!currentEdgeSet.containsEntry(entry.getKey(), entry.getValue())) { return false; } } return true; }
From source file:org.sosy_lab.cpachecker.cpa.value.refiner.ValueAnalysisConcreteErrorPathAllocator.java
private Multimap<IDExpression, MemoryLocation> getAllMemoryLocationInPath( List<Pair<ValueAnalysisState, CFAEdge>> pPath) { Multimap<IDExpression, MemoryLocation> result = HashMultimap.create(); for (Pair<ValueAnalysisState, CFAEdge> edgeStatePair : pPath) { ValueAnalysisState valueState = edgeStatePair.getFirst(); for (MemoryLocation loc : valueState.getConstantsMapView().keySet()) { IDExpression idExp = createBaseIdExpresssion(loc); if (!result.containsEntry(idExp, loc)) { result.put(idExp, loc);/*from ww w . j a va 2s .c om*/ } } } return result; }
From source file:com.axelor.db.JPA.java
@SuppressWarnings("all") private static <T extends Model> T _edit(Class<T> klass, Map<String, Object> values, Set<Model> visited, Multimap<String, Long> edited) { if (values == null) return null; Mapper mapper = Mapper.of(klass);/*from w ww . jav a 2 s. c o m*/ Long id = null; T bean = null; try { id = Long.valueOf(values.get("id").toString()); } catch (NumberFormatException e) { throw new IllegalArgumentException(e); } catch (NullPointerException e) { } if (id == null || id <= 0) { id = null; try { bean = klass.newInstance(); } catch (Exception ex) { throw new IllegalArgumentException(ex); } } else { bean = JPA.em().find(klass, id); if (bean == null) { throw new OptimisticLockException(new StaleObjectStateException(klass.getName(), id)); } } // optimistic concurrency check Integer beanVersion = (Integer) values.get("version"); boolean beanChanged = false; if (visited.contains(bean) && beanVersion == null) { return bean; } visited.add(bean); // don't update reference objects if (id != null && (beanVersion == null || edited.containsEntry(klass.getName(), id))) { return bean; } if (id != null) { edited.put(klass.getName(), id); } for (String name : values.keySet()) { Property p = mapper.getProperty(name); if (p == null || p.isPrimary() || p.isVersion() || mapper.getSetter(name) == null) continue; Object value = values.get(name); Class<Model> target = (Class<Model>) p.getTarget(); if (p.isCollection()) { Collection items = new ArrayList(); if (Set.class.isAssignableFrom(p.getJavaType())) items = new HashSet(); if (value instanceof Collection) { for (Object val : (Collection) value) { if (val instanceof Map) { if (p.getMappedBy() != null) { if (val instanceof ImmutableMap) val = Maps.newHashMap((Map) val); ((Map) val).remove(p.getMappedBy()); } Model item = _edit(target, (Map) val, visited, edited); items.add(p.setAssociation(item, bean)); } else if (val instanceof Number) { items.add(JPA.find(target, Long.parseLong(val.toString()))); } } } Object old = mapper.get(bean, name); if (old instanceof Collection) { boolean changed = ((Collection) old).size() != items.size(); if (!changed) { for (Object item : items) { if (!((Collection) old).contains(item)) { changed = true; break; } } } if (changed) { if (p.isOrphan()) { for (Object item : (Collection) old) { if (!items.contains(item)) { p.setAssociation(item, null); } } } p.clear(bean); p.addAll(bean, items); beanChanged = true; } continue; } if (p.getType() == PropertyType.MANY_TO_MANY && p.getMappedBy() != null) { p.addAll(bean, items); } value = items; } else if (value instanceof Map) { value = _edit(target, (Map) value, visited, edited); } Object oldValue = mapper.set(bean, name, value); if (p.valueChanged(bean, oldValue)) { beanChanged = true; } } if (beanChanged) { checkVersion(bean, beanVersion); } else if (id != null) { edited.remove(klass.getName(), id); } return bean; }
From source file:com.haulmont.cuba.core.sys.PersistenceSecurityImpl.java
@SuppressWarnings("unchecked") protected void applyConstraints(Entity entity, Set<EntityId> handled) { MetaClass metaClass = entity.getMetaClass(); EntityId entityId = new EntityId(referenceToEntitySupport.getReferenceId(entity), metaClass.getName()); if (handled.contains(entityId)) { return;// www. j a v a2s . com } handled.add(entityId); if (entity instanceof BaseGenericIdEntity) { BaseGenericIdEntity baseGenericIdEntity = (BaseGenericIdEntity) entity; Multimap<String, Object> filteredData = BaseEntityInternalAccess.getFilteredData(baseGenericIdEntity); for (MetaProperty property : metaClass.getProperties()) { if (metadataTools.isPersistent(property) && PersistenceHelper.isLoaded(entity, property.getName())) { Object value = entity.getValue(property.getName()); if (value instanceof Collection) { Collection entities = (Collection) value; for (Iterator<Entity> iterator = entities.iterator(); iterator.hasNext();) { Entity item = iterator.next(); if (filteredData != null && filteredData.containsEntry(property.getName(), referenceToEntitySupport.getReferenceId(item))) { iterator.remove(); } else { applyConstraints(item, handled); } } } else if (value instanceof Entity) { if (filteredData != null && filteredData.containsEntry(property.getName(), referenceToEntitySupport.getReferenceId((Entity) value))) { baseGenericIdEntity.setValue(property.getName(), null); } else { applyConstraints((Entity) value, handled); } } } } } }
From source file:org.eclipse.papyrus.uml.diagram.activity.activitygroup.GroupRequestAdvisor.java
/** * Handle all the children of the group (graphical and non graphical children) * // ww w . j a v a2s. c om * @param request * @param cc * @param targetElement */ protected void handleSemanticChildren(final IGroupRequest request, CompositeCommand cc, EObject targetElement) { List<EObject> graphicalChildren = Lists.newArrayList(); /* * There is graphical childrne only when the node is moving */ if (request.getInitialRequest() instanceof ChangeBoundsRequest) { graphicalChildren = handleGraphicalChildren(request, cc); } /* * Unset */ for (Entry<EReference, EObject> oldChildrenEntry : Utils.getOldChildren(request).entries()) { Multimap<EReference, EObject> allActualChildren = request.getChildrenEReferenceMap(); EReference ref = oldChildrenEntry.getKey(); if (ref != null) { if (!allActualChildren.containsEntry(oldChildrenEntry.getValue(), ref)) { EReference eOpposite = ref.getEOpposite(); if (!graphicalChildren.contains(oldChildrenEntry.getValue())) { if (eOpposite != null && !eOpposite.isContainment() && !ref.isContainment()) { RemoveValueRequest rmVa = new RemoveValueRequest(targetElement, ref, Collections.singletonList(oldChildrenEntry.getValue())); RemoveValueCommand rmCmd = new RemoveValueCommand(rmVa); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("From handling parent : Remove ");////$NON-NLS-1$ stringBuilder.append(Utils.getCorrectLabel(ref)); stringBuilder.append(" from ");////$NON-NLS-1$ stringBuilder.append(Utils.getCorrectLabel(targetElement)); stringBuilder.append(" value ");////$NON-NLS-1$ stringBuilder.append(Utils.getCorrectLabel(oldChildrenEntry.getValue()));////$NON-NLS-1$ rmCmd.setLabel(stringBuilder.toString()); if (rmCmd != null) { cc.compose(rmCmd); } } } } } } /* * Set semantic */ Set<EObject> newChildren = Sets.newHashSet(); for (Entry<EReference, EObject> entry : request.getChildrenEReferenceMap().entries()) { EReference ref = entry.getKey(); if (ref != null) { EReference eOpposite = ref.getEOpposite(); if (!graphicalChildren.contains(entry.getValue())) { newChildren.add(entry.getValue()); if (eOpposite != null && !eOpposite.isContainment()) { SetDeferredRequest setRq = new SetDeferredRequest( request.getHostRequest().getEditingDomain(), request.getTargetElement(), ref, entry.getValue()); DeferredSetValueCommand setCmd = new DeferredSetValueCommand(setRq); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("From handling parent : Set deferred");////$NON-NLS-1$ stringBuilder.append(Utils.getCorrectLabel(entry.getValue())); stringBuilder.append(" from ");////$NON-NLS-1$ stringBuilder.append(Utils.getCorrectLabel(ref)); stringBuilder.append(" value ");////$NON-NLS-1$ stringBuilder.append(Utils.getCorrectLabel(entry.getValue()));////$NON-NLS-1$ setCmd.setLabel(stringBuilder.toString()); if (setCmd != null) { cc.compose(setCmd); } } } } if (!newChildren.isEmpty()) { handleChangeParentNotificationCommand(request, cc, newChildren); } } }
From source file:org.eclipse.papyrus.uml.diagram.activity.activitygroup.GroupRequestAdvisor.java
/** * Set and Unset semantic relation with parents * // w w w . j a v a2s . c o m * @param request * {@link IGroupRequest} * @param cc * {@link CompositeCommand} to compose command * @param elementAdapter */ protected void handleSemanticParents(IGroupRequest request, CompositeCommand cc, Object elementAdapter) { EObject targetElement = (EObject) elementAdapter; Multimap<EReference, EObject> allActualParent = request.getParentEReferenceMap(); for (Entry<EReference, EObject> entry : Utils.getOldParents(request).entries()) { EReference ref = entry.getKey(); if (ref != null) { if (!allActualParent.containsEntry(ref, entry.getValue())) { EReference eOpposite = ref.getEOpposite(); if (eOpposite != null && !eOpposite.isContainment() && !eOpposite.isDerived()) { RemoveValueRequest rmVa = new RemoveValueRequest(targetElement, ref, Collections.singletonList(entry.getValue())); RemoveValueCommand rmCmd = new RemoveValueCommand(rmVa); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("From handling parent : Remove ");////$NON-NLS-1$ stringBuilder.append(Utils.getCorrectLabel(entry.getValue())); stringBuilder.append(" from ");////$NON-NLS-1$ stringBuilder.append(Utils.getCorrectLabel(targetElement)); stringBuilder.append(" value ");////$NON-NLS-1$ stringBuilder.append(Utils.getCorrectLabel(entry.getValue()));////$NON-NLS-1$ rmCmd.setLabel(stringBuilder.toString()); if (rmCmd != null) { cc.compose(rmCmd); } } // } } } } /* * Set semantic * If the EObject has not been already handle as graphical children */ for (Entry<EReference, EObject> entry : request.getParentEReferenceMap().entries()) { EReference ref = entry.getKey(); if (ref != null) { EReference eOpposite = ref.getEOpposite(); if (eOpposite != null && !eOpposite.isContainment() && !ref.isContainment()) { SetDeferredRequest setRq = new SetDeferredRequest(request.getHostRequest().getEditingDomain(), request.getTargetElement(), ref, entry.getValue()); DeferredSetValueCommand setCmd = new DeferredSetValueCommand(setRq); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("From handling parent : Set deferred ");////$NON-NLS-1$ stringBuilder.append(Utils.getCorrectLabel(ref)); stringBuilder.append(" from ");////$NON-NLS-1$ stringBuilder.append(Utils.getCorrectLabel(request.getTargetElement())); stringBuilder.append(" value ");////$NON-NLS-1$ stringBuilder.append(Utils.getCorrectLabel(entry.getValue()));////$NON-NLS-1$ setCmd.setLabel(stringBuilder.toString()); if (setCmd != null) { cc.compose(setCmd); } } } } }
From source file:org.voltdb.sysprocs.saverestore.StreamSnapshotWritePlan.java
/** * For each site, generate a task for each target it has for this table. *//*from w w w . j a v a 2 s. c o m*/ private void createTasksForTable(Table table, List<DataTargetInfo> dataTargets, Multimap<Long, Long> replicatedSrcToDst, AtomicInteger numTables, SnapshotRegistry.Snapshot snapshotRecord) { // srcHSId -> tasks Multimap<Long, SnapshotTableTask> tasks = ArrayListMultimap.create(); for (DataTargetInfo targetInfo : dataTargets) { // Create a predicate for the table task AbstractExpression predicate = null; boolean deleteTuples = false; if (!table.getIsreplicated()) { predicate = createPredicateForTableStream(table, targetInfo.stream); // Only delete tuples if there is a predicate, e.g. elastic join if (predicate != null) { deleteTuples = true; } } else { // If the current (source, destination) pair is not in the replicated table source // list, then it shouldn't send any replicated table data. // TODO: Remove this once non-blocking elastic join is implemented. if (!replicatedSrcToDst.containsEntry(targetInfo.srcHSId, targetInfo.dstHSId)) { if (SNAP_LOG.isDebugEnabled()) { SNAP_LOG.debug("Skipping replicated table " + table.getTypeName() + " for source destination pair " + CoreUtils.hsIdToString(targetInfo.srcHSId) + " -> " + CoreUtils.hsIdToString(targetInfo.dstHSId)); } continue; } } final Runnable onClose = new TargetStatsClosure(targetInfo.dataTarget, table.getTypeName(), numTables, snapshotRecord); targetInfo.dataTarget.setOnCloseHandler(onClose); final SnapshotTableTask task = new SnapshotTableTask(table, targetInfo.dataTarget, new SnapshotDataFilter[0], // This task no longer needs partition filtering predicate, deleteTuples); tasks.put(targetInfo.srcHSId, task); m_targets.add(targetInfo.dataTarget); } placeTasksForTable(table, tasks); }