Java Code Examples for com.google.common.collect.SetMultimap#isEmpty()

The following examples show how to use com.google.common.collect.SetMultimap#isEmpty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HtmlReport.java    From sailfish-core with Apache License 2.0 6 votes vote down vote up
private void writeReportKnownBugsTable(SetMultimap<String, BugDescription> allKnownBugsMap, SetMultimap<String, BugDescription> reproducedBugsMap, Writer reportWriter) throws IOException, TemplateException {
    if(allKnownBugsMap.isEmpty()) {
        return;
    }

    ReportTable table = new ReportTable(KNOWN_BUGS_TABLE_NAME, Arrays.asList("Test Case", BUG_CATEGORY_COLUMN_NAME, REPRODUCED_COLUMN_NAME, NOT_REPRODUCED_COLUMN_NAME));

    for(String testCaseDescription : allKnownBugsMap.keySet()) {
        Set<BugDescription> allKnownBugs = allKnownBugsMap.get(testCaseDescription);
        Set<BugDescription> reproducedBugs = reproducedBugsMap.get(testCaseDescription);

        List<Map<String, String>> rows = fillKnowBugTable(allKnownBugs, reproducedBugs);
        if (!rows.isEmpty()) {
            rows.get(0).put("Test Case", testCaseDescription);
            table.addRows(rows);
        }
    }

    writeTable(reportWriter, StatusType.NA, table, 4);
}
 
Example 2
Source File: FullMessageEntityValidator.java    From sailfish-core with Apache License 2.0 6 votes vote down vote up
private void checkUniqueness(List<DictionaryValidationError> errors, IMessageStructure message) {

        SetMultimap<String, String> duplicates = HashMultimap.create();

        checkFields(message, duplicates);

        if (!duplicates.isEmpty()) {
            for (String fieldName : duplicates.keySet()) {
                if (duplicates.get(fieldName).size() > 1) {
                    StringBuilder error = new StringBuilder(
                            String.format("Field <strong>[%s]</strong> in <strong>[%s]</strong> message duplicated in ",
                                    fieldName, message.getName()));
                    for (Iterator<String> i = duplicates.get(fieldName).iterator(); i.hasNext();) {
                        error.append(String.format("<strong>[%s]</strong>", i.next()));
                        if (i.hasNext()) {
                            error.append(", ");
                        }
                    }
                    errors.add(new DictionaryValidationError(message.getName(), fieldName, error.toString(),
                            DictionaryValidationErrorLevel.MESSAGE, DictionaryValidationErrorType.ERR_DUPLICATE_NAME));
                }
            }
        }
    }
 
Example 3
Source File: BaggageImpl.java    From tracing-framework with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/** Constructs a {@link BaggageMessage} protobuf message with the contents of this baggage. If this baggage is
 * empty, returns null */
BaggageMessage buildMessage() {
    // Call baggage handlers
    Handlers.preSerialize(this);
    
    // Construct message
    BaggageMessage.Builder b = BaggageMessage.newBuilder();
    for (ByteString namespace : contents.keySet()) {
        SetMultimap<ByteString, ByteString> namespaceData = contents.get(namespace);

        // Namespace should not exist if it has no data
        if (namespaceData.isEmpty()) {
            continue;
        }

        // Construct the namespace data message
        NamespaceData.Builder nb = b.addNamespaceBuilder().setKey(namespace);
        for (ByteString key : namespaceData.keySet()) {
            nb.addBagBuilder().setKey(key).addAllValue(namespaceData.get(key));
        }
    }

    // Return null if the baggage message is empty
    return b.getNamespaceCount() == 0 ? null : b.build();
}
 
Example 4
Source File: ConditionalEdges.java    From bazel with Apache License 2.0 6 votes vote down vote up
/** Builds ConditionalEdges from given graph. */
public ConditionalEdges(Digraph<Target> graph) {
  this.map = new HashMap<>();

  for (Node<Target> node : graph.getNodes()) {
    Rule rule = node.getLabel().getAssociatedRule();
    if (rule == null) {
      // rule is null for source files and package groups. Skip them.
      continue;
    }

    SetMultimap<Label, Label> conditions = getAllConditions(rule, RawAttributeMapper.of(rule));
    if (conditions.isEmpty()) {
      // bail early for most common case of no conditions in the rule.
      continue;
    }

    Label nodeLabel = node.getLabel().getLabel();
    for (Node<Target> succ : node.getSuccessors()) {
      Label successorLabel = succ.getLabel().getLabel();
      if (conditions.containsKey(successorLabel)) {
        insert(nodeLabel, successorLabel, conditions.get(successorLabel));
      }
    }
  }
}
 
Example 5
Source File: ObservableSetMultimapWrapper.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void clear() {
	SetMultimap<K, V> previousContents = delegateCopy();
	super.clear();
	if (!previousContents.isEmpty()) {
		List<ElementarySubChange<K, V>> elementaryChanges = new ArrayList<>();
		for (K key : previousContents.keySet()) {
			elementaryChanges.add(new ElementarySubChange<>(key,
					previousContents.get(key), Collections.<V> emptySet()));
		}
		helper.fireValueChangedEvent(
				new SetMultimapListenerHelper.AtomicChange<>(this,
						previousContents, elementaryChanges));
	}
}
 
Example 6
Source File: ShowHiddenNeighborsOfFirstAnchorageOnClickHandler.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void click(MouseEvent e) {
	SetMultimap<IVisualPart<? extends Node>, String> anchorages = getHost().getAnchoragesUnmodifiable();
	if (anchorages == null || anchorages.isEmpty()) {
		return;
	}
	IVisualPart<? extends Node> anchorage = anchorages.keySet().iterator().next();
	ShowHiddenNeighborsPolicy hiddenNeighborsPolicy = anchorage.getAdapter(ShowHiddenNeighborsPolicy.class);
	init(hiddenNeighborsPolicy);
	hiddenNeighborsPolicy.showHiddenNeighbors();
	commit(hiddenNeighborsPolicy);
}
 
Example 7
Source File: HideFirstAnchorageOnClickHandler.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void click(MouseEvent e) {
	SetMultimap<IVisualPart<? extends Node>, String> anchorages = getHost().getAnchoragesUnmodifiable();
	if (anchorages == null || anchorages.isEmpty()) {
		return;
	}
	IVisualPart<? extends Node> anchorage = anchorages.keySet().iterator().next();
	HidePolicy hideNodePolicy = anchorage.getAdapter(HidePolicy.class);
	init(hideNodePolicy);
	hideNodePolicy.hide();
	commit(hideNodePolicy);
}
 
Example 8
Source File: HoverHandleContainerPart.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void doRefreshVisual(VBox visual) {
	// check if we have a host
	SetMultimap<IVisualPart<? extends Node>, String> anchorages = getAnchoragesUnmodifiable();
	if (anchorages.isEmpty()) {
		return;
	}

	// determine center location of host visual
	IVisualPart<? extends Node> anchorage = anchorages.keys()
			.iterator().next();
	refreshHandleLocation(anchorage.getVisual());
}
 
Example 9
Source File: BaggageImpl.java    From tracing-framework with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Construct a baggage instance from the provided BaggageMessage. If the provided message is invalid, null, or
 * empty, this method will return null
 * 
 * @param message A baggagemessage protobuf
 * @return A baggage instance if the provided message is valid and has contents, null otherwise */
static BaggageImpl create(BaggageMessage message) {
    // Check the message is not null and has some namespaces
    if (message == null || message.getNamespaceCount() == 0) {
        return null;
    }

    // Construct the baggage from the received message
    Map<ByteString, SetMultimap<ByteString, ByteString>> data = Maps.newHashMapWithExpectedSize(message.getNamespaceCount());
    for (NamespaceData namespaceData : message.getNamespaceList()) {
        SetMultimap<ByteString, ByteString> namespace = HashMultimap.create(namespaceData.getBagCount(), 1);
        for (BagData bag : namespaceData.getBagList()) {
            namespace.putAll(bag.getKey(), bag.getValueList());
        }
        if (!namespace.isEmpty()) {
            data.put(namespaceData.getKey(), namespace);
        }
    }

    // If there was no data after all, return null
    if (data.isEmpty()) {
        return null;
    }

    BaggageImpl impl = new BaggageImpl(data);
    Handlers.postDeserialize(impl);
    return impl;
}
 
Example 10
Source File: BaggageImpl.java    From tracing-framework with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Remove a key from a specified namespace
 * 
 * @param namespace The namespace the key resides in
 * @param key The key to remove */
public void remove(ByteString namespace, ByteString key) {
    if (namespace != null && key != null) {
        SetMultimap<ByteString, ByteString> namespaceData = contents.get(namespace);
        if (namespaceData != null) {
            namespaceData.removeAll(key);
            if (namespaceData.isEmpty()) {
                contents.remove(namespace);
            }
        }
    }
}
 
Example 11
Source File: BaggageImpl.java    From tracing-framework with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Replace the values for a key with the new provided values. Null keys ignored, while null values treated as
 * removing the key
 * 
 * @param namespace The namespace the provided key resides in, 
 * @param key The key to replace values for
 * @param values These values replace existing values for the key */
public void replace(ByteString namespace, ByteString key, Iterable<? extends ByteString> values) {
    if (namespace != null && key != null) {
        if (values == null) {
            remove(namespace, key);
        } else {
            SetMultimap<ByteString, ByteString> namespaceData = modifyKey(namespace, key);
            namespaceData.putAll(key, values);
            namespaceData.remove(key, null);
            if (namespaceData.isEmpty()) {
                contents.remove(namespace);
            }
        }
    }
}
 
Example 12
Source File: KitParser.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
public AttributeKit parseAttributeKit(Element el) throws InvalidXMLException {
  SetMultimap<String, AttributeModifier> modifiers = parseAttributeModifiers(el);
  attributeModifiers.addAll(modifiers.values());
  return modifiers.isEmpty() ? null : new AttributeKit(modifiers);
}
 
Example 13
Source File: SetMultimapExpression.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public boolean isEmpty() {
	final SetMultimap<K, V> setMultimap = get();
	return (setMultimap == null) ? EMPTY_SETMULTIMAP.isEmpty()
			: setMultimap.isEmpty();
}
 
Example 14
Source File: WaitCoalescer.java    From swift-t with Apache License 2.0 4 votes vote down vote up
/**
 * Try to push down waits from current block into child blocks
 * @param logger
 * @param fn
 * @param block
 * @param currContext
 * @return
 */
private boolean pushDownWaits(Logger logger, Program prog, Function fn,
                              Block block, ExecContext currContext) {
  SetMultimap<Var, InstOrCont> waitMap = buildWaiterMap(prog, block);

  if (logger.isTraceEnabled()) {
    logger.trace("waitMap keys: " + waitMap.keySet());
  }

  if (waitMap.isEmpty()) {
    // If waitMap is empty, can't push anything down, so just shortcircuit
    return false;
  }
  boolean changed = false;

  HashSet<Continuation> allPushedDown = new HashSet<Continuation>();
  ArrayList<Continuation> contCopy =
              new ArrayList<Continuation>(block.getContinuations());
  for (Continuation c: contCopy) {
    if (allPushedDown.contains(c)) {
      // Was moved
      continue;
    }
    ExecContext newContext = canPushDownInto(c, currContext);
    if (newContext != null) {
      for (Block innerBlock: c.getBlocks()) {
        StackLite<Continuation> ancestors =
                                      new StackLite<Continuation>();
        ancestors.push(c);
        PushDownResult pdRes =
             pushDownWaitsRec(logger, fn, block, currContext, ancestors,
                              innerBlock, newContext, waitMap);
         changed = changed || pdRes.anyChanges;
        /* The list of continuations might be modified as continuations are
         * pushed down - track which ones are relocated */
        allPushedDown.addAll(pdRes.relocated);
      }
    }
  }
  return changed;
}