|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.faunos.util.io.IntegerFilename
public class IntegerFilename
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.
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 |
---|
public static final IntegerFilename INSTANCE
Constructor Detail |
---|
protected IntegerFilename()
Method Detail |
---|
public String toName(int n)
i
.
public int toInt(String name)
name
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |