Introduction To TECUJ

By Abdul Habra
Version  1.2
Date 2009.01.15

Latest: Source, JAR, JavaDocs.
Java Docs.

Old versions
Scroll to the end of this page to see change details
Version Date Download
1.1 2008.01.02
1.01 2007.09.21
1.0 2007.09.15
0.19 2006.08.16
0.18 2006.06.22
0.17 2006.06.14
0.16 2005.11.15

1. Introduction

Technology Exponent Common Utilities for Java (TECUJ) is a Java library that makes common programming tasks easier. TECUJ is a free software with a GNU LGPL license. Examples of things made easier by the library include:

  1. Enhancements to the Java and Jakarta-commons collections API
  2. File I/O.
  3. Configuration and properties files.
  4. JDBC handling.
  5. Email.
  6. Logging.
  7. XML processing.
  8. String processing.
  9. A powerful list of String items.
  10. Configurable tokenizers.
  11. And many more ...

TECUJ aspires to achieve the following:

  1. Eliminate repetitive Java programming chores.
  2. TECUJ is not a framework that forces you to either use it all or not at all. If you decide to use any of its features, you could continue to use your favorite libraries or framework.
  3. TECUJ tries not to reinvent the wheel, it builds on existing standards and open source libraries.

TECUJ uses the following libraries (which are included in the download):

  1. Java Mail API: mail.jar, version 1.4
  2. JavaBeans Activation Framework: activation.jar, version 1.1
  3. Apache Jakarta Commons lang library: commons-lang-2.3.jar
  4. Apache Jakarta Commons collections library: commons-collections-3.2.jar
  5. Apache Jakarta Commons codec library: commons-codec-1.3.jar
  6. Apache Jakarta Commons IO library: commons-io-1.3.2.jar
  7. Apache Log4j library: log4j-1.2.15.jar
  8. Apache Jakarta Commons Logging library: commons-logging-1.1.jar

TECUJ should run with any version of Java 1.4 or higher. To use this library, just make sure that Tek271Util.jar (and the other dependent jars) are in your classpath.

2. Classes

The following is a list of classes and a brief description of each. The green background indicates the start of a new package.

1 interface ICallback public interface package com.tek271.util
An interface that allows executing a callback method with a parameter.
2 interface IExecutable public interface package com.tek271.util

An interface that allows executing a method and returning a success/failed code.

3 class Printf public package com.tek271.util
Different overloaded printf methods. Not as extensive as Java 1.5. Very handy for building dynamic SQL statements or error messages.
4 class CacheItem   package com.tek271.util.cache
implements com.tek271.util.cache.ICacheItem
Encapsulates an item in the cache. Note that this class has a package scope and cannot be accessed from outside the package.
5 class CacheStore   package com.tek271.util.cache
implements com.tek271.util.cache.ICacheStore

Encapsulates a caches store with a LRU and TTL removal policy, all methods of this class are synchronized. A store is uniquly identified by its name. Each store has a maximum size of items and a Time-To-Live (TTL) in seconds for its items.

To create a cache store use the StoreFactory.createStore() static method.

6 interface ICacheItem interface package com.tek271.util.cache
An interface to represent a cached item.
7 interface ICacheStore public interface package com.tek271.util.cache
An interface to represent a cache store.
8 class StoreFactory public package com.tek271.util.cache
Contains static methods to create/access/remove a cache store. Cache stores are keyed by either User:StoreName or just StoreName. Note that this key is global per JVM, i.e. In the same JVM, two classes can access the same cache store by the same key value.

Warning 1: When two classes access the same store/key, one can modify a cached value that the other may use. Cached objects are available to all classes in the JVM. If you are concerned about this issue, store only immutable objects in the store.
Warning 2: Some objects have restrictions on how to read them, for example, the JDBC ResultSet after fully reading it, requires that you call the first() method in order to read it again. (Assuming you have the right JDBC driver)

9 class AbstractKey public abstract package com.tek271.util.cache.key
implements com.tek271.util.cache.key.IKey,
Implements th IKey interface, key classes should extend this class and implement the methods: getPart(int), setPart(int, String), compare(IKey, IKey).
10 interface IKey public interface package com.tek271.util.cache.key
implements java.lang.Comparable, java.util.Comparator
Encapsulate a key to a cache store. The key can consist of 1 or more string parts.
11 class Key1 public package com.tek271.util.cache.key
extends com.tek271.util.cache.key.AbstractKey
A key that consists of one part.
12 class Key2 public package com.tek271.util.cache.key
extends com.tek271.util.cache.key.AbstractKey
A key that consists of two parts.
13 class KeyN public package com.tek271.util.cache.key
extends com.tek271.util.cache.key.AbstractKey
A key that consists of N parts, where N is determined when you create an instance of KeyN.
14 class CircularFifoOfLong public package com.tek271.util.collections
Code adapted from org.apache.commons.collections.buffer.CircularFifoBuffer. CircularFifoBuffer is a first in first out buffer with a fixed size that replaces its oldest element if full.

The removal order of a CircularFifoBuffer is based on the insertion order; elements are removed in the same order in which they were added. The iteration order is the same as the removal order.

The add(Object), remove() and get() operations all perform in constant time. All other operations perform in linear time or worse.

Note that this implementation is not synchronized. The following can be used to provide synchronized access to yourCircularFifoBuffer:

   Buffer fifo = BufferUtils.synchronizedBuffer(new CircularFifoBuffer());
15 class CollectionUtility public package com.tek271.util.collections
extends CollectionUtils
Different collections utility methods. Extends the Jakarta CollectionUtils class.
16 class NotifyingCollection public package com.tek271.util.collections
implements java.util.Collection
A collection implementation that notifies when items are added or deleted. It decorates another collection be making it notifying.
17 class ArrayUtilities public package com.tek271.util.collections.array
extends ArrayUtils
Generic array methods including different overloaded indexOf() and concat() methods.
18 class AbstractGraphStructuredStackNode public abstract package com.tek271.util.collections.graph
implements com.tek271.util.collections.graph.IGraphStructuredStackNode
Implements IGraphStructuredStackNode which abstracts a Graph-structured Stack (GS) node. A GS is a directed acyclic graph where each directed path is considered a stack. You can think of a GS as a structure similar to a tree structure with the exception that a node can have more than one parent. See wikipedia for more info on GS.
19 class GraphStructuredStackNode public package com.tek271.util.collections.graph
extends com.tek271.util.collections.graph.AbstractGraphStructuredStackNode
A node that has a key and contents.
20 class GssUtils public package com.tek271.util.collections.graph
Helper static methods for graph handling.
21 class GssUtils.GraphEntry public static package com.tek271.util.collections.graph
Encapsulates (key, contents, parentKey) of a graph entry, a list of this object can be used to construct a graph using the GssUtils.createGraph() method.
22 interface GssUtils.IGssNodeFactory public static interface package com.tek271.util.collections.graph
provides a method to create a IGraphStructuredStackNode object
23 interface IGraphNode public interface package com.tek271.util.collections.graph
Abstracts a node in a graph. The node has a key and contents. This interface does not enforce any restrictions on the keys or contents.
24 interface IGraphStructuredStackNode public interface package com.tek271.util.collections.graph
implements com.tek271.util.collections.graph.IGraphNode
Abstracts a Graph-structured Stack (GS) node. A GS is a directed acyclic graph where each directed path is considered a stack. You can think of a GS as a structure similar to a tree structure with the exception that a node can have more than one parent. See wikipedia for more info on GS.

Notice that this interface extends the IGraphNode interface.

Each node consists of the following:
  1. Key
  2. Contents
  3. List of its children. Each child is an IGraphStructuredStackNode object. Children will have distinct keys.
  4. List of its parents. Each parent is an IGraphStructuredStackNode object. A node CAN have more than one parents with the same key. However, the list of parents will not contain the same parent node more than once.
25 class MapOfGraphNode public package com.tek271.util.collections.graph
extends java.util.HashMap
A map of IGraphNode objects. The key of the map is the node's key, and the value is the node itself.
26 interface ILongIterator public interface package com.tek271.util.collections.iterator
implements java.util.Iterator
27 class NotifyingIterator public package com.tek271.util.collections.iterator
implements java.util.Iterator
Decorate an Iterator such that remove operations will cause a callback through aRemoveNotifier.execute().
28 class ListOfString public package com.tek271.util.collections.list
extends java.util.ArrayList
Encapsulates a list whose items are String objects. This class extends the ArrayList class. Some interesting features are:
  1. Can read/write to a text file where each line is an item in the list.
  2. Can populate from a page at a given URL where each line is an item in the list.
  3. Items can be in the form: name=value. With methods to access by name.
  4. Many different indexOf() methods.
  5. Intersection/Difference/Merge two lists.
  6. Sort items of the list.
29 class RowList public package com.tek271.util.collections.list

A RowList represents a growable table of data. A row within the RowList can contain many columns, however, each row in the RowList will contain the same number of columns. A column within a RowList consists of a column name and a column value.

A RowList can be populated from a Map, an array of Objects, or a List by invoking the appropriate add method.

The RowList class provides getXXX methods for retrieving column values from a row. Values can be retrieved using either the index number of the row, which returns a Map where the key is the column name and the value is the column value, or by supplying the index number and the column name. Rows are numbered from 0.

For the getXXX methods, the RowList attempts to convert the underlying data to the Java type specified in the XXX part of the getXXX method and returns a suitable Java value.

When a getXXX method is called with a column name and several columns have the same name, the value of the first matching column will be returned.

30 class RowListComparator   package com.tek271.util.collections.list
implements java.util.Comparator,
RowListComparator implements the Comparator interface and provides the compare method to compare the rows in a RowList based on the column and direction flag arrays passed into it.

Note that the class has a default package scope, and is not accessiable outside its package.

31 class SingleRowList public package com.tek271.util.collections.list
extends com.tek271.util.collections.list.RowList
32 class MapOfString public package
extends java.util.HashMap
A map where both keys and values are strings. When you construct an object of this class you can specify if you want it to be case sensetive or not. Using the case insensetive option will not change the case of either keys or values. Additionally, using the setListOrder() method you can have the class keep track of the order in which items where added to the map.
33 class MapOfStringMV public package
A map of string which can have multiple values for the same key.
34 class MapUtility public package
extends MapUtils
Static utility map-related methods.
35 class MapValue   package
implements java.util.Map.Entry
When running in a case insensitive mode, we need to maintain the original key in order to return it to the caller if needed. This class represent a value in a map with its original key. Used only in case insensitive mode.

Note that the class has a default package scope, and is not accessiable outside its package.

36 class MapValueMV   package
n * Encapsulate a multi-value value for the MapOfStringMV class.

Note that the class has a default package scope, and is not accessiable outside its package.

37 class OrderedMapOfTimestamp public package
extends LinkedMap
A map whose values are the time stamp of addition to the map. The elements in the map are ordered by their insertion order.
38 class TimedLruMap public package
extends java.util.LinkedHashMap
A map with a maximum size and time-to-live for ite entries. When trying to add to the map which reached its max size, the Least Recently Used (LRU) item is removed. Items that have been in the map for a period greater than the time-to-live period will be removed when trying to use any map-related method, in-other-words, methods of the Object class do not cause the removal of expired entries. This class extends java.utils.LinkedHashMap with accessOrder feature.
39 class NotifyingSet public package com.tek271.util.collections.set
extends com.tek271.util.collections.NotifyingCollection
implements java.util.Set
A set implementation that notifies when items are added or deleted. It decorates another set be making it notifying.
40 class SetUtility public package com.tek271.util.collections.set
extends SetUtils
41 class AbstractTree public abstract package com.tek271.util.collections.tree
extends com.tek271.util.collections.graph.AbstractGraphStructuredStackNode
implements com.tek271.util.collections.tree.ITree
Implements the ITree interface. Classes that need to implement ITree should extend this class and provide implementation for its abstract methods. The abstract methods of this class are:
  abstract public Object getContents() ;
  abstract public void setContents(final Object aContents);
  abstract public boolean isEqualContents(final Object aContents);

  abstract public Object getKey();
  abstract public void setKey(final Object aKey);
  abstract public boolean isEqualKey(final Object aKey);
42 interface ITree public interface package com.tek271.util.collections.tree
implements com.tek271.util.collections.graph.IGraphStructuredStackNode
Defines the interface of a generic tree node. A tree node consists of
  1. Key: must be unique for children of the same parent
  2. Contents
  3. List of children, each child is a also an ITree. (a recursive structure)
  4. A reference to the parent ITree node of this ITree.
43 class TreeOfString public package com.tek271.util.collections.tree
extends com.tek271.util.collections.tree.AbstractTree
A Tree structure of string objects. This tree has the same object for key and contents.
44 class BlobUtil public package com.tek271.util.db
Utility methods to handle Blobs in db tables.

Note that:

  1. This library uses 1 as the starting index of query parameters to stay similar to JDBC (albeit it is goofy).
  2. This library uses integers to represent sizes of blobs which will restrict the size of the blob to the max represented by Integer.MAX_VALUE.
  3. It does not make sense to create classes that implement the Blob interface outside the context of a JDBC driver. The Blob api requires direct connection to the db BLOB fields.
45 class ClobUtil public package com.tek271.util.db
Utility methods to Clobs in db tables.

Note that:

  1. This library uses 1 as the starting index of query parameters to stay similar to JDBC (albeit it is goofy).
  2. This library uses integers to represent sizes of clobs which will restrict the size of the clob to the max represented by Integer.MAX_VALUE.
  3. It does not make sense to create classes that implement the Clob interfaces outside the context of a JDBC driver. The Clob api requires direct connection to the db CLOB fields.
46 class DBRowList public package com.tek271.util.db
extends com.tek271.util.collections.list.RowList
Extends a RowList by adding JDBC-related methods, including the ability to construct from a ResultSet.
47 class DbUtil public package com.tek271.util.db
Generic database library methods.

The motivation for creating this library:

  1. Simplify JDBC access, including handling exceptions and logging.
  2. Avoid adding a new abstraction or a framework that requires hours of learning or may impact performance.
  3. Do not try to remove SQL from the picture, just make it easier to issue SQL queries.
  4. If a feature is not supported by this library, the programmer can use her/his favorite method in conjunction with this library.

All the methods are:

  1. Static.
  2. Take a parameter of type com.tek271.util.log.ILogger that allow logging errors when errors are possible. You can use SimpleConsoleLogger.LOGGER for logging to console.
  3. Handle and log exceptions so the user does not have to do try/catch.
  4. When possible, return a value indicating failure. (usually false or null)

Some interesting features are:

  1. Overloaded close() to close Connection, Statement, and ResultSet.
  2. Given a resultset, close it, its Statement, and Connection using closeAll().
  3. Open either a standard JDBC connection, or get a connection from a JNDI lookup, used typically in J2EE environments.
  4. Get a row from a ResultSet as either an array or as a List.
  5. Increment the value of a numeric column in a table.
  6. Get the next value of an Oracle sequencer. (This does not mean that you can use Oracle only with this library, but that this method is only valid on an Oracle database.).
  7. Several readCellAsXXX() methods that read a given column at a given row from a given table, where the value can be int, long, or String.
  8. Read a column from a table into a ListOfString.
  9. Read one row from a table into either an array or a ListOfString.
  10. Run a SELECT statement and put the result into a RowList object.
  11. Run a method in a transaction using the IExecutable interface.
  12. Update the value of a given column in a table.
  13. Overloaded write() and writeAndGetCount() methods that run write queries (insert, update, or delete).
  14. Insert or update blobs using the writeLongString() method.
  15. And more ...

The following example opens a db connection, reads a value from a table, then closes the db connection.

ILogger log= SimpleConsoleLogger.LOGGER;  // log errors to console
String driver= "oracle.jdbc.driver.OracleDriver";
String url= "";
String user= "coolDude";
String password= "password";
Connection con= DbUtil.getConnectionJdbc(log, driver, url, user, password);
if (con==null) return;      // error happened and logged

String sql= "select name from employee where id=5";
String name= DbUtil.readCellAsString(log, sql, con);
if (name==null) { 
  // error happened and logged
  DbUtil.close(log, con);

System.out.println("Name is " + name);
DbUtil.close(log, con);
In a typical application you may put the code to open connection in a separate method. Note the simplification here over standard JDBC calls; you do not have to do try/catch, and that logging is done automatically.
48 class SqlSelect public package com.tek271.util.db
Simplifies building Select SQL statement strings. When you have long SQL select statements that take many lines, this class will be very helpful.
49 class SqlWhere public package com.tek271.util.db
Build the where clause for an SQL statement. Helps avoiding string concatenations and worrying about quoting string values.
50 class SqlWrite public package com.tek271.util.db
Build an INSERT or an UPDATE SQL string. This is specially helpful to avoid repeating sql code for insert and update on the same table.


SqlWrite q = new SqlWrite(SqlWrite.UPDATE, "employee");
q.addColumn("destination", "Hawaii", true);  // true: surround Hawaii by single quotes
q.addColumn("vacationDays", 10);

The above code will generate the following SQL statement:

    UPDATE employee SET destination='Hawaii',vacationDays=10 WHERE age<18

Now, to generate an INSERT statement on the same table and columns, all we need is to call:


Which will generate: (notice that we did not have to repeat column definitions)

    INSERT INTO employee (destination,vacationDays) VALUES ('Hawaii',10) WHERE age<18

Although this was a simple example that may not justify using the SqlWrite class, it is meant to demonstrate the basic usage. This class really shines when you have complex inserts or updates that take many lines and are hard to follow.

51 class TransUtil public package com.tek271.util.db
Database transactions utilities, including static methods for commit, rollback, setAutoCommit, and a method that executes several db operations as one transaction.
52 class ExceptionUtil public package com.tek271.util.exception
Generic static methods to manage exceptions, including:
  1. Build consistent debug or error messages.
  2. Log a debug, warning, or error message to an ILogger object.
  3. Convert an exception stack trace to a string.
  4. Print an exception's stack trace to console, an OutputStream, or a Writer object. This is useful to print the stack trace to a web page during development.
53 class LoggedException public package com.tek271.util.exception
extends java.lang.Exception
An exception that logs error messages, it will also log the stack trace.
54 class Email public package com.tek271.util.internet
Simplifies sending SMTP email. Its static methods send() and sendAsynchronous() are very easy to use and send email.

Requires javax.mail. Can be downloaded at: However, this is included with the tecuj.jar.

55 class EmailSender public package
Send email using the SMTP/SMTPS prtocol. I used the which comes with Java Mail API demo as a starting point for creating this class. The authors of are Max Spivak and Bill Shannon.
56 class EmailUtils public package
Email helper static methods.
57 class ColorGradient public package com.tek271.util.internet.html
Given two colors and a range, get the gradient color for each step, in other words, get the interpolation of color as we transition in the range.
58 class ComboBox public package com.tek271.util.internet.html
Build the html for a combo box.
59 class ErrorList public package com.tek271.util.internet.html
Collect a list of errors which can be displayed later in one page.
60 class Grade public package com.tek271.util.internet.html
Display a list of grades (e.g. from 1 to 10) with each grade displayed as a link. Background colors will gradually change from minium grade to max grade
61 class HtmlTable public package com.tek271.util.internet.html
Generates an HTML table. To use this class,
  1. Implement the interface HtmlTable.ICellCallback
  2. create a new object of HtmlTable
  3. initialize its properties as you like,
  4. then call the toString() method.
62 interface HtmlTable.ICellCallback public static interface package com.tek271.util.internet.html
Client applications should implement this interface to provide the text to be displayed at each cell in the table.
63 class HtmlUtil public package com.tek271.util.internet.html
Static methods to build different HTML tags and elements. Supported elements include: <a>, <b>, <br>, <h>, <i>, <img>, <p>, Check box, Font color, Numbered lines, ...

The purpose of this class is to simplify the creation of HTML elements in Java code.

64 class Paginator public package com.tek271.util.internet.html
Generate pagination links that could be used to navigate to different search results.
65 class TableUtils public package com.tek271.util.internet.html
Utility methods for HTML tables, including the creation of <td> and <th> elements.
66 class MultiLevelMenu public
Generate a cross browser multi-level html menu. It expects that the style sheet multiLevelTopMenu.css is available to the browser.

The html and css idea of this class was taken and refactored from:

67 class MultiLevelMenu.Config public static
68 class XmlMultiLevelMenu public
Create a MultiLevelMenu from XML. An example XML could be:
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
  <mi text='Home' href='home.html' />
   <mi text='Affiliate' href='' target='_blank' />
   <mi text='Books' href='books.html'>
     <mi text='Fiction' href='Fiction.html'>
       <mi text='Mystery' href='Mystry.html'>
         <mi text='Cold Prey' href='coldPrey.html' />
         <mi text='Silent Prey' href='silentPrey.html' />
         <mi text='Blood Memory' href='bloodMemory.html' />
69 class Compress public package
70 class ConfigFile public package
implements java.lang.Cloneable
Encapsulates a configuration file interface. This is a better handler for properties files that can support inline comments and grouping.

The user can (optionally) specify in the file what is the equality character and the comment start character. For example:

If the above two lines are the first two lines in the file, values will be separated from their names by the > or ] char, while comments will start with %.

The default Equal chars are = or : while the default Comment chars are ; or #.

71 class FileIO public package
Generic file i/o methods for reading, writing, listing, and finding files.
72 class Net public package
73 class AbstractBufferedLogger public abstract package com.tek271.util.log
implements com.tek271.util.log.ILogger
Buffer logging messages. Remember to call flush when you are done with objects of this class. Implementing classes must provide logNow() implementation.
74 class AbstractLogger public abstract package com.tek271.util.log
implements com.tek271.util.log.ILogger
Implements the ILogger interface method log(level, msg). This makes it easier for classes that implement the ILogger interface.
75 class BufferedLog4jAdapter public package com.tek271.util.log
extends com.tek271.util.log.AbstractBufferedLogger
A buffered logger that uses log4j. Remember to call flush when you are done with objects of this class. Note that this class extends AbstractBufferedLogger which implements the ILogger interface, so you can use this class whereever ILogger is expected.
76 class ClassLogger public package com.tek271.util.log

Provide info/debug/warn/error methods for a client class

77 class CommonsLoggingAdapter public package com.tek271.util.log
extends com.tek271.util.log.AbstractLogger

Implements the ILogger interface using the commons logging logger.

78 interface ILogger public interface package com.tek271.util.log
Interface of a generic logger. Used to create logging classes that implement this interface. The interface has only one method log() that is overloaded once. Some classes (E.g. DbUtil) in this library use this interface to log error message.

To use this interface you should implement it in one of your classes and pass an object of your class.

79 class ListLogger public package com.tek271.util.log
extends com.tek271.util.log.AbstractLogger
An ILogger implementation that Decorates another ILogger by manitaining a list of logged events. The list can be accessed at any time. Remember that if you dump the list contents to some output device, you should clear it afterwords.
80 class ListLogger.LogItem public package com.tek271.util.log
a log item
81 class Log4jAdapter public package com.tek271.util.log
extends com.tek271.util.log.AbstractLogger

Implements the ILogger interface using Log4j

82 class MultiThrowable   package com.tek271.util.log
extends java.lang.Throwable

A throwable that can have multiple stack traces.

83 class PerformanceLog public package com.tek271.util.log
Log timing for different events in the JVM. The caller logs the time of an event by name. Accessing this class is throu the singlton PerformanceLog.LOG. The method that will be called the most is PerformanceLog.LOG.putNow(key, startTime)
84 class PerformanceLog.LogEntry public static package com.tek271.util.log
Store info about a single operation logging times
85 class SimpleConsoleLogger public package com.tek271.util.log
extends com.tek271.util.log.AbstractLogger
Simple logger that implements ILogger and writes to console. Usually used for debugging.

The static member SimpleConsoleLogger.LOGGER can be used instead of creating several objects of this class.

86 class AbstractTokenizer abstract package com.tek271.util.parse
This is an abstract class that is implemented by the Tokenizer class.
  1. Has a default package scope, i.e. not visible outside this package.
  2. Defines the public properties, methods, and fields of the Tokenizer class.

The class defines the following public methods:

  1. set/get Text: The text or source to be tokenized.
  2. getNext: abstract, implemented in the Tokenizer class. Returns the next token.
  3. getList: Tokenize the source and return a list of Token objects.
  4. toString: Converts the class into a string including its properties values.
  5. set/is CaseSensitive: Controls if keywords are case sensitive or not.
  6. set/get Keywords: A list of the keywords. E.g. if else class while.
  7. set/get MultiLineCommentEnders: A list of character sequences that indicate end of a multi-line comment. E.g. */ or*).
  8. set/get MultiLineCommentStarters: A list of character sequences that indicate start of a multi-line comment. E.g. /* or(*.
  9. set/get NewLineMarkers: A list of character sequences that indicate the end of a line and the start of a new line. E.g.\n or \n\r.
  10. set/get Separators: A list of arithmetic or punctuation separators. E.g. = + - * == <= ; : .
  11. set/get SingleLineCommentMarkers: A list of character sequences that indicate the start of a single line comment. The comment may start at any position in the line. E.g. // or REM.
  12. set/get StringMarkers: A list of characters that indicate the beginning/end of a string literal. E.g. " or '.
  13. set/get WhiteSpaces: A list of characters that indicate a space. E.g. blank or tab.

The class also defines the following public boolean fields:

  1. isReturnComments: Controls if comments should be returned as a result of tokenization. Default is true.
  2. isReturnNewLineMarkers: Controls if new-line-markers should be returned as a result of tokenization. Default is true.
  3. isReturnWhiteSpace: Controls if white-spaces should be returned as a result of tokenization. Default is true.
87 class FileTokenizer public package com.tek271.util.parse
extends com.tek271.util.parse.Tokenizer
  1. Extends the Tokenizer class.
  2. Tokenizes a text file, reading the syntax definition from another file.
88 class Token public package com.tek271.util.parse
The Tokenizer class produces Token objects. This is a simple data structure that contains the value, type, line, and column of the token. The token type can be one of: Keyword, String, Separator, Literal, White Space, Comment, New Line, and Error.
89 class Token.List public static package com.tek271.util.parse
Define a list of tokens.
90 class Tokenizer public package com.tek271.util.parse
extends com.tek271.util.parse.AbstractTokenizer
A generic tokenizer. To use it:
  1. Initialize the syntax definition by calling setKeyworks, setCaseSensitive, setSeparators, ...
  2. Call setText() and pass it the text you want to tokenize.
  3. Call getNext() repeatedly. Each call will return an object of type Token. When no more tokens, a null is returned.
  4. You can call getList() instead of calling getNext() many times.
91 class SelectParser public package com.tek271.util.parse.sql
Define a parser that parses a Select Sql statement. To use it:
  1. Construct a SelectParser object using a select statement, this will also parse the Sql string.
  2. getColumns: a list of selected columns
  3. getTables: a list of tables in the From clause.
  4. getWhere: a list of items in the where clause.
  5. getGroupBy: an optional list of items in the Group by clause.
  6. getOrderBy: an optional list of items in the Order by clause.
92 class BasicTypes public package com.tek271.util.reflect
Utility class that define primitive types, their wrappers, and other basic types
93 interface IPrimitiveWrapper public interface package com.tek271.util.reflect
Allows grouping primitive types with their wrappers
94 class ReflectUtil public package com.tek271.util.reflect
Utility methods that handle dynamic class introspections
95 class BeanAccessor public package com.tek271.util.reflect.accessors
96 class FieldAccessor public package com.tek271.util.reflect.accessors
97 class MethodAccessor public package com.tek271.util.reflect.accessors
98 class AbstractBeanBuilder public abstract package com.tek271.util.reflect.builder
Dynamically creates a bean that implements a given interface and back its property values using the IBeanValueAccessor interface.
99 interfaceAbstractBeanBuilder.IBeanValueAccessor public static interface package com.tek271.util.reflect.builder
An interface that must be implemented by subclasses of AbstractBeanBuilder. It provides the mechanism to get and set the bean property values using the name of the property.
100 class BeanFromMapBuilder public package com.tek271.util.reflect.builder
extends com.tek271.util.reflect.builder.AbstractBeanBuilder
Dynamically creats a bean that implements a given interface and back its property values using a Map object. An example which uses this class:
import java.util.*;


  public interface IPerson {
    String getName();
    void setName(String name);

    Integer getAge();
    void setAge(Integer age);

    String getSsn();
    void setSsn(String ssn);

  private static final Object[][] ARRAY = {
      {"name", "abdul"},
      {"age", new Integer(40)},
      {"ssn", "123456789"},
  public static final Map MAP= MapUtility.toMap(ARRAY);

  public void testSetProperties() throws Exception {
    IPerson person= (IPerson) BeanFromMapBuilder.create(IPerson.class, MAP);

    System.out.println(person.getName());   // abdul
    System.out.println(person.getAge());    // 40
    System.out.println(person.getSsn());    // 123456789

    System.out.println(person.getName() );  // aaa
101 class MethodFilter public package com.tek271.util.reflect.filter
Provides a list of methods on a class filtered by different criteria. To use the class, set the exclude properties, then call getMethods().
102 class MethodSignature public package com.tek271.util.reflect.filter
Encapsulates the signature of a method, ie, its name and parameters types.
103 class Encryption public package
A simple encryption program to encrypt and decrypt strings using a given password. It helps encrypting password columns in db tables. Uses DES algorithm.
104 class StringComparator public package com.tek271.util.string
implements java.util.Comparator, java.lang.Comparable
Implement the Comparator and Comparable interfaces for String objects, with support for case sensitivity.
105 class StringEscapeUtility public package com.tek271.util.string
extends StringEscapeUtils
Different string escapeing methods.
106 class StringUtility public package com.tek271.util.string
extends StringUtils
Contains common string functions. Note that this class extends org.apache.commons.lang.StringUtils. The StringUtils class is available to download from Make sure to include the downloaded jar file in your classpath, currently this is commons-lang-2.1.jar. However, the tecuj download includes this jar file.

Some interesting features are:

  1. Define some common String constants like NEW_LINE, ALPHA_CAPS, WHITE_SPACE, ...
  2. Delete a set of characters from a given string.
  3. equals() method with a case sensitivity flag.
  4. Convert to/from Hexadecimals and Unicode.
  5. Check if a value is a member in a given set of values.
  6. Several overloaded indexOf(), indexOfAny(), indexOfAnyBut() methods to find the index of a value in a target.
  7. Get the lastChar() of a given string.
  8. Repeat a character a given number of times.
  9. And more ...
107 class TextTemplate public package com.tek271.util.string
A text template class that allows substituting patterns (or tags) with values. The easiest way to use it is to call one of the process() static methods.
However, if you want to reuse the same template in your program but with different values, consider creating a TextTemplate object and assigning values to it using either setTagValue() or setAll().


  1. 2005.06.22: Added copy() method.
  2. 2006.01.30: Added ITagTransformer and transformTags()
108 interface TextTemplate.ITagTransformer public static interface package com.tek271.util.string
Allows transforming tags to new values
109 class TextTemplate.Element public package com.tek271.util.string
Represents a single element of the processed text, the element can be either a string or a tag.
110 class WordUtility public package com.tek271.util.string
extends WordUtils
111 class AbstractMutex public abstract package com.tek271.util.thread
implements com.tek271.util.thread.IMutex

Implements the IMutex interface

112 class FileMutex public package com.tek271.util.thread
extends com.tek271.util.thread.AbstractMutex

A mutual-exclusion-lock based on the existance of a file in the file system

113 interface IMutex public interface package com.tek271.util.thread

Define the interface of a mutual-exclusion-lock

114 class Mutex public package com.tek271.util.thread
extends com.tek271.util.thread.AbstractMutex

Create an in-memory mutual-exclusion-lock

115 class OsExecutor public package com.tek271.util.thread
A wrapper around Runtime.getRuntime().exec()
116 class ThreadUtility public package com.tek271.util.thread
Several static thread related methods including sleep(seconds).
117 class DateFormatUt public package com.tek271.util.time
extends DateFormatUtils
Date/Time formatting functions.
118 class DateUt public package com.tek271.util.time
extends DateUtils
Date/Time functions.
119 class XmlTree public package com.tek271.util.xml
implements java.lang.Cloneable
A tree data structure that represents an XML document in a simplified DOM style. It is a wrapper around the XML libraries that come with J2SE.

To use this class, use the static methods create() or createXxx() which will return an XmlTree object.

The program uses SAX to parse the XML document and build the tree. Some of its features:

  1. You can parse an XML document from a String, InputStream, Reader, File, or URL.
  2. Each XmlTree has a tag, optional text, an optional list of attributes, and an optional list of children.
  3. The children are XmlTree objects also. This structure is recursive.
  4. You can add, get, or delete children by index or path (slash / separated).
  5. You can get/set the tag, attributes, and text of an XmlTree object.
  6. You can get the string representation of an XmlTree object.
120 class XmlTreeParser   package com.tek271.util.xml
extends org.xml.sax.helpers.DefaultHandler
Handles events received from SAX parser to populate an XmlTree object.

Note that this class has a package scope and is not intended to be used by classes other than XmlTree.

This parser will ignore all comments in the XML data.

This class was refactored in 2006.08.15 to extend DefaultHandler instead of HandlerBase which was deprecated.

121 class XmlUtil public package com.tek271.util.xml
General XML utility methods, including the building of XML tags from their components.

Version 1.2, 2009.01.15
  1. Added
  2. Added
  3. Added (style sheet)
  4. Added com.tek271.util.string.StringUtility.deleteControlChars()
  5. Added com.tek271.util.string.StringUtility.mutate()
  6. Added com.tek271.util.string.StringUtility.selectOption()
  7. Added com.tek271.util.string.StringUtility.pluralize()
  8. Added com.tek271.util.string.WordUtility
  9. Added com.tek271.util.reflect.ReflectUtil.getPackageDirectoryOfClass()
  10. Added com.tek271.util.reflect.ReflectUtil.getSuperclasses()
  11. Added com.tek271.util.reflect.ReflectUtil.isDefaultScope()
  12. Added com.tek271.util.reflect.BasicTypes
  13. Added com.tek271.util.reflect.IPrimitiveWrapper
  14. Added com.tek271.util.reflect.filter.MethodFilter
  15. Added com.tek271.util.reflect.filter.MethodSignature
  16. Added com.tek271.util.collections.set.SetUtility
  17. Added com.tek271.util.collections.list.ListOfString.readFromTextFileInContext()
  18. Updated com.tek271.util.reflect.accessors.MethodAccessor.invoke() to call non-public methods
  19. Added overloaded factory methods to XmlTree to enable preserving space in elemetns's data. Thanks Nilanjan Raychaudhuri.
  20. Fixed the spelling error in class com.tek271.util.thread.OsExecutor name
Version 1.1, 2008.01.02
  1. Added com.tek271.util.collections.CollectionUtility.addAll(Collection, Object[])
  2. Added com.tek271.util.collections.array.ArrayUtilities.toArrayOfString(Object[])
  3. Added com.tek271.util.collections.array.ArrayUtilities.toArrayOfString(Collection)
  4. Added com.tek271.util.reflect.accessors.BeanAccessor
  5. Added com.tek271.util.reflect.accessors.FieldAccessor
  6. Added com.tek271.util.reflect.accessors.MethodAccessor
  7. Added com.tek271.util.thread.OsExecutor
  8. Added com.tek271.util.string.StringUtility.replaceBetween*() methods
  9. Added com.tek271.util.string.StringUtility.removeBetween*() methods
  10. Added com.tek271.util.string.StringUtility.defaultToNull() method
  11. Added com.tek271.util.string.StringUtility.substringAfterOpenClose(str, open, close, fromIndex) method
  12. Added com.tek271.util.log.Log4jAdapter.Log4jAdapter(URL) constructor
Version 1.01, 2007.09.21
Updated the used libraries (Jakarta Commons and Log4J) to the latest release.
Version 1.0, 2007.09.15
This is a major release with many updates and bug fixes.
  1. Added Ant build script.
  2. Converted the project to use Eclipse.
  3. Cleaned up many of JavaDocs warnings.
  4. Added
  5. Added com.tek271.util.thread.ThreadUtility.sleepMillis()
  6. Added
  7. Added
  8. Added com.tek271.util.collections.array.ArrayUtilities.clone(String[] aArray)
  9. Refactored com.tek271.util.cache.CacheStore to use instead of
  10. Fixed a bug in com.tek271.util.cache.CacheStore.equals()
  11. Deprecated com.tek271.util.cache.CacheItem
  12. Deprecated com.tek271.util.cache.ICacheItem
  13. Added these fields to com.tek271.util.internet.html.HtmlTable: classHeader, classRow1, and classRow2
  14. Added
  15. Added com.tek271.util.string.StringUtility.deleteControlChars(String)
  16. Added com.tek271.util.string.TextTemplate.setText(String) method.
  17. Added com.tek271.util.string.TextTemplate.getAllTagNames(String aStartsWith) method.
  18. Added com.tek271.util.xml.XmlTree.isEqualTag(String aTag, boolean aIsRegExp)
  19. Added com.tek271.util.xml.XmlTree.findAllChildren(String aTagPath, boolean aIsRegExp)
Version 0.19, 2006.08.16
  1. Fixed a bug in com.tek271.util.xml.XmlUtil.tagStart() where attributes that contain the double-quote character will be surrounded by single quotes.
  2. Refactored com.tek271.util.xml.* classes to use none-deprecated SAX APIs.
  3. Added com.tek271.util.internet.html.TableUtils.rowListToHtmlTable()
  4. Added com.tek271.util.collections.list.RowList.set/getColumnHeadersList()
  5. Added com.tek271.util.reflect.builder.AbstractBeanBuilder
  6. Added com.tek271.util.reflect.builder.BeanFromMapBuilder
  7. Added methods to com.tek271.util.collections.list.RowList: set/getRowInterface(), getRowAsBean()
  8. Added
Version 0.18, 2006.06.22
  1. Added a new constructor to com.tek271.util.log.Log4jAdapter that takes a Log4j Logger object
  2. Add the class com.tek271.util.log.CommonsLoggingAdapter
  3. Fixed a bug in the generation of JavaDocs where the source code was not viewable form FireFox browser.
Version 0.17, 2006.06.14
Small bug fixes. Also, added the following classes and packages:
  1. com.tek271.util.string.StringEscapeUtility
  2. com.tek271.util.string.StringComparator
  3. com.tek271.util.collections.CollectionUtility
  4. com.tek271.util.collections.graph.*
  5. com.tek271.util.collections.tree.*


Abdul Habra,
Mar 28, 2011, 2:51 PM
Abdul Habra,
Mar 28, 2011, 2:52 PM
Abdul Habra,
Mar 28, 2011, 2:52 PM
Abdul Habra,
Mar 28, 2011, 2:53 PM
Abdul Habra,
Mar 28, 2011, 2:54 PM
Abdul Habra,
Mar 28, 2011, 2:55 PM
Abdul Habra,
Mar 28, 2011, 2:56 PM
Abdul Habra,
Mar 28, 2011, 2:56 PM