com.faunos.util.io
Class IntegerFilename

java.lang.Object
  extended by com.faunos.util.io.IntegerFilename

public class IntegerFilename
extends Object

Utility for creating integer-based filenames that are lexically pleasing to the eye. Here's the problem I was trying to solve when I factored out this code:

Suppose you create and name files based on the decimal representation of a monotonically increasing number. Suppose these files are in the same directory. When you list the contents of that directory, e.g. through the command line, the results are typically lexicographically ordered. This ordering results in the listing appearing to be numerically jumbled. The aim of this class is to name such files in a way that makes listing them look less jumbled.

It does this by appending zeroes to the front of the decimal representation of a number. (The input number is assumed to > 0.) The number of leading zeroes added is equal to one minus the number of digits in the decimal representation of the input number.

Author:
Babak Farhang

Field Summary
static IntegerFilename INSTANCE
          The default instance.
 
Constructor Summary
protected IntegerFilename()
          For subclasses only.
 
Method Summary
 int toInt(String name)
          Returns the integer associated with the given name.
 String toName(int n)
          Returns a string based representation of the given number i.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INSTANCE

public static final IntegerFilename INSTANCE
The default instance. Since instances are state-less, a single globlal instance will do.

Constructor Detail

IntegerFilename

protected IntegerFilename()
For subclasses only.

Method Detail

toName

public String toName(int n)
Returns a string based representation of the given number i.


toInt

public int toInt(String name)
Returns the integer associated with the given name.



SourceForge.net Logo