package com.tapina.util;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.util.Collection;
import java.util.Map;
import java.util.regex.Pattern;
/**
* A utility class providing transformation routines to convert one type to
* another using Java 1.5 generics for type safety (unlike ConvertUtils)
* and brevity.
*
* Static methods on this class provide the utilities, and the class itself
* provides the interface required to perform transformation. Users of the utilities
* will need to therefore create concrete implementations of the class, which may
* be anonymous if the transformer is not to be reused. An example follows:
*
* A number of Transformer implementations are provided as constants.
*
* @param input object
* @param output object
*/
public abstract class Transformer {
public final static Transformer STRING_TO_LITERAL_PATTERN = new Transformer() {
@Override
public Pattern transform(String s) {
return Pattern.compile(s, Pattern.LITERAL);
}
};
public final static Transformer FILE_TO_CANONICAL_PATH = new Transformer() {
@Override
public String transform(File file) {
try {
return file.getCanonicalPath();
} catch (IOException e) {
return null;
}
}
};
public final static Transformer FILE_TO_URI = new Transformer() {
@Override
public URI transform(File file) {
return file.toURI();
}
};
public final static Transformer