In this section you can read about the features provided by event-based-collections like Set, List, Map etc..
The JDK unmodifiable decorator - Collections.unmodifiableCollection(Collection c) is simple to use but has only one feature: it makes the collection unmodifiable! The happy-collections implements four features for an unmodifiable state of the collection:
example:
UnmodifiableCollection_1x0 c = UnmodifiableCollection_1x0.of( new ArrayList(), UnmodifiableStrategy_1x0.AddAllowed); //add some elements c.add(1); c.add(2); c.add(3); c.add(4); //change modify-strategy c.setStrategy(UnmodifiableStrategy_1x0.Unmodifiable);
The UnmodifiableCollection can be used to decorate any java.util.Collection types, below you can see an example how to forbid removing any elements from a decorated collection.
Collection c = ...; c = UnmodifiableCollection_1x0.of(c, UnmodifiableStrategy_1x0.RemoveAllowed);
UnmodifiableList can be created in analogue to the UnmodifiableCollection and can decorate any java.util.List types. For example in the code bellow the list will be decorated to be unmodifiable for the removing of any elements, but it can be modified by adding new elements.
List list =...; list = UnmodifiableList_1x0.of( list, UnmodifiableStrategy_1x0.AddAllowed);
UnmodifiableSet can be created in the same manner as the Unmodified Collection or List, see the code below:
Set set = new HashSet(); //... //decorate set to be unmodifiable set = UnmodifiableSet_1x0.of(set, UnmodifiableStrategy_1x0.AddAllowed);
UnmodifiableMap example looks almost the same as other decorating examples above:
Map map = new HashMap(); //... //decorate map to be unmodifiable map = UnmodifiableMap_1x0.of(map, UnmodifiableStrategy_1x0.AddAllowed);