java - Best way to make many generic objects -


background

for class, made linear-chaining hash table. stores array of linked lists, , whenever or put called, key hashed , modulo'd array size. or put called on resulting linked list (which implemented).

i have st (symbol table) interface. map, of map's required operations confusing me implement. implementing interface have implementations of linked list, red-black tree, linear-probing hash table, , linear-chaining hash table.

i make similar linear-chaining hash table accepts arbitrary delegate symbol table type. example, initializing red-black tree type make table of red-black trees, , , put functions delegate red-black trees.

i recognize implementations slower library-provided ones, , better off use in real code. trying experiment , learn.

question

what best way supply type hash table hash table consist of table of type, , calls delegate symbol tables?

i can't use generics because can't initialize those, , need initialize on construction , on re-sizing.

i thought providing blank symbol table of desired type start, , using copy method on that, seems there should better way. there?

you require factory provided creates instances of desired backing structure.

a simple example map delegates map:

public static interface supplier<t> {      t get(); }  public static class delegatingmap<k, v> implements map<k, v> {      private final map<k, v> backingmap;      public delegatingmap(final supplier<map<k, v>> backingmapsupplier) {         backingmap = backingmapsupplier.get();     }      @override     public int size() {         throw new unsupportedoperationexception("not supported yet."); //to change body of generated methods, choose tools | templates.     }      @override     public boolean isempty() {         throw new unsupportedoperationexception("not supported yet."); //to change body of generated methods, choose tools | templates.     }     //etc... } 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -