Example usage for org.apache.commons.collections.bag HashBag add

List of usage examples for org.apache.commons.collections.bag HashBag add

Introduction

In this page you can find the example usage for org.apache.commons.collections.bag HashBag add.

Prototype

public boolean add(Object object, int nCopies) 

Source Link

Document

Adds a new element to the bag, incrementing its count in the map.

Usage

From source file:TasteOfThingsV1.java

 public static void main(String args[]) throws Exception {
   prepareData();//w w  w  . jav a  2s  . co m

   HashBag myBag = new HashBag(testMap.values());

   System.err.println("How many Boxes? " + myBag.getCount("Boxes"));
   myBag.add("Boxes", 5);
   System.err.println("How many Boxes now? " + myBag.getCount("Boxes"));

   Method method =
     testBean.getClass().getDeclaredMethod("getTestMap", new Class[0]);
   HashMap reflectionMap =
     (HashMap)method.invoke(testBean, new Object[0]);
   System.err.println("The value of the 'squ' key using reflection: " +
     reflectionMap.get("squ"));

   String squ = BeanUtils.getMappedProperty(testBean, "testMap", "squ");
   squ = StringUtils.capitalize(squ);

   PropertyUtils.setMappedProperty(testBean, "testMap", "squ", squ);

   System.err.println("The value of the 'squ' key is: " +
     BeanUtils.getMappedProperty(testBean, "testMap", "squ"));

   String box = (String)testMap.get("box");
   String caps =
     Character.toTitleCase(box.charAt(0)) +
     box.substring(1, box.length());
   System.err.println("Capitalizing boxes by Java: " + caps);
}