
12-05-2008, 01:23 PM
|
|
Member
|
|
Join Date: Dec 2008
Posts: 9
Rep Power: 0
|
|
accessing hashtables from another class
Hi, very very new to Java (this is my first post)!
I am trying to access a set of Hashtables that I have created in another class but am having real difficulty getting my head around it.
Data is loaded from a file in the class DataAccess
Set into a group of Hashtables in Timeseries
I am then looking to query the group of hash tables in class TimeseriesManipulation, but keep getting a error. All the classes are in the same package.
I can't figure out how from the Engine class I call class DataManipulation and once I've successfully called the class I don't know the syntax to get data out of the hashtables.
Can someone help please.
Please find attched a txt file with all relevant code. (if you cannot access the code please let me know).
Very many thanks
|
|

12-05-2008, 03:15 PM
|
 |
Moderator
|
|
Join Date: Jun 2008
Posts: 6,506
Rep Power: 8
|
|
|
Have you first gone through a basic Java textbook or tutorial series before trying to do this code? From the code I've seen, it looks as if you're trying to fly before you can crawl as there are mistakes that suggest misconceptions of basic core Java such as trying to use objects before they have been declared. It's either that or you have tried to borrow other code but have only done so incompletely. If the former, then I hate to say this but the only solution that I see to this is for you to stop what you are doing and study up on the rudiments of the language. If the latter, then don't do this. Learn how to understand what you are doing before trying to borrow other's code. Again, the tutorials will help you immensely here.
Last edited by Fubarable; 12-05-2008 at 03:20 PM.
|
|

12-05-2008, 04:00 PM
|
|
Member
|
|
Join Date: Dec 2008
Posts: 9
Rep Power: 0
|
|
|
Thanks for the reply, this is my own code. I've tried reading up and obviously I have not grasped something. Apart from re reading a 1500 word text book in my free time and missing which ever concept i've suppose to have missed again (which you did not make clear) this is my only source help. I am not at college/school or frustratingly work as unemployed. Can someone please help me with a practical solution to my problem please?
|
|

12-05-2008, 04:06 PM
|
 |
Moderator
|
|
Join Date: Jun 2008
Posts: 6,506
Rep Power: 8
|
|
|
I tried compiling your code and found many many errors suggesting that you're breaking one of the first rules of coding: adding good code to bad code. The best solution for this code is what I call the "Old Yeller" treatment.
Also remember that when coding you should:
* Only add small amounts of code to a project at a time.
* Before adding code to a project, compile it first, run it if possible, and make sure that there are no errors first.
* If you find compile or run-time errors, fix them first before adding any code.
* Work with smaller classes that are testable in their own right. This often means heavy use of interfaces.
Good luck.
|
|

12-05-2008, 04:14 PM
|
|
Member
|
|
Join Date: Dec 2008
Posts: 9
Rep Power: 0
|
|
|
I tried to par the code down so it was easier to read. Please find attched new txt with all the code. The only errors should now be associated with my problem (in the Engine and TimeSeriesManipulation classes).
|
|

12-05-2008, 04:17 PM
|
 |
Moderator
|
|
Join Date: Jun 2008
Posts: 6,506
Rep Power: 8
|
|
|
what about the text file?
|
|

12-05-2008, 04:24 PM
|
 |
Moderator
|
|
Join Date: Jun 2008
Posts: 6,506
Rep Power: 8
|
|
Also, describe what each class is supposed to be doing? Where are you comments / javadoc notes?
Also, here:
|
Code:
|
public class TimeSeriesManipulation
{
void addIdTogether(int start, int finish)
{
int Total = 0;
myTimeseries.displayTsRecord("1234561");
for (int i = start; i < finish; i++)
{
String newString = "1234" + i;
//Total=Total+Timeseries.getSingleId(newString);
Timeseries.this.getSingleId(newString);
}
}
} |
you're using Timeseries.this.... as if this method were being called from within an instance of a Timeseries object. It's not, and so this has no meaning here. You must have an instance of this object here.
You're also using an instance, myTimeseries without declaring or instantiating it. Both of these errors go to the core of basic Java programming.
Edit: similar problems are occuring with the Engine class:
|
Code:
|
import java.io.IOException;
import java.util.Hashtable;
public class Engine
{
public static void main(String[] arguments) {
DataAccess tsData = new DataAccess("c:\\PairsData\\timeseries1.txt");
addIdTogether TSMan = new TimeSeriesManipulation(myTimeseries);
System.out.println(Timeseries.class.myTimeseries.getSingleId("1234561"));
myTimeseries.
}
} |
addItTogether is a method but you seem to be treating it as a class. How can that work/
Timeseries.class.myTimeseries ahs no meaning here. Do you instead want to declare and initialize a Timeseries object here and use it?
Finally, what is "myTimeseries." for?
Last edited by Fubarable; 12-05-2008 at 04:27 PM.
|
|

12-05-2008, 04:26 PM
|
|
Member
|
|
Join Date: Dec 2008
Posts: 9
Rep Power: 0
|
|
|
can you see it now (Hashtable access1.txt) attached? If not I'll copy it into the mesage box
|
|

12-05-2008, 04:31 PM
|
|
Member
|
|
Join Date: Dec 2008
Posts: 9
Rep Power: 0
|
|
|
Engine- this is the main class
DataAccess - Time series data from text files is accessed and put into some Hashtables
Timeseries - Gives the hashtables a common theme namily belonging to a type timeseries
TimeSeriesManipulation - this is where I would like to access the hash tables and manipulate the data
|
|

12-05-2008, 04:41 PM
|
 |
Moderator
|
|
Join Date: Jun 2008
Posts: 6,506
Rep Power: 8
|
|
Originally Posted by SimC
|
|
can you see it now (Hashtable access1.txt) attached? If not I'll copy it into the mesage box
|
my bad, I meant the data file, "timeseries1.txt"
|
|

12-05-2008, 04:51 PM
|
|
Member
|
|
Join Date: Dec 2008
Posts: 9
Rep Power: 0
|
|
|
ahh please see attached
|
|

12-05-2008, 05:08 PM
|
 |
Moderator
|
|
Join Date: Jun 2008
Posts: 6,506
Rep Power: 8
|
|
|
I'm still having a great deal of difficulty trying to figure out what you are trying to do here. It seems as if you are trying to store numeric data into a bunch of parallel HashTables. Why? Why not group data that needs to be stored together into a single object and place that object into a HashMap if need be? Or better still use a database which was built to store lots of data?
Your design may need to be completely rethought here.
|
|

12-05-2008, 05:15 PM
|
 |
Moderator
|
|
Join Date: Jun 2008
Posts: 6,506
Rep Power: 8
|
|
|
Going through some of this. First I see that you are hard-coding your file strings in your program. Don't do this as it's very very bad practice and makes your program hard to maintain and harder for others to try out. For one instance, I will have a different directory structure than you. Also, don't make logical decisions based on file names. What if they're changed in the future?
|
|

12-05-2008, 05:19 PM
|
|
Member
|
|
Join Date: Dec 2008
Posts: 9
Rep Power: 0
|
|
|
The Timeseries1 file is only one record long, this is just for testing. In reality this file will consist of thousands of day records for thousands of different stocks. I need to be able to query the tables quickly and very often. All the individual data types in the hash tables will eventually be analysed individually. eg beta data for a number of days will be queried, analysed and a result put somewhere.
I do not have access to database software. Does this help?
|
|

12-05-2008, 05:22 PM
|
 |
Moderator
|
|
Join Date: Jun 2008
Posts: 6,506
Rep Power: 8
|
|
|
Quote:
|
|
In reality this file will consist of thousands of day records for thousands of different stocks. I need to be able to query the tables quickly and very often.
|
Then it's settled. You don't need to re-invent the wheel as the only thing that will work here, and I mean only thing, is a database. Anything else is bound to fail.
|
Quote:
|
|
I do not have access to database software.
|
now you're talkin' nonsense. We all have access to database software; all you have to do is to download mySQL or some other free database and start learning it.
|
|

12-05-2008, 05:23 PM
|
|
Member
|
|
Join Date: Dec 2008
Posts: 9
Rep Power: 0
|
|
|
don't worry about that I know about hard coding address, I just did it to get this project running. It will be changed at some point
|
|

12-05-2008, 05:24 PM
|
|
Member
|
|
Join Date: Dec 2008
Posts: 9
Rep Power: 0
|
|
|
no, believe me this has to work without a database (it has to)
|
|

12-05-2008, 05:25 PM
|
 |
Moderator
|
|
Join Date: Jun 2008
Posts: 6,506
Rep Power: 8
|
|
|
why is this so?
|
|

12-05-2008, 05:47 PM
|
 |
Moderator
|
|
Join Date: Oct 2008
Location: Mexico
Posts: 1,159
Rep Power: 3
|
|
Corrections
Some observations: - Do not compare strings using "==".. use the String methods of equal, compare, etc
|
Code:
|
if (address == "c:\\PairsData\\timeseries1.txt")//wrong !!! |
- The variable eof (at least in the file I was looking at) is initalized as false
|
Code:
|
boolean eof = false; |
but it is never is set to true therefore, the following use of eof serves no purpose:
|
Code:
|
while ((thisLine = buff.readLine()) != null && !eof) |
I'm coming to the conclution that this code is too buggy even start to review it.
Luck,
CJSL
__________________
Chris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
|
|

12-05-2008, 05:49 PM
|
 |
Moderator
|
|
Join Date: Jun 2008
Posts: 6,506
Rep Power: 8
|
|
|
Quote:
|
|
I'm coming to the conclution that this code is too buggy even start to review it.
|
I agree, but even more important than the code, what about the premise of using a bunch of hashtables (not even generic HashMaps) in parallel here instead of a stable database?
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT +2. The time now is 04:30 PM.
|
|