Package org.apache.commons.collections.bag

Examples of org.apache.commons.collections.bag.HashBag


            // expected
       
    }
   
    public void testTypedBag() {
        Bag bag = BagUtils.typedBag(new HashBag(), stringClass);     
        assertTrue("Returned object should be a TypedBag.",
            bag instanceof PredicatedBag);
        try {
            bag = BagUtils.typedBag(null, stringClass);
            fail("Expecting IllegalArgumentException for null bag.");
        } catch (IllegalArgumentException ex) {
            // expected
        }
        try {
            bag = BagUtils.typedBag(new HashBag(), null);
            fail("Expecting IllegalArgumentException for null type.");
        } catch (IllegalArgumentException ex) {
            // expected
       
    }
View Full Code Here


            // expected
       
    }
   
     public void testTransformedBag() {
        Bag bag = BagUtils.transformedBag(new HashBag(), nopTransformer);     
        assertTrue("Returned object should be an TransformedBag.",
            bag instanceof TransformedBag);
        try {
            bag = BagUtils.transformedBag(null, nopTransformer);     
            fail("Expecting IllegalArgumentException for null bag.");
        } catch (IllegalArgumentException ex) {
            // expected
        }
        try {
            bag = BagUtils.transformedBag(new HashBag(), null)
            fail("Expecting IllegalArgumentException for null transformer.");
        } catch (IllegalArgumentException ex) {
            // expected
       
    }
View Full Code Here

            Set set = new HashSet();
            set.addAll((Set) col);
            return set;
        }
        else if (col instanceof Bag) {
            Bag bag = new HashBag();
            bag.addAll((Bag) col);
            return bag;
        }
        else {
            throw new IllegalArgumentException("Cannot clone collections of type: " + col.getClass().getName());
        }
View Full Code Here

       
        // Instantiate members for the other select()
        TypeExpr[] typePieces = gemType.getTypePieces();
        TypeExpr outputType = typePieces[typePieces.length - 1];

        Bag remainingInputTypes = new HashBag(Arrays.asList(typePieces));
        remainingInputTypes.remove(outputType, 1);

        return select(new ArrayList<TypeExpr>(), remainingInputTypes, outputType);
    }
View Full Code Here

        // Now check if we should call ourselves recursively..
        if (numInputsToTry < filterInputTypes.length) {

            // Create a set that represents the remaining input types that will be passed down to the next level.
            Bag remainingInputTypesArg = new HashBag(remainingInputTypes);

            for (Iterator it = remainingInputTypes.iterator(); it.hasNext(); ) {

                TypeExpr nextType = (TypeExpr)it.next();

                inputTypesToTry.add(nextType);
                remainingInputTypesArg.remove(nextType, 1);

                // recursive call.
                if (select(inputTypesToTry, remainingInputTypesArg, outputTypeToTry)) {
                    return true;
                }

                inputTypesToTry.remove(numInputsToTry);
                remainingInputTypesArg.add(nextType);
            }

            // none of the matching succeeded.
            return false;
View Full Code Here

  protected Metrics getMetricKey() {
    return Metrics.COMPLEXITY_CLASSES_COUNT_DISTRIBUTION;
  }
 
  public void execute(Module module, List<Module> directSubmodules) {
    HashBag countByRange = new HashBag();

    if (directSubmodules == null || directSubmodules.isEmpty()) {
      for (MeasureKey key : module.getMeasureKeys()) {
        if (key.getFile() != null && key.getMetric().equals(getMetric(Metrics.CYCLOMATIC_COMPLEXITY))) {
          int ccn = module.getMeasureValue(key).intValue();
          countByRange.add(getComplexityRange(ccn));
        }
      }
    } else {
      for (Module submodule : directSubmodules) {
        for (MeasureKey key : submodule.getMeasureKeys()) {
          if (key.getFile() == null && key.getMetric().equals(getMetric())) {
            ProjectMeasure measure = (ProjectMeasure) submodule.getMeasure(key);
            int range = Integer.parseInt(measure.getSubkey());
            countByRange.add(range, measure.getValue().intValue());
          }
        }
      }
    }
View Full Code Here

        assertEquals(0, CollectionUtils.cardinality("B", set));
        assertEquals(1, CollectionUtils.cardinality("C", set));
        assertEquals(0, CollectionUtils.cardinality("D", set));
        assertEquals(1, CollectionUtils.cardinality("E", set));

        Bag bag = new HashBag();
        bag.add("A", 3);
        bag.add("C");
        bag.add("E");
        bag.add("E");
        assertEquals(3, CollectionUtils.cardinality("A", bag));
        assertEquals(0, CollectionUtils.cardinality("B", bag));
        assertEquals(1, CollectionUtils.cardinality("C", bag));
        assertEquals(0, CollectionUtils.cardinality("D", bag));
        assertEquals(2, CollectionUtils.cardinality("E", bag));
View Full Code Here

        // Enumeration, non-existent entry -- "dead" enumerator returned
        test = CollectionUtils.index(en,3);
        assertTrue(test.equals(en) && !en.hasMoreElements());
       
        // Collection, entry exists
        Bag bag = new HashBag();
        bag.add("element", 1);
        test = CollectionUtils.index(bag, 0);
        assertTrue(test.equals("element"));
       
        // Collection, non-existent entry -- "dead" iterator returned
        test = CollectionUtils.index(bag, 2);
View Full Code Here

            assertTrue(!en.hasMoreElements());
        }
       
        {
            // Collection, entry exists
            Bag bag = new HashBag();
            bag.add("element", 1);
            assertEquals("element",CollectionUtils.get(bag, 0));
       
            // Collection, non-existent entry
            try {
                CollectionUtils.get(bag, 1);
View Full Code Here

    protected Transformer nopTransformer = TransformerUtils.nopTransformer();
   
    //----------------------------------------------------------------------
   
    public void testSynchronizedBag() {
        Bag bag = BagUtils.synchronizedBag(new HashBag());
        assertTrue("Returned object should be a SynchronizedBag.",
            bag instanceof SynchronizedBag);
        try {
            bag = BagUtils.synchronizedBag(null);
            fail("Expecting IllegalArgumentException for null bag.");
View Full Code Here

TOP

Related Classes of org.apache.commons.collections.bag.HashBag

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.