Results 1 to 1 of 1
- 05-18-2010, 01:53 AM #1Member
- Join Date
- May 2010
- Rep Power
Iterator as return and argument or Iterator-String(not visible in the test file)
Welcome from a Cobol employed in the past. Not currently as now i don't work but to imagine how hard for me is this.
I'm doing a Snow Manager to record incidencies in roads caused by the snow. One of the methods consists in show the notifications of a user (Class User, as you can guess) of the roads he's subscribed in. Actually the method is this:
public Iterator viewMessages(String userId)
User subbed = getUser(userId);
Iterator<UserRoad> sub = subbed.getUserRoad();
//SOME INTERMEDIAL PASS, THAT I DON'T KNOW WHAT CAN BE, AND GETINCIDENTS STILL NOT IMPLEMENTED
Iterador<RoadMessage> incidents = some_variable_of_Road_class.getIncidents();
if (incidents == null) throw new EIException("There are no messages");
I have done the method getUserRoad:
public Iterador getUserRoad() throws EIException
if (usersRoad.isEmpty() == true)
throw new EIException("There are no messages");
So actually i've got "sub" that has an Iterator of UserRoad with the roads subscribed by that user. UserRoad only storages (as attribute) the RoadId.
The problem comes with the association created in the class Road, roadsMessages (class RoadMessage), and the class Road have three attributes: RoadId, source and destination. So I need some type of variable of type Road.
I have thought in two possible options:
1- create a method for transform the iterator in a String to look for in every Road in that string in the roadsMessages to get the notifications of that road. The problem of this option is that I should pass by the toString method and in the output test file doesn't show a list of the roads subscribed. I don't know if would have another way to convert it to String without necessity of show it (really new to OOP ¬¬). To see the output test file, the argument is the user, and the result is the Id of the message and the Id of the user who put the incident:
2- create a method to transform the Iterator<UserRoad> in a Iterator<Road<. I think is the most logical option. As you all have guessed, both doesn't have the same data, so not possible to make variable_of_type_Road = sub. With that Road iterator, implement getIncidents accessing for every element in the iterator to the RoadMessage. The problem of this option is that I have not seen anything method that take an Iterator argument and returns another Iterator. Something like:
Public Iterator<Road> getRoadsSubscribed (Iterator<UserRoad> sub)
I can't change the definition of the method viewMessages, as was part of the template and being a university practise is to accomplish it.
Sorry for my poor language but english isn't my natural language.
- By Harb in forum New To JavaReplies: 13Last Post: 11-21-2009, 08:25 PM
- By alpdog14 in forum New To JavaReplies: 2Last Post: 10-13-2009, 09:42 PM
- By mayhewj7 in forum New To JavaReplies: 1Last Post: 04-08-2009, 04:45 AM
- By venkatallu in forum Advanced JavaReplies: 3Last Post: 09-23-2008, 02:32 PM
- By eva in forum New To JavaReplies: 0Last Post: 01-31-2008, 03:07 PM