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

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

Introduction

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

Prototype

public int getCount(Object object) 

Source Link

Document

Returns the number of occurrence of the given element in this bag by looking up its count in the underlying map.

Usage

From source file:TasteOfThingsV1.java

 public static void main(String args[]) throws Exception {
   prepareData();/*from  w w  w  . j av a 2s .c  o  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);
}