private void reportMissingDependencies( String type, ListMultimap<Artifact, DependencyNode> artifactNotFoundMap, ReportEntryType reportEntryType, TestSetStats testSuite) { for (Artifact artifact : sortArtifacts(artifactNotFoundMap.keySet())) { List<DependencyNode> roots = sortDependencyNodes(artifactNotFoundMap.get(artifact)); if (roots.size() == 1) { String msg = "Miss " + artifact + " in " + roots.get(0).getArtifact() + " (path " + findPathToDependency(artifact, roots.get(0)) + ")"; reportTestCase(type, reportEntryType, msg, null, testSuite); } else { String msg = "Miss " + artifact + " in " + roots.size() + " artifacts ..."; StringBuilder dsc = new StringBuilder(); dsc.append("Miss " + artifact + " in ..."); dsc.append(LINE_SEPARATOR).append(LINE_SEPARATOR); for (DependencyNode root : roots) { dsc.append(root.getArtifact() + " (path " + findPathToDependency(artifact, root) + ")"); dsc.append(LINE_SEPARATOR).append(LINE_SEPARATOR); } reportTestCase(type, reportEntryType, msg, dsc.toString(), testSuite); } } }
/** Test throwing ConcurrentModificationException when a sublist's ancestor's delegate changes. */ public void testSublistConcurrentModificationException() { ListMultimap<String, Integer> multimap = create(); multimap.putAll("foo", asList(1, 2, 3, 4, 5)); List<Integer> list = multimap.get("foo"); ASSERT.that(multimap.get("foo")).hasContentsInOrder(1, 2, 3, 4, 5); List<Integer> sublist = list.subList(0, 5); ASSERT.that(sublist).hasContentsInOrder(1, 2, 3, 4, 5); sublist.clear(); assertTrue(sublist.isEmpty()); multimap.put("foo", 6); try { sublist.isEmpty(); fail("Expected ConcurrentModificationException"); } catch (ConcurrentModificationException expected) { } }
public void testConstrainedTypePreservingRandomAccessList() { ListMultimap<String, Integer> multimap = MapConstraints.constrainedListMultimap( ArrayListMultimap.<String, Integer>create(), TEST_CONSTRAINT); multimap.put("foo", 1); Map.Entry<String, Collection<Integer>> entry = multimap.asMap().entrySet().iterator().next(); assertTrue(entry.getValue() instanceof List); assertFalse(multimap.entries() instanceof Set); assertTrue(multimap.get("foo") instanceof RandomAccess); }
@Override public PColumn getPKColumn(String name) throws ColumnNotFoundException { List<PColumn> columns = columnsByName.get(name); int size = columns.size(); if (size == 0) { throw new ColumnNotFoundException(name); } if (size > 1) { do { PColumn column = columns.get(--size); if (column.getFamilyName() == null) { return column; } } while (size > 0); throw new ColumnNotFoundException(name); } return columns.get(0); }
@Override public PColumn getColumn(String name) throws ColumnNotFoundException, AmbiguousColumnException { List<PColumn> columns = columnsByName.get(name); int size = columns.size(); if (size == 0) { throw new ColumnNotFoundException(name); } if (size > 1) { for (PColumn column : columns) { if (QueryConstants.DEFAULT_COLUMN_FAMILY.equals(column.getFamilyName().getString())) { // Allow ambiguity with default column, since a user would not know how to prefix it. return column; } } throw new AmbiguousColumnException(name); } return columns.get(0); }
private Map<FieldName, ? extends ClassificationMap<?>> evaluateRuleSet( ModelManagerEvaluationContext context) { RuleSetModel ruleSetModel = getModel(); RuleSet ruleSet = ruleSetModel.getRuleSet(); List<RuleSelectionMethod> ruleSelectionMethods = ruleSet.getRuleSelectionMethods(); RuleSelectionMethod ruleSelectionMethod; // "If more than one method is included, the first method is used as the default method for // scoring" if (ruleSelectionMethods.size() > 0) { ruleSelectionMethod = ruleSelectionMethods.get(0); } else { throw new InvalidFeatureException(ruleSet); } // Both the ordering of keys and values is significant ListMultimap<String, SimpleRule> firedRules = LinkedListMultimap.create(); List<Rule> rules = ruleSet.getRules(); for (Rule rule : rules) { collectFiredRules(firedRules, rule, context); } RuleClassificationMap result = new RuleClassificationMap(); RuleSelectionMethod.Criterion criterion = ruleSelectionMethod.getCriterion(); Set<String> keys = firedRules.keySet(); for (String key : keys) { List<SimpleRule> keyRules = firedRules.get(key); switch (criterion) { case FIRST_HIT: { SimpleRule winner = keyRules.get(0); // The first value of the first key if (result.getEntity() == null) { result.setEntity(winner); } result.put(key, winner.getConfidence()); } break; case WEIGHTED_SUM: { SimpleRule winner = null; double totalWeight = 0; for (SimpleRule keyRule : keyRules) { if (winner == null || (winner.getWeight() < keyRule.getWeight())) { winner = keyRule; } totalWeight += keyRule.getWeight(); } result.put(winner, key, totalWeight / firedRules.size()); } break; case WEIGHTED_MAX: { SimpleRule winner = null; for (SimpleRule keyRule : keyRules) { if (winner == null || (winner.getWeight() < keyRule.getWeight())) { winner = keyRule; } } result.put(winner, key, winner.getConfidence()); } break; default: throw new UnsupportedFeatureException(ruleSelectionMethod, criterion); } } return TargetUtil.evaluateClassification(result, context); }