This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I'm trying to work out some code for a scheduling system which takes an id, works out if this id is an person or a group. If its a person, then easy to return but I'm having some issue regarding the return of the individuals in a group. (Its a hack around an issue in the calDAV specs.) My code queries a database via two methods (one for individuals and one to return a list of individuals in a group). I've iterated through the returned list and placed into the uri string but I cannot then return all the users to another method which works on another scheduling task - I either get the first or the last. Is there a sensible way around this (I'm trying to debug some code which relies on returning a list but its making the job harder than it need be and the code less maintainable)?
Difficult to understand what you want, but you can only return one thing from a method. You appear to get a String from caladdrToUsers and a List<String> later on.
If you have an ID you can obtain, you ought to be able to pass/return it with the flag for individual/group.
Joined: Oct 11, 2007
What I want to do is to take the List and then return each of the IDs contained in it if it is a group. The method above takes a string then calls the caladdToUser(s) methods to work out if the string is group or an individual. What I'd like to do is to then take the returned list (morelists), iterate through it and return the each id inside it (passed back to uri). As per my post, I can either get the first or the last but I'd also like the bits in between.
The schedule relies on having the individual id not the group, hence trying to do this. [Edited to add second paragraph] [ August 22, 2008: Message edited by: Iain Emsley ]
Joined: Oct 13, 2005
There is something very peculiar in that method; you are getting a String from calladdrToUser() and later a List from the same method. I am surprised that will compile. What does that calladdrToUser() method return?
Originally posted by Iain Emsley: I've iterated through the returned list and placed into the uri string but I cannot then return all the users...
Your method is designed to return a String. That isn't a good choice if it is supposed to return "all the users". Unless you can cram them all into a String in some way, which I don't recommend unless somebody else has required you to return a String and you don't have the choice of returning a List of Strings.
Which is what you should do. Return a List<String>, not a String. Inside the method, create an empty list. If you're iterating through a group, then add the uri's to the list. If you have an individual, add that uri to the list. Then return that list as the value of the method.