Local Variables Passing info between classes etc.
From: Jeffrey Spoon (JeffreySpoon_at_hotmail.com)
Date: 08/13/04
- Next message: Andrew Thompson: "Re: Why doesn't this work?"
- Previous message: Lee Fesperman: "Re: jdbc help:sun.jdbc.odbc.JdbcOdbcDriver"
- Next in thread: Jeffrey Spoon: "Re: Local Variables Passing info between classes etc."
- Reply: Jeffrey Spoon: "Re: Local Variables Passing info between classes etc."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 13 Aug 2004 22:46:20 +0100
Hello again. I suppose I have a sort of general question. The program I
am working on has this method (which I posted in another thread).
public void parseArticleMethod (String articleField) {
System.out.println("Article Field: " + articleField);
String[] data = { articleField };
int i = 0;
String[] field = data[i].split("\\s+");
int len = field.length;
System. out.println("Record " + i + " has " + len + "
fields.");
if(len > 0) {
// System. out.println("First field: " + field[0]); //test
}
if(field[0].equals("Message-ID:")) {
System. out.println("Message-ID found: " + field[0]);
}else if(field[0].equals("From:")){
System. out.println("From found: " + field[0]);
}else if(field[0].equals("Subject:")){
System. out.println("Subject found: " + field[0]);
}else if(field[0].equals("Newsgroups:")){
System. out.println("Newsgroups found: " + field[0]);
}else if(field[0].equals("")){
System. out.println("Body found: " + field[0]);}
}//method parseArticleMethod
in a class, amongst other methods. Now it extends the class above it
which passes it the input a string at a time. Another class does the
input/output loop with the server/client. What I want to do is pass the
Message-ID etc. fields to an Article Object and initialise it with the
arguments parsed (such as the actual message-id etc.).
The trouble is, since it gets data a string at a time, that's fine for
the single line headers, but for the body it's a bit more difficult. The
parseArticleMethod needs to return to get the next line of input, by
returning itself and getting the response from the client/server
handling class. Declaring a set or array etc. inside the ParseArticle
method would simply reset it each time it is called. I think declaring
the set or array in the superclass might work, but this seems untidy as
the superclass doesn't need to know the contents of the set/array and
just generally confuses things. Am I missing something here, or should I
just declare it in the superclass (though I'm not even sure if that will
work since the class above may reset it also once it is called again).
Any help appreciated.
-- Jeffrey Spoon
- Next message: Andrew Thompson: "Re: Why doesn't this work?"
- Previous message: Lee Fesperman: "Re: jdbc help:sun.jdbc.odbc.JdbcOdbcDriver"
- Next in thread: Jeffrey Spoon: "Re: Local Variables Passing info between classes etc."
- Reply: Jeffrey Spoon: "Re: Local Variables Passing info between classes etc."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|