Skip navigation links

Package de.caff.generics

Generics tools package.

See: Description

Package de.caff.generics Description

Generics tools package.

Package Specification

Most items in this package are no longer necessary when using Java 8 and later.

This package contains classes using generics to allow for functional programming without the overhead of streams and also have dedicated read-only collections.

Read-only Collection Interfaces

The package provides some read-only substitutes for standard collections. Basically they can be used in places where a standard collection with an unmodifiable wrapper is used, with the main advantage that using one of the classes here substitutes the implicit don't modify (or you'll get an excpetion) with a much clearer can't modify (because there are no methods for that). The classes are

Interface from this PackagePurpose
CountableRead-only substitute for java.util.Collection
IndexableRead-only subatitute for java.util.List and arrays
DictRead-only substitute for java.util.Map
FStackFunctional implementation similar to java.util.Stack, used a bit differently

As these interfaces only provide read-only methiods it's simple to view them as if they have different contents.

Similar to Indexable for objects there are also flavors for all primitive values, e.g. IntIndexable for int. In many cases these can be used instead of arrays, again with the advantage that they are not modifiable. So they can be used as public constants which would be a bad idea with an array. Also useful when an array field is returned from a method. Using arrays usually a copy is necessary when returning such a field when the receiver should not be able to modify the array's content.

Handling Standard Collections

Copying one collection into another while modifying it is possible with streams, but sometimes this is a bit over the top. In these cases many methods provided here are still useful.

Skip navigation links