Skip to content

Instantly share code, notes, and snippets.

@Riduidel
Created June 27, 2011 12:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Riduidel/1048747 to your computer and use it in GitHub Desktop.
Save Riduidel/1048747 to your computer and use it in GitHub Desktop.
An example external adapter (for cases where IAdaptable won't suffice)
public interface Adapter {
/**
* Check if this adapter can adapt from source class to target one
* @param from class to adapt
* @param to class to create
* @return isn't it obvious ? true if this adapter can transform an object of "from" class into an object of "to" class
*/
public boolean canAdapt(Class<?> from, Class<?> to);
/**
* Adapts an object of input class into an object of output class
* @param input input object to adapt
* @param outputClass output class to produce. This is given due to some restrictions of Java generics
* @return an object of output class that corresponds to input object
* @throws UnableToAdapt if adaptation failed for any reason
*/
public <Input, Output> Output getAdapter(Input input, Class<Output> outputClass) throws UnableToAdapt;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment