List of usage examples for com.google.common.collect Multimap isEmpty
boolean isEmpty();
From source file:fr.ujm.tse.lt2c.satin.triplestore.VerticalPartioningTripleStoreRWLock.java
@Override public void remove(final Triple triple) { this.rwlock.writeLock().lock(); try {//from w w w . j a v a2s . c o m if (this.contains(triple)) { final Multimap<Long, Long> multimap = this.internalstore.get(triple.getPredicate()); multimap.remove(triple.getSubject(), triple.getObject()); this.triples--; if (multimap.isEmpty()) { this.internalstore.remove(triple.getPredicate()); } } } catch (final Exception e) { logger.error("", e); } finally { this.rwlock.writeLock().unlock(); } }
From source file:com.palantir.atlasdb.cleaner.Scrubber.java
private void deleteCellsAtTimestamps(TransactionManager txManager, String tableName, Multimap<Cell, Long> cellToTimestamp, Transaction.TransactionType transactionType) { if (!cellToTimestamp.isEmpty()) { for (Follower follower : followers) { follower.run(txManager, tableName, cellToTimestamp.keySet(), transactionType); }/*from w ww . j a v a 2 s . c o m*/ keyValueService.addGarbageCollectionSentinelValues(tableName, cellToTimestamp.keySet()); keyValueService.delete(tableName, cellToTimestamp); } }
From source file:org.sosy_lab.cpachecker.cpa.octagon.refiner.OctagonArgBasedDelegatingRefiner.java
/** * This method performs an value-analysis refinement. * * @param reached the current reached set * @param errorPath the current error path * @returns true, if the value-analysis refinement was successful, else false * @throws CPAException when value-analysis interpolation fails *///from w ww . java2s . c om private boolean performValueAnalysisRefinement(final ARGReachedSet reached, final ARGPath errorPath) throws CPAException, InterruptedException { numberOfValueAnalysisRefinements++; UnmodifiableReachedSet reachedSet = reached.asReachedSet(); Precision precision = reachedSet.getPrecision(reachedSet.getLastState()); VariableTrackingPrecision octPrecision = (VariableTrackingPrecision) Precisions.asIterable(precision) .filter(VariableTrackingPrecision.isMatchingCPAClass(OctagonCPA.class)).get(0); VariableTrackingPrecision refinedOctPrecision; Pair<ARGState, CFAEdge> refinementRoot; Multimap<CFANode, MemoryLocation> increment = interpolatingRefiner.determinePrecisionIncrement(errorPath); refinementRoot = interpolatingRefiner.determineRefinementRoot(errorPath, increment, false); // no increment - value-analysis refinement was not successful if (increment.isEmpty()) { return false; } // if two subsequent refinements are similar (based on some fancy heuristic), choose a different refinement root if (checkForRepeatedRefinements && isRepeatedRefinement(increment, refinementRoot)) { refinementRoot = interpolatingRefiner.determineRefinementRoot(errorPath, increment, true); } refinedOctPrecision = octPrecision.withIncrement(increment); if (valueAnalysisRefinementWasSuccessful(errorPath, octPrecision, refinedOctPrecision)) { numberOfSuccessfulValueAnalysisRefinements++; reached.removeSubtree(refinementRoot.getFirst(), refinedOctPrecision, VariableTrackingPrecision.isMatchingCPAClass(OctagonCPA.class)); return true; } else { return false; } }
From source file:org.sosy_lab.cpachecker.cpa.octagon.refiner.OctagonDelegatingRefiner.java
/** * This method performs an value-analysis refinement. * * @param reached the current reached set * @param errorPath the current error path * @returns true, if the value-analysis refinement was successful, else false * @throws CPAException when value-analysis interpolation fails * @throws InvalidConfigurationException */// ww w . ja va2 s. c om private boolean performValueAnalysisRefinement(final ARGReachedSet reached, final MutableARGPath errorPath) throws CPAException, InterruptedException { numberOfValueAnalysisRefinements++; UnmodifiableReachedSet reachedSet = reached.asReachedSet(); Precision precision = reachedSet.getPrecision(reachedSet.getLastState()); VariableTrackingPrecision octPrecision = (VariableTrackingPrecision) Precisions.asIterable(precision) .filter(VariableTrackingPrecision.isMatchingCPAClass(OctagonCPA.class)).get(0); VariableTrackingPrecision refinedOctPrecision; Pair<ARGState, CFAEdge> refinementRoot; Multimap<CFANode, MemoryLocation> increment = interpolatingRefiner.determinePrecisionIncrement(errorPath); refinementRoot = interpolatingRefiner.determineRefinementRoot(errorPath, increment, false); // no increment - value-analysis refinement was not successful if (increment.isEmpty()) { return false; } // if two subsequent refinements are similar (based on some fancy heuristic), choose a different refinement root if (checkForRepeatedRefinements && isRepeatedRefinement(increment, refinementRoot)) { refinementRoot = interpolatingRefiner.determineRefinementRoot(errorPath, increment, true); } refinedOctPrecision = octPrecision.withIncrement(increment); if (valueAnalysisRefinementWasSuccessful(errorPath, octPrecision, refinedOctPrecision)) { numberOfSuccessfulValueAnalysisRefinements++; reached.removeSubtree(refinementRoot.getFirst(), refinedOctPrecision, VariableTrackingPrecision.isMatchingCPAClass(OctagonCPA.class)); return true; } else { return false; } }
From source file:org.sosy_lab.cpachecker.cpa.apron.refiner.ApronARGBasedDelegatingRefiner.java
/** * This method performs an value-analysis refinement. * * @param reached the current reached set * @param errorPath the current error path * @returns true, if the value-analysis refinement was successful, else false * @throws CPAException when value-analysis interpolation fails *//*from w w w . jav a 2 s . c om*/ private boolean performValueAnalysisRefinement(final ARGReachedSet reached, final ARGPath errorPath) throws CPAException, InterruptedException { numberOfValueAnalysisRefinements++; UnmodifiableReachedSet reachedSet = reached.asReachedSet(); Precision precision = reachedSet.getPrecision(reachedSet.getLastState()); VariableTrackingPrecision apronPrecision = (VariableTrackingPrecision) Precisions.asIterable(precision) .filter(VariableTrackingPrecision.isMatchingCPAClass(ApronCPA.class)).get(0); VariableTrackingPrecision refinedApronPrecision; Pair<ARGState, CFAEdge> refinementRoot; Multimap<CFANode, MemoryLocation> increment = interpolatingRefiner.determinePrecisionIncrement(errorPath); refinementRoot = interpolatingRefiner.determineRefinementRoot(errorPath, increment, false); // no increment - value-analysis refinement was not successful if (increment.isEmpty()) { return false; } // if two subsequent refinements are similar (based on some fancy heuristic), choose a different refinement root if (checkForRepeatedRefinements && isRepeatedRefinement(increment, refinementRoot)) { refinementRoot = interpolatingRefiner.determineRefinementRoot(errorPath, increment, true); } refinedApronPrecision = apronPrecision.withIncrement(increment); if (valueAnalysisRefinementWasSuccessful(errorPath, apronPrecision, refinedApronPrecision)) { numberOfSuccessfulValueAnalysisRefinements++; reached.removeSubtree(refinementRoot.getFirst(), refinedApronPrecision, VariableTrackingPrecision.isMatchingCPAClass(ApronCPA.class)); return true; } else { return false; } }
From source file:co.cask.cdap.internal.app.verification.FlowVerification.java
/** * Verifies a single {@link FlowSpecification} for a {@link co.cask.cdap.api.flow.Flow}. * * @param input to be verified//from w w w.j a v a 2s.c om * @return An instance of {@link VerifyResult} depending of status of verification. */ @Override public VerifyResult verify(Id.Application appId, final FlowSpecification input) { VerifyResult verifyResult = super.verify(appId, input); if (!verifyResult.isSuccess()) { return verifyResult; } String flowName = input.getName(); // Check if there are no flowlets. if (input.getFlowlets().isEmpty()) { return VerifyResult.failure(Err.Flow.ATLEAST_ONE_FLOWLET, flowName); } // Check if there no connections. if (input.getConnections().isEmpty()) { return VerifyResult.failure(Err.Flow.ATLEAST_ONE_CONNECTION, flowName); } // We go through each Flowlet and verify the flowlets. // First collect all source flowlet names Set<String> sourceFlowletNames = Sets.newHashSet(); for (FlowletConnection connection : input.getConnections()) { if (connection.getSourceType() == FlowletConnection.Type.FLOWLET) { sourceFlowletNames.add(connection.getSourceName()); } } for (Map.Entry<String, FlowletDefinition> entry : input.getFlowlets().entrySet()) { FlowletDefinition defn = entry.getValue(); String flowletName = defn.getFlowletSpec().getName(); // Check if the Flowlet Name is an ID. if (!isId(defn.getFlowletSpec().getName())) { return VerifyResult.failure(Err.NOT_AN_ID, flowName + ":" + flowletName); } // We check if all the dataset names used are ids for (String dataSet : defn.getDatasets()) { if (!isId(dataSet)) { return VerifyResult.failure(Err.NOT_AN_ID, flowName + ":" + flowletName + ":" + dataSet); } } // Check if the flowlet has output, it must be appear as source flowlet in at least one connection if (entry.getValue().getOutputs().size() > 0 && !sourceFlowletNames.contains(flowletName)) { return VerifyResult.failure(Err.Flow.OUTPUT_NOT_CONNECTED, flowName, flowletName); } } // NOTE: We should unify the logic here and the queue spec generation, as they are doing the same thing. Table<QueueSpecificationGenerator.Node, String, Set<QueueSpecification>> queueSpecTable = new SimpleQueueSpecificationGenerator( appId).create(input); // For all connections, there should be an entry in the table. for (FlowletConnection connection : input.getConnections()) { QueueSpecificationGenerator.Node node = new QueueSpecificationGenerator.Node(connection.getSourceType(), connection.getSourceName()); if (!queueSpecTable.contains(node, connection.getTargetName())) { return VerifyResult.failure(Err.Flow.NO_INPUT_FOR_OUTPUT, flowName, connection.getTargetName(), connection.getSourceType(), connection.getSourceName()); } } // For each output entity, check for any unconnected output for (QueueSpecificationGenerator.Node node : queueSpecTable.rowKeySet()) { // For stream output, no need to check if (node.getType() == FlowletConnection.Type.STREAM) { continue; } // For all outputs of a flowlet, remove all the matched connected schema, if there is anything left, // then it's a incomplete flow connection (has output not connect to any input). Multimap<String, Schema> outputs = toMultimap(input.getFlowlets().get(node.getName()).getOutputs()); for (Map.Entry<String, Set<QueueSpecification>> entry : queueSpecTable.row(node).entrySet()) { for (QueueSpecification queueSpec : entry.getValue()) { outputs.remove(queueSpec.getQueueName().getSimpleName(), queueSpec.getOutputSchema()); } } if (!outputs.isEmpty()) { return VerifyResult.failure(Err.Flow.MORE_OUTPUT_NOT_ALLOWED, flowName, node.getType().toString().toLowerCase(), node.getName(), outputs); } } return VerifyResult.success(); }
From source file:org.sosy_lab.cpachecker.cpa.apron.refiner.ApronDelegatingRefiner.java
/** * This method performs an value-analysis refinement. * * @param reached the current reached set * @param errorPath the current error path * @returns true, if the value-analysis refinement was successful, else false * @throws CPAException when value-analysis interpolation fails * @throws InvalidConfigurationException *///from w w w . j a v a 2 s . com private boolean performValueAnalysisRefinement(final ARGReachedSet reached, final MutableARGPath errorPath) throws CPAException, InterruptedException { numberOfValueAnalysisRefinements++; UnmodifiableReachedSet reachedSet = reached.asReachedSet(); Precision precision = reachedSet.getPrecision(reachedSet.getLastState()); VariableTrackingPrecision apronPrecision = (VariableTrackingPrecision) Precisions.asIterable(precision) .filter(VariableTrackingPrecision.isMatchingCPAClass(ApronCPA.class)).get(0); VariableTrackingPrecision refinedApronPrecision; Pair<ARGState, CFAEdge> refinementRoot; Multimap<CFANode, MemoryLocation> increment = interpolatingRefiner.determinePrecisionIncrement(errorPath); refinementRoot = interpolatingRefiner.determineRefinementRoot(errorPath, increment, false); // no increment - value-analysis refinement was not successful if (increment.isEmpty()) { return false; } // if two subsequent refinements are similar (based on some fancy heuristic), choose a different refinement root if (checkForRepeatedRefinements && isRepeatedRefinement(increment, refinementRoot)) { refinementRoot = interpolatingRefiner.determineRefinementRoot(errorPath, increment, true); } refinedApronPrecision = apronPrecision.withIncrement(increment); if (valueAnalysisRefinementWasSuccessful(errorPath, apronPrecision, refinedApronPrecision)) { numberOfSuccessfulValueAnalysisRefinements++; reached.removeSubtree(refinementRoot.getFirst(), refinedApronPrecision, VariableTrackingPrecision.isMatchingCPAClass(ApronCPA.class)); return true; } else { return false; } }
From source file:com.tinspx.util.net.Request.java
static StringBuilder append(@NonNull StringBuilder sb, @Nullable Multimap<String, String> map, @NonNull Escaper escaper) {/*ww w . j av a 2 s .c o m*/ if (map == null || map.isEmpty()) { return sb; } boolean first = true; for (Map.Entry<String, String> entry : map.entries()) { if (sb.length() > 0 || !first) { sb.append('&'); } first = false; sb.append(escaper.escape(entry.getKey())); if (entry.getValue() != null) { sb.append('='); sb.append(escaper.escape(entry.getValue())); } } return sb; }
From source file:com.b2international.snowowl.snomed.datastore.converter.InactivationExpander.java
void expand(List<T> results, Set<String> componentIds) { if (componentIds.isEmpty()) { return;//ww w . j a v a 2s.c om } final List<String> refSetIds = newArrayList(); for (final AssociationType associationType : AssociationType.values()) { refSetIds.add(associationType.getConceptId()); } refSetIds.add(inactivationIndicatorId); final SnomedReferenceSetMembers members = SnomedRequests.prepareSearchMember().all() .filterByRefSet(refSetIds).filterByReferencedComponent(componentIds).filterByActive(true).build() .execute(context); if (members.getItems().isEmpty()) { return; } final Multimap<String, SnomedReferenceSetMember> membersByReferencedComponentId = Multimaps.index(members, new Function<SnomedReferenceSetMember, String>() { @Override public String apply(SnomedReferenceSetMember input) { return input.getReferencedComponent().getId(); } }); for (T result : results) { final Collection<SnomedReferenceSetMember> referringMembers = membersByReferencedComponentId .get(result.getId()); final List<SnomedReferenceSetMember> associationMembers = newArrayList(); final List<SnomedReferenceSetMember> inactivationMembers = newArrayList(); for (SnomedReferenceSetMember referringMember : referringMembers) { if (SnomedRefSetType.ASSOCIATION.equals(referringMember.type())) { associationMembers.add(referringMember); } else if (SnomedRefSetType.ATTRIBUTE_VALUE.equals(referringMember.type())) { inactivationMembers.add(referringMember); } } if (!inactivationMembers.isEmpty()) { final String valueId = (String) Iterables.getFirst(inactivationMembers, null).getProperties() .get(SnomedRf2Headers.FIELD_VALUE_ID); setInactivationIndicator(result, valueId); } Multimap<AssociationType, String> associationTargets = HashMultimap.create(); for (SnomedReferenceSetMember associationMember : associationMembers) { AssociationType type = AssociationType.getByConceptId(associationMember.getReferenceSetId()); final SnomedCoreComponent target = (SnomedCoreComponent) associationMember.getProperties() .get(SnomedRf2Headers.FIELD_TARGET_COMPONENT); associationTargets.put(type, target.getId()); } if (!associationTargets.isEmpty()) { setAssociationTargets(result, associationTargets); } } }
From source file:com.b2international.snowowl.datastore.server.snomed.merge.rules.SnomedRefsetMemberReferencingDetachedComponentRule.java
@Override public Collection<MergeConflict> validate(CDOTransaction transaction) { List<MergeConflict> conflicts = newArrayList(); // If SNOMED CT components were detached on target, but SNOMED CT reference set members are referencing them on source branch: Map<String, String> idToComponentTypeMap = newHashMap(); for (Component component : getDetachedObjects(transaction, Component.class)) { idToComponentTypeMap.put(component.getId(), component.eClass().getName()); }//w w w.j a va 2s . c o m if (!idToComponentTypeMap.isEmpty()) { // if there was any detached Component on target branch final Set<String> detachedMemberIds = FluentIterable .from(getDetachedObjects(transaction, SnomedRefSetMember.class)) .transform(MEMBER_TO_ID_FUNCTION).toSet(); final SnomedReferenceSetMembers membersReferencingDetachedComponents = SnomedRequests .prepareSearchMember().filterByReferencedComponent(idToComponentTypeMap.keySet()).all() .build(SnomedDatastoreActivator.REPOSITORY_UUID, BranchPathUtils.createPath(transaction).getPath()) .execute(getEventBus()).getSync(); for (SnomedReferenceSetMember member : membersReferencingDetachedComponents) { if (!detachedMemberIds.contains(member.getId())) { conflicts.add(MergeConflictImpl.builder().componentId(member.getReferencedComponent().getId()) .componentType(idToComponentTypeMap.get(member.getReferencedComponent().getId())) .type(ConflictType.CAUSES_MISSING_REFERENCE).build()); } } } // If SNOMED CT components were detached on source, but SNOMED CT reference set members are referencing them on target: Multimap<String, Pair<String, String>> referencedComponentIdToRefsetMemberMap = HashMultimap .<String, Pair<String, String>>create(); for (SnomedRefSetMember member : getNewObjects(transaction, SnomedRefSetMember.class)) { referencedComponentIdToRefsetMemberMap.put(member.getReferencedComponentId(), Pair.<String, String>of(member.eClass().getName(), member.getUuid())); } if (!referencedComponentIdToRefsetMemberMap.isEmpty()) { // if there was any new reference set member on target Set<String> conceptIds = newHashSet(FluentIterable.from(getNewObjects(transaction, Concept.class)) .transform(COMPONENT_TO_ID_FUNCTION).toSet()); Set<String> descriptionIds = newHashSet( FluentIterable.from(getNewObjects(transaction, Description.class)) .transform(COMPONENT_TO_ID_FUNCTION).toSet()); Set<String> relationshipIds = newHashSet( FluentIterable.from(getNewObjects(transaction, Relationship.class)) .transform(COMPONENT_TO_ID_FUNCTION).toSet()); String branchPath = BranchPathUtils.createPath(transaction).getPath(); Set<String> referencedComponentIds = referencedComponentIdToRefsetMemberMap.keySet(); Set<String> referencedConceptIds = referencedComponentIds.stream() .filter(id -> SnomedIdentifiers.getComponentCategory(id) == ComponentCategory.CONCEPT) .collect(toSet()); Set<String> referencedRelationshipIds = referencedComponentIds.stream() .filter(id -> SnomedIdentifiers.getComponentCategory(id) == ComponentCategory.RELATIONSHIP) .collect(toSet()); Set<String> referencedDescriptionIds = referencedComponentIds.stream() .filter(id -> SnomedIdentifiers.getComponentCategory(id) == ComponentCategory.DESCRIPTION) .collect(toSet()); if (!referencedConceptIds.isEmpty()) { conceptIds .addAll(FluentIterable .from(SnomedRequests.prepareSearchConcept().filterByIds(referencedConceptIds) .setLimit(referencedConceptIds.size()) .build(SnomedDatastoreActivator.REPOSITORY_UUID, branchPath) .execute(getEventBus()).getSync()) .transform(IComponent.ID_FUNCTION).toSet()); } if (!referencedDescriptionIds.isEmpty()) { descriptionIds.addAll(FluentIterable.from(SnomedRequests.prepareSearchDescription() .filterByIds(referencedDescriptionIds).setLimit(referencedDescriptionIds.size()) .build(SnomedDatastoreActivator.REPOSITORY_UUID, branchPath).execute(getEventBus()) .getSync()).transform(IComponent.ID_FUNCTION).toSet()); } if (!referencedRelationshipIds.isEmpty()) { relationshipIds.addAll(FluentIterable.from(SnomedRequests.prepareSearchRelationship() .filterByIds(referencedRelationshipIds).setLimit(referencedRelationshipIds.size()) .build(SnomedDatastoreActivator.REPOSITORY_UUID, branchPath).execute(getEventBus()) .getSync()).transform(IComponent.ID_FUNCTION).toSet()); } Set<String> missingConceptIds = Sets.difference(referencedComponentIds, Sets.union(Sets.union(conceptIds, descriptionIds), relationshipIds)); for (String id : missingConceptIds) { for (Pair<String, String> entry : referencedComponentIdToRefsetMemberMap.get(id)) { conflicts .add(MergeConflictImpl.builder().componentId(entry.getB()).componentType(entry.getA()) .conflictingAttribute(ConflictingAttributeImpl.builder() .property("referencedComponent").value(id).build()) .type(ConflictType.HAS_MISSING_REFERENCE).build()); } } } return conflicts; }