Java Doc for Bag.java in  » Library » Apache-common-Collections » org » apache » commons » collections » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Library » Apache common Collections » org.apache.commons.collections 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


org.apache.commons.collections.Bag

All known Subclasses:   org.apache.commons.collections.bag.AbstractMapBag,  org.apache.commons.collections.bag.SynchronizedBag,  org.apache.commons.collections.bag.HashBag,  org.apache.commons.collections.DefaultMapBag,  org.apache.commons.collections.bag.AbstractBagDecorator,  org.apache.commons.collections.bag.PredicatedBag,  org.apache.commons.collections.HashBag,  org.apache.commons.collections.bag.TransformedBag,
Bag
public interface Bag extends Collection(Code)
Defines a collection that counts the number of times an object appears in the collection.

Suppose you have a Bag that contains {a, a, b, c}. Calling Bag.getCount(Object) on a would return 2, while calling Bag.uniqueSet() would return {a, b, c}.

NOTE: This interface violates the Collection contract. The behavior specified in many of these methods is not the same as the behavior specified by Collection. The noncompliant methods are clearly marked with "(Violation)". Exercise caution when using a bag as a Collection.

This violation resulted from the original specification of this interface. In an ideal world, the interface would be changed to fix the problems, however it has been decided to maintain backwards compatibility instead.
since:
   Commons Collections 2.0
version:
   $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
author:
   Chuck Burdick
author:
   Stephen Colebourne





Method Summary
 booleanadd(Object object)
     (Violation) Adds one copy the specified object to the Bag.

If the object is already in the Bag.uniqueSet() then increment its count as reported by Bag.getCount(Object) .

 booleanadd(Object object, int nCopies)
     Adds nCopies copies of the specified object to the Bag.

If the object is already in the Bag.uniqueSet() then increment its count as reported by Bag.getCount(Object) .

 booleancontainsAll(Collection coll)
     (Violation) Returns true if the bag contains all elements in the given collection, respecting cardinality.
 intgetCount(Object object)
     Returns the number of occurrences (cardinality) of the given object currently in the bag.
 Iteratoriterator()
     Returns an Iterator over the entire set of members, including copies due to cardinality.
 booleanremove(Object object)
     (Violation) Removes all occurrences of the given object from the bag.
 booleanremove(Object object, int nCopies)
     Removes nCopies copies of the specified object from the Bag.
 booleanremoveAll(Collection coll)
     (Violation) Remove all elements represented in the given collection, respecting cardinality.
 booleanretainAll(Collection coll)
     (Violation) Remove any members of the bag that are not in the given collection, respecting cardinality.
 intsize()
     Returns the total number of items in the bag across all types.
 SetuniqueSet()
     Returns a Set of unique elements in the Bag.



Method Detail
add
boolean add(Object object)(Code)
(Violation) Adds one copy the specified object to the Bag.

If the object is already in the Bag.uniqueSet() then increment its count as reported by Bag.getCount(Object) . Otherwise add it to the Bag.uniqueSet() and report its count as 1.

Since this method always increases the size of the bag, according to the Collection.add(Object) contract, it should always return true. Since it sometimes returns false, this method violates the contract.
Parameters:
  object - the object to add true if the object was not already in the uniqueSet




add
boolean add(Object object, int nCopies)(Code)
Adds nCopies copies of the specified object to the Bag.

If the object is already in the Bag.uniqueSet() then increment its count as reported by Bag.getCount(Object) . Otherwise add it to the Bag.uniqueSet() and report its count as nCopies.
Parameters:
  object - the object to add
Parameters:
  nCopies - the number of copies to add true if the object was not already in the uniqueSet




containsAll
boolean containsAll(Collection coll)(Code)
(Violation) Returns true if the bag contains all elements in the given collection, respecting cardinality. That is, if the given collection coll contains n copies of a given object, calling Bag.getCount(Object) on that object must be >= n for all n in coll.

The Collection.containsAll(Collection) method specifies that cardinality should not be respected; this method should return true if the bag contains at least one of every object contained in the given collection.
Parameters:
  coll - the collection to check against true if the Bag contains all the collection




getCount
int getCount(Object object)(Code)
Returns the number of occurrences (cardinality) of the given object currently in the bag. If the object does not exist in the bag, return 0.
Parameters:
  object - the object to search for the number of occurrences of the object, zero if not found



iterator
Iterator iterator()(Code)
Returns an Iterator over the entire set of members, including copies due to cardinality. This iterator is fail-fast and will not tolerate concurrent modifications. iterator over all elements in the Bag



remove
boolean remove(Object object)(Code)
(Violation) Removes all occurrences of the given object from the bag.

This will also remove the object from the Bag.uniqueSet() .

According to the Collection.remove(Object) method, this method should only remove the first occurrence of the given object, not all occurrences. true if this call changed the collection




remove
boolean remove(Object object, int nCopies)(Code)
Removes nCopies copies of the specified object from the Bag.

If the number of copies to remove is greater than the actual number of copies in the Bag, no error is thrown.
Parameters:
  object - the object to remove
Parameters:
  nCopies - the number of copies to remove true if this call changed the collection




removeAll
boolean removeAll(Collection coll)(Code)
(Violation) Remove all elements represented in the given collection, respecting cardinality. That is, if the given collection coll contains n copies of a given object, the bag will have n fewer copies, assuming the bag had at least n copies to begin with.

The Collection.removeAll(Collection) method specifies that cardinality should not be respected; this method should remove all occurrences of every object contained in the given collection.
Parameters:
  coll - the collection to remove true if this call changed the collection




retainAll
boolean retainAll(Collection coll)(Code)
(Violation) Remove any members of the bag that are not in the given collection, respecting cardinality. That is, if the given collection coll contains n copies of a given object and the bag has m > n copies, then delete m - n copies from the bag. In addition, if e is an object in the bag but !coll.contains(e), then remove e and any of its copies.

The Collection.retainAll(Collection) method specifies that cardinality should not be respected; this method should keep all occurrences of every object contained in the given collection.
Parameters:
  coll - the collection to retain true if this call changed the collection




size
int size()(Code)
Returns the total number of items in the bag across all types. the total size of the Bag



uniqueSet
Set uniqueSet()(Code)
Returns a Set of unique elements in the Bag.

Uniqueness constraints are the same as those in java.util.Set . the Set of unique Bag elements




www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.