• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A question about generics

 
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am writing a simple object database, that uses an AVL tree, and am trying to implement it using generics.

The database recieves recieves a request(insert, find, delete, whatever) and and in the case of insert, recieves an object and then passes it to the appropriate AVL method.

I am writing this for a specific project but would like to be able to reuse the simple database. I can easily write it using Comparable as the type, but am wanting to use generics.

This is what I have so far, I used a fairly confusing tutorial online. This is legal syntax, but I am not sure if it is correct. I will be needing to access a specific method to search for a specific search criteria, so I am thinking of requiring another interface for this purpose, would I need to add another parameter type so the tree can use both interface types? The objects being stored, are custom, but would like this to be usable by common API class(Integer, String, ect), which makes the requirement for a second interface seem wrong.

So here is the code so far:





Assuning that this is correct(big assumption I know), how would one instantiate an object of AVLTree?

Any comments, advice or links would be greatly appreciated.
[ August 15, 2006: Message edited by: Rusty Shackleford ]
 
Rusty Shackleford
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess my question was too confusing, vague or not worth replying to. Let me try again.

I am writing a simple database that creates an AVL tree, and would like the tree to be able to accept any type using generics. The issue is that the object that will be initially used has many members with a String being used as a key for searching and sorting. To find an object a String(or Integer, ect) will be passed to the the tree. The problem is this works easily if the tree is of type String, not my custom object.

So is the above code proper use of generics to get this behavior, if not what is the correct approach?
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess that Node.left and Node.right should be of type Node<T>?
 
This tiny ad is wafer thin:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic