*
The moose likes Beginning Java and the fly likes Subclassing and creating a new instance of a variable and putting it into a HashMap Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Subclassing and creating a new instance of a variable and putting it into a HashMap" Watch "Subclassing and creating a new instance of a variable and putting it into a HashMap" New topic
Author

Subclassing and creating a new instance of a variable and putting it into a HashMap

Noam Ingalls
Ranch Hand

Joined: Jan 11, 2012
Posts: 60

Hi. I haven't much experience constructing classes with parameters to be honest which is why I'm feeling a bit lost now. In my project I have these classes I'm currently working with that are mapped to 2 different HashMaps: HashMap #1 contains all the xStatement classes (for keywords) e.g. a StringStatement class which implements the Directive interface, and the second HashMap stores variable names and values for easier search and manipulation; it has the TPLVariable class with constructor for a variable name, which is extended by the TPLString with constructors for the respective values plus the superclass constructor (so the TPLString class constructor should have strings for the variable's name and value), and TPLInteger classes.

I start with a String from an ArrayList, which is broken into two Strings (parts[]). The first part of the String is the keyword that maps to HashMap 1 (parts[0])and tells the program which of the Statement classes it's supposed to call up. After the appropriate Statement class is triggered, the contents of parts[1] is what gets processed in it. parts[1] is tokenized and parsed and saved into the HashMap #2 as variable name and values, but I need some way to check whether the value being instantiated is a String or an int. Now in the StringStatement class, what's supposed to happen is that I need to instantiate a new TPLString type of TPLVariable, with its name and an empty string. Later on I need to be able to change the empty string to some assigned value. The same thing goes for the TPLInteger class. How should I write my constructor(s) for the various classes so it can do that? Need some hints as to what I should be doing with all these. Thanks for the help in advance!


Relevant code:




"How do you define fool?"
"I don't attempt it. I wait for demonstrations. They inevitably surpass my imagination."
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Subclassing and creating a new instance of a variable and putting it into a HashMap
 
Similar Threads
iterating a hashmap
Sun Cirtification
Returning more than one value?
Not sure whether to override or overload methods in interface
Data storage for interpreter