Hello,
I don't know if anybody will find this helpfull, but I'd thought I'd post it. I've written a quick velocity template for creating a typesafed Lists wrapper in IntelliJ IDEA (it actually should work with anything that supports Velocity, but I've formatted these so the dialog looks nice in IntelliJ).
I think this could be helpul for those working on Hibernate2.x projects who are making heavy use of a given collection throughout thier code.
Note that the code generated doesn't implement a Collection interface, you'll have to set your mapping up to persist the actuall List this class wraps (getter and setter are provided).
If you're only going to have one collection in the class leave the "PREFIX" variable blank. Specifying it would allow you to create two files and hack them together to create an object that wraps two collections, without a ton variable signature conflicts.
This is something I just whipped up real quick, and I may work up something for the rest of the collection classes as well, if people are interested.
Just copy and past the first smaller code listing to your file templates and the second in the "include" tab/directory and call it "ListWrapperImport.java"
First bit of code - just a wrapper for the other code so the IntelliJ Dialog looks nice:
Code:
// ${CLASS_NAME}
// ${SUB_CLASS_NAME}
// ${PREFIX}
#parse("ListWrapperImport.java")
The rest of it
Code:
#if($SUB_CLASS_NAME.substring(0,1).equals($SUB_CLASS_NAME.substring(0,1).toLowerCase()))
#set ($SUB_CLASS_NAME_LOWER_CASE = "$SUB_CLASS_NAME.substring(0,1).toUpperCase()$SUB_CLASS_NAME.substring(1)")
#else
#set ($SUB_CLASS_NAME_LOWER_CASE = "$SUB_CLASS_NAME.substring(0,1).toLowerCase()$SUB_CLASS_NAME.substring(1)")
#end
#set ($SUB_CLASS_ACCESSOR = "${PREFIX}${SUB_CLASS_NAME}s")
#set ($METHOD_PARAMATER_NAME = ${SUB_CLASS_NAME_LOWER_CASE})
#set ($SUB_CLASS_VARIABLE_NAME = "${PREFIX}${SUB_CLASS_NAME_LOWER_CASE}s")
package ${PACKAGE_NAME};
import java.util.*;
public class ${CLASS_NAME} {
public class ${CLASS_NAME}Iterator {
private ListIterator iter;
protected ${CLASS_NAME}Iterator(ListIterator iter){
this.iter = iter;
}
public int nextIndex() {
return iter.nextIndex();
}
public int previousIndex() {
return iter.previousIndex();
}
public void remove() {
iter.remove();
}
public boolean hasNext() {
return iter.hasNext();
}
public boolean hasPrevious() {
return iter.hasPrevious();
}
public ${SUB_CLASS_NAME} next() {
return (${SUB_CLASS_NAME})iter.next();
}
public ${SUB_CLASS_NAME} previous() {
return (${SUB_CLASS_NAME}) iter.previous();
}
public void add(${SUB_CLASS_NAME} ${METHOD_PARAMATER_NAME}) {
iter.add(${METHOD_PARAMATER_NAME});
}
public void set(${SUB_CLASS_NAME} ${METHOD_PARAMATER_NAME}) {
iter.add(${METHOD_PARAMATER_NAME});
}
}
private List ${SUB_CLASS_VARIABLE_NAME};
public ${CLASS_NAME}() {
${SUB_CLASS_VARIABLE_NAME} = new ArrayList();
}
private ${CLASS_NAME}(List list) {
${SUB_CLASS_VARIABLE_NAME} = list;
}
public List get${SUB_CLASS_ACCESSOR}() {
return ${SUB_CLASS_VARIABLE_NAME};
}
public void set${SUB_CLASS_ACCESSOR}(List list){
${SUB_CLASS_VARIABLE_NAME} = list;
}
public int ${PREFIX}size() {
return ${SUB_CLASS_VARIABLE_NAME}.size();
}
public void ${PREFIX}clear() {
${SUB_CLASS_VARIABLE_NAME}.clear();
}
public boolean ${PREFIX}isEmpty() {
return ${SUB_CLASS_VARIABLE_NAME}.isEmpty();
}
public ${SUB_CLASS_NAME}[] ${PREFIX}toArray() {
return (${SUB_CLASS_NAME}[]) ${SUB_CLASS_VARIABLE_NAME}.toArray(new ${SUB_CLASS_NAME}[0]);
}
public ${SUB_CLASS_NAME} get${PREFIX}(int i) {
return (${SUB_CLASS_NAME}) ${SUB_CLASS_VARIABLE_NAME}.get(i);
}
public ${SUB_CLASS_NAME} remove${PREFIX}(int i) {
return (${SUB_CLASS_NAME}) ${SUB_CLASS_VARIABLE_NAME}.remove(i);
}
public void add${PREFIX}(int i, ${SUB_CLASS_NAME} ${METHOD_PARAMATER_NAME}) {
${SUB_CLASS_VARIABLE_NAME}.add(i,${METHOD_PARAMATER_NAME});
}
public int indexOf${PREFIX}(${SUB_CLASS_NAME} ${METHOD_PARAMATER_NAME}) {
return ${SUB_CLASS_VARIABLE_NAME}.indexOf(${METHOD_PARAMATER_NAME});
}
public int lastIndexOf${PREFIX}(${SUB_CLASS_NAME} ${METHOD_PARAMATER_NAME}) {
return ${SUB_CLASS_VARIABLE_NAME}.lastIndexOf(${METHOD_PARAMATER_NAME});
}
public boolean add${PREFIX}(${SUB_CLASS_NAME} ${METHOD_PARAMATER_NAME}) {
return ${SUB_CLASS_VARIABLE_NAME}.add(${METHOD_PARAMATER_NAME});
}
public boolean contains${PREFIX}(${SUB_CLASS_NAME} ${METHOD_PARAMATER_NAME}) {
return ${SUB_CLASS_VARIABLE_NAME}.contains(${METHOD_PARAMATER_NAME});
}
public boolean remove${PREFIX}(${SUB_CLASS_NAME} ${METHOD_PARAMATER_NAME}) {
return ${SUB_CLASS_VARIABLE_NAME}.remove(${METHOD_PARAMATER_NAME});
}
public boolean addAll${PREFIX}(int i, ${CLASS_NAME} collection) {
return ${SUB_CLASS_VARIABLE_NAME}.addAll(i, collection.get${SUB_CLASS_ACCESSOR}());
}
public boolean addAll${PREFIX}(${CLASS_NAME} collection) {
return ${SUB_CLASS_VARIABLE_NAME}.addAll(collection.get${SUB_CLASS_ACCESSOR}());
}
public boolean containsAll${PREFIX}(${CLASS_NAME} collection) {
return ${SUB_CLASS_VARIABLE_NAME}.containsAll(collection.get${SUB_CLASS_ACCESSOR}());
}
public boolean removeAll${PREFIX}(${CLASS_NAME} collection) {
return ${SUB_CLASS_VARIABLE_NAME}.removeAll(collection.get${SUB_CLASS_ACCESSOR}());
}
public boolean retainAll${PREFIX}(${CLASS_NAME} collection) {
return ${SUB_CLASS_VARIABLE_NAME}.retainAll(collection.get${SUB_CLASS_ACCESSOR}());
}
public ${CLASS_NAME} sub${CLASS_NAME}${PREFIX}(int i, int i1) {
return new ${CLASS_NAME}(${SUB_CLASS_VARIABLE_NAME}.subList(i,i1));
}
public ${CLASS_NAME}Iterator ${PREFIX}listIterator() {
return new ${CLASS_NAME}Iterator (${SUB_CLASS_VARIABLE_NAME}.listIterator());
}
public ${CLASS_NAME}Iterator ${PREFIX}listIterator(int i) {
return new ${CLASS_NAME}Iterator (${SUB_CLASS_VARIABLE_NAME}.listIterator(i));
}
public ${SUB_CLASS_NAME} set${PREFIX}(int i, ${SUB_CLASS_NAME} ${METHOD_PARAMATER_NAME}) {
return (${SUB_CLASS_NAME}) ${SUB_CLASS_VARIABLE_NAME}.set(i,${METHOD_PARAMATER_NAME});
}
}