The org.bzdev.util package
The package org.bzdev.util contains a number of 'utility' classes.
The class CopyUtilities
contains
code for copying files, resources, and objects referenced by URLs to a
file, output stream or ZIP stream. Copying to a ZIP stream directly is
complicated as for a 'stored' entry, the size of the entry must be
known in advance.
The class TemplateProcessor
allows a file or output stream to be created given a template
accessible via a URL, resource, character array, or Reader. The
templates consist of ordinary text and directives that consist of a
'$', an open delimiter, a keyword, and a closing delimiter. The
keyword is used to look up a replacement (there is a variant to this
syntax for iteration and comments). The template processor is
initialized with maps that indicate how to handle each directive.
There are several iterator classes:
-
EncapsulatingIterator
provides a class that takes an iterator whose values have a type T and maps those values to ones of a different type E. For example, if one has an iterator that provides a sequence of strings and a method whose argument is an iterator that produces a series of string lengths, one can use an EncapsulatingIterator to create an iterator that will generate a sequence of string lengths. -
FilteringIterator
provides an iterator that filters the values provided by a different iterator by removing specified values from the iteration. -
EnumerationIterator
andIteratorEnumeration
are essentially inverses of each other: these classes can be used to turn an Iterator into an Enumeration and vice versa. The Iterator interface was added to Java after the Enumeration interface was added, and Iterator is the preferred choice, but existing code that used the Enumeration interface was not changed so applications may have to handle a mixture of the two. -
CollectionScanner
provides an iterator that can iterate over the concatenation of multiple collections.
There are several formatter classes:
-
SafeFormatter
extends Formatter by including exception-handling code that will replace formatting directives with "%s" directives as a way of handling errors. It is useful for formatting Exception messages where it is better to recover from a formatting error by doing something sensible rather than throwing another exception. Use of this class can make exception handling more robust. -
SciFormatter
extends the Formatter class by allowing floating point numbers to be printed in scientific notation. -
VarArgsFormatter
works like the usual Formatter class, but has explicit methods for up to 11 formatted arguments. This is intended to simply the use of scripting languages that do not recognize Java's use of variable arguments.
There are a number of miscellaneous classes:
- The class
Cloner
provides type-safe cloning.ArrayMerger
is a class with only static methods. It allows one to take a sequence of arrays and return a single array that interleaves their values.ClassSorter
andClassArraySorter
allows classes and arrays of classes to be sorted in a particular order (needed by the dynamic method code but other uses are possible). The classDisjointSetsUnion
andDisjointSortedSetsUnion
provide the union of disjoint sets. - The interfaces
ByteComparator
,CharComparator
,DoubleComparator
,FloatComparator
,IntComparator
,LongComparator
, andShortComparator
provide a comparator whose argument types are primitive types. The classPrimArrays
uses these comparators for binary searches and sorting. - The class
SuffixArray
provides an O(N) computation of a suffix array and will additionally compute the longest common prefix array. These can be used for efficient searching of long sequences. The classSuffixArray
is an abstract class. Its inner classes are the ones that will be instantiated:-
SuffixArray.Array
for arrays of type T (where T is a type parameter) -
SuffixArray.Byte
for arrays of bytes. -
SuffixArray.Char
for arrays of chararacters (primative type 'char'). -
SuffixArray.Integer
for arrays of integers (primative type 'int'). -
SuffixArray.Short
for arrays of short integers. -
SuffixArray.String
for strings. -
SuffixArray.UnsignedByte
for arrays of the primitive type 'byte' where the values are treated as unsigned bytes. -
SuffixArray.UnsignedShort
for arrays of the primitive type 'short' where the values are treated as unsigned shorts. -
SuffixArray.UTF
for arrays of bytes where the bytes represent UTF-8 encoded characters.
-