Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-05-2008, 01:23 PM
Member
 
Join Date: Dec 2008
Posts: 9
Rep Power: 0
SimC is on a distinguished road
Default 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
Attached Files:
File Type: txt hashtable access.txt (5.7 KB, 4 views)
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 12-05-2008, 03:15 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,506
Rep Power: 8
Fubarable is on a distinguished road
Default
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.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-05-2008, 04:00 PM
Member
 
Join Date: Dec 2008
Posts: 9
Rep Power: 0
SimC is on a distinguished road
Default
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?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 12-05-2008, 04:06 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,506
Rep Power: 8
Fubarable is on a distinguished road
Default
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.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 12-05-2008, 04:14 PM
Member
 
Join Date: Dec 2008
Posts: 9
Rep Power: 0
SimC is on a distinguished road
Default
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).
Attached Files:
File Type: txt hashtable access1.txt (13.2 KB, 2 views)
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 12-05-2008, 04:17 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,506
Rep Power: 8
Fubarable is on a distinguished road
Default
what about the text file?
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 12-05-2008, 04:24 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,506
Rep Power: 8
Fubarable is on a distinguished road
Default
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.
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 12-05-2008, 04:26 PM
Member
 
Join Date: Dec 2008
Posts: 9
Rep Power: 0
SimC is on a distinguished road
Default
can you see it now (Hashtable access1.txt) attached? If not I'll copy it into the mesage box
Attached Files:
File Type: txt hashtable access1.txt (13.2 KB, 2 views)
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 12-05-2008, 04:31 PM
Member
 
Join Date: Dec 2008
Posts: 9
Rep Power: 0
SimC is on a distinguished road
Default
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
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 12-05-2008, 04:41 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,506
Rep Power: 8
Fubarable is on a distinguished road
Default
Originally Posted by SimC View Post
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"
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 12-05-2008, 04:51 PM
Member
 
Join Date: Dec 2008
Posts: 9
Rep Power: 0
SimC is on a distinguished road
Default
ahh please see attached
Attached Files:
File Type: txt timeseries1.txt (96 Bytes, 2 views)
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 12-05-2008, 05:08 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,506
Rep Power: 8
Fubarable is on a distinguished road
Default
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.
Bookmark Post in Technorati
Reply With Quote
  #13 (permalink)  
Old 12-05-2008, 05:15 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,506
Rep Power: 8
Fubarable is on a distinguished road
Default
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?
Bookmark Post in Technorati
Reply With Quote
  #14 (permalink)  
Old 12-05-2008, 05:19 PM
Member
 
Join Date: Dec 2008
Posts: 9
Rep Power: 0
SimC is on a distinguished road
Default
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?
Bookmark Post in Technorati
Reply With Quote
  #15 (permalink)  
Old 12-05-2008, 05:22 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,506
Rep Power: 8
Fubarable is on a distinguished road
Default
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.
Bookmark Post in Technorati
Reply With Quote
  #16 (permalink)  
Old 12-05-2008, 05:23 PM
Member
 
Join Date: Dec 2008
Posts: 9
Rep Power: 0
SimC is on a distinguished road
Default
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
Bookmark Post in Technorati
Reply With Quote
  #17 (permalink)  
Old 12-05-2008, 05:24 PM
Member
 
Join Date: Dec 2008
Posts: 9
Rep Power: 0
SimC is on a distinguished road
Default
no, believe me this has to work without a database (it has to)
Bookmark Post in Technorati
Reply With Quote
  #18 (permalink)  
Old 12-05-2008, 05:25 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,506
Rep Power: 8
Fubarable is on a distinguished road
Default
why is this so?
Bookmark Post in Technorati
Reply With Quote
  #19 (permalink)  
Old 12-05-2008, 05:47 PM
CJSLMAN's Avatar
Moderator
 
Join Date: Oct 2008
Location: Mexico
Posts: 1,159
Rep Power: 3
CJSLMAN is on a distinguished road
Default 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.
Bookmark Post in Technorati
Reply With Quote
  #20 (permalink)  
Old 12-05-2008, 05:49 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,506
Rep Power: 8
Fubarable is on a distinguished road
Default
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?
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing inner class from outer class (an example) Java Tip Java Tips 0 02-17-2008 10:03 AM
An example of accessing outer class from inner class Java Tip Java Tips 0 02-17-2008 10:01 AM
Inner class accessing outer class Java Tip Java Tips 0 02-17-2008 09:59 AM
Accessing one class from another class through swing kbyrne AWT / Swing 5 01-03-2008 08:54 AM
Generic Hashtables ShoeNinja New To Java 0 12-04-2007 11:43 PM


All times are GMT +2. The time now is 04:30 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org