Generically Yours
May. 13th, 2013 09:55 pmI spent today immersed in Java generics, trying to figure out how to write an abstract base class using generics that would do everything that I wanted it to do. I've coded something up and sent it to one of the fellows in the shop who is a good bit further along with Java coding than I am (since I am at less than a week, that wouldn't be saying a lot, but apparently he's quite good) and we'll see what he has to say about my questions on the subject.
The thing that's causing me the problem is that I'm building a tree of items (in arbitrary order, so it doesn't look like there's anything in the Collection classes that quite does what I need) where each node in the tree has a unique key. Normally, that key is a String and needs to be searched for in a case-insensitive fashion. But in one of the cases where I want to use this generic tree class, the key is going to be a complex object, because when I'm storing time periods, you can't really compare any sort of reasonable human-readable String using a normal String comparison and get the right answer.
I'm trying to code a Find function and pass it my arbitrary generic Key and I'm having a real problem getting it to work. Maybe what I should be doing is actually storing the TreeItems in a Tree and putting a HashMap into the Tree to solve the Find problem. Except right now, I'm storing just one reference to the HashMap in the root object for the Tree.
Of course, if the generic Tree class extends the generic TreeItem class, I could probably get that trick to work... :)
The thing that's causing me the problem is that I'm building a tree of items (in arbitrary order, so it doesn't look like there's anything in the Collection classes that quite does what I need) where each node in the tree has a unique key. Normally, that key is a String and needs to be searched for in a case-insensitive fashion. But in one of the cases where I want to use this generic tree class, the key is going to be a complex object, because when I'm storing time periods, you can't really compare any sort of reasonable human-readable String using a normal String comparison and get the right answer.
I'm trying to code a Find function and pass it my arbitrary generic Key and I'm having a real problem getting it to work. Maybe what I should be doing is actually storing the TreeItems in a Tree and putting a HashMap into the Tree to solve the Find problem. Except right now, I'm storing just one reference to the HashMap in the root object for the Tree.
Of course, if the generic Tree class extends the generic TreeItem class, I could probably get that trick to work... :)