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);
     }
   }
 }
 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);
 }
  private ListMultimap<Artifact, DependencyNode> collectDependencyNotFoundData(
      List<Exception> exceptionList, Class<? extends DependencyNotFoundException> exceptionType) {
    ListMultimap<Artifact, DependencyNode> artifactNotFoundMap = ArrayListMultimap.create();

    ListIterator<Exception> exceptionIterator = exceptionList.listIterator();
    while (exceptionIterator.hasNext()) {
      Exception e = exceptionIterator.next();
      if (e.getClass().equals(exceptionType)) {
        DependencyNode from = exceptionType.cast(e).getDependencyNode();
        artifactNotFoundMap.put(exceptionType.cast(e).getMissingArtifact(), from);
        exceptionIterator.remove();
      }
    }
    return artifactNotFoundMap;
  }
  private static void collectFiredRules(
      ListMultimap<String, SimpleRule> firedRules, Rule rule, EvaluationContext context) {
    Predicate predicate = rule.getPredicate();
    if (predicate == null) {
      throw new InvalidFeatureException(rule);
    }

    Boolean status = PredicateUtil.evaluate(predicate, context);
    if (status == null || !status.booleanValue()) {
      return;
    } // End if

    if (rule instanceof SimpleRule) {
      SimpleRule simpleRule = (SimpleRule) rule;

      firedRules.put(simpleRule.getScore(), simpleRule);
    } else if (rule instanceof CompoundRule) {
      CompoundRule compoundRule = (CompoundRule) rule;

      List<Rule> childRules = compoundRule.getRules();
      for (Rule childRule : childRules) {
        collectFiredRules(firedRules, childRule, context);
      }
    }
  }
  /** 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) {
    }
  }
Beispiel #6
0
 @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);
 }
Beispiel #7
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);
 }
Beispiel #8
0
  private void init(
      PName name,
      PTableType type,
      long timeStamp,
      long sequenceNumber,
      String pkName,
      List<PColumn> columns,
      PTableStats stats) {
    this.name = name;
    this.type = type;
    this.timeStamp = timeStamp;
    this.sequenceNumber = sequenceNumber;
    this.columnsByName = ArrayListMultimap.create(columns.size(), 1);
    this.pkName = pkName;
    List<PColumn> pkColumns = Lists.newArrayListWithExpectedSize(columns.size() - 1);
    PColumn[] allColumns = new PColumn[columns.size()];
    RowKeySchemaBuilder builder = new RowKeySchemaBuilder();
    for (int i = 0; i < allColumns.length; i++) {
      PColumn column = columns.get(i);
      allColumns[column.getPosition()] = column;
      PName familyName = column.getFamilyName();
      if (familyName == null) {
        pkColumns.add(column);
        builder.addField(column);
      }
      columnsByName.put(column.getName().getString(), column);
    }
    this.pkColumns = ImmutableList.copyOf(pkColumns);
    this.rowKeySchema = builder.setMinNullable(pkColumns.size()).build();
    this.allColumns = ImmutableList.copyOf(allColumns);

    // Two pass so that column order in column families matches overall column order
    // and to ensure that column family order is constant
    int maxExpectedSize = allColumns.length - pkColumns.size();
    // Maintain iteration order so that column families are ordered as they are listed
    Map<PName, List<PColumn>> familyMap = Maps.newLinkedHashMap();
    for (PColumn column : allColumns) {
      PName familyName = column.getFamilyName();
      if (familyName != null) {
        List<PColumn> columnsInFamily = familyMap.get(familyName);
        if (columnsInFamily == null) {
          columnsInFamily = Lists.newArrayListWithExpectedSize(maxExpectedSize);
          familyMap.put(familyName, columnsInFamily);
        }
        columnsInFamily.add(column);
      }
    }

    Iterator<Map.Entry<PName, List<PColumn>>> iterator = familyMap.entrySet().iterator();
    PColumnFamily[] families = new PColumnFamily[familyMap.size()];
    ImmutableMap.Builder<String, PColumnFamily> familyByString = ImmutableMap.builder();
    ImmutableSortedMap.Builder<byte[], PColumnFamily> familyByBytes =
        ImmutableSortedMap.orderedBy(Bytes.BYTES_COMPARATOR);
    for (int i = 0; i < families.length; i++) {
      Map.Entry<PName, List<PColumn>> entry = iterator.next();
      PColumnFamily family = new PColumnFamilyImpl(entry.getKey(), entry.getValue());
      families[i] = family;
      familyByString.put(family.getName().getString(), family);
      familyByBytes.put(family.getName().getBytes(), family);
    }
    this.families = ImmutableList.copyOf(families);
    this.familyByBytes = familyByBytes.build();
    this.familyByString = familyByString.build();
    this.stats = stats;
  }
  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);
  }