Results 1 to 11 of 11
  1. #1
    Tim99 is offline Member
    Join Date
    Dec 2011
    Posts
    13
    Rep Power
    0

    Default How access values of a map that has been pass as a parameter?

    Hi,

    I'm desperately thinking about this problem for days and would really, really appreciate some hints. Basically, I have a UserModel, which comprises a map<key,value> and I have absolutely no clue how to access these values later.

    Java Code:
    /**
     * A UserModel comprises statements about the user provided by certain entities.
     *
     * Example:
     * locationServiceId --> [New York]
     * weatherServiceId --> [cloudy,rainy]
     * purchaseHistoryId --> [DVD-X, DVD-Y, DVD-Z]
     */
    public class UserModel {
    	
    	// All statements about the user such as
    	private Map<ProviderId,Set<Statement>> statements = new HashMap<ProviderId,Set<Statement>>();	
    	
    	// Returns all statements provided by a certain provider
    	public Set<Statement> getStatements(ProviderId id){
    		return statements.get(id);
    	}
    }
    
    /**
     * A UserClassifier classifies users based on certain elements of their
     * model. For instance by their location or purchase behavior.  
     *
     */
    public interface UserClassifier {
    	public void classify(UserModel userModel);
    }
    
    public class LocationClassifier implements UserClassifier {
    	
            // perhaps some Binding-objects that tie stmts to
            // a ProviderId?
            // And a constructor Classifier(Binding ... bindings)?
            // Or some magic pattern? 
    
    	@Override
    	public void classify(UserModel userModel) {
    
    		// How can I access the location statements?
    		Set<Statement> locationStmts = userModel.getStatements(???);
                    Set<Statement> weatherStmts = userModel.getStatements(???);
    		...
    	}
    }
    Last edited by Tim99; 01-10-2012 at 03:56 PM. Reason: Corrected some mistakes

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default Re: How access values of a map that has been pass as a parameter?

    how to access these values later.
    Can you explain what you are trying to do?
    Can you show some sample code that you are having a problem with?

  3. #3
    Tim99 is offline Member
    Join Date
    Dec 2011
    Posts
    13
    Rep Power
    0

    Default Re: How access values of a map that has been pass as a parameter?

    Thank you for the reply. Is the code example in my initial posting not enough?

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default Re: How access values of a map that has been pass as a parameter?

    Please explain what I should look at to see your problem?

  5. #5
    Tim99 is offline Member
    Join Date
    Dec 2011
    Posts
    13
    Rep Power
    0

    Default Re: How access values of a map that has been pass as a parameter?

    In lines 39-41, I try to assign certain statements to a variable and have no clue how to access them.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default Re: How access values of a map that has been pass as a parameter?

    There is a lot of code missing. Without definitions, hard to say what can be done or what needs to be done.

    Where is the get() method defined?
    The closest method in UserModel is the getStatement() method which takes a ProviderID as argument.

    Do these need to be connected somehow?

    What is classify? It is coded like a constructor not a method.

  7. #7
    Tim99 is offline Member
    Join Date
    Dec 2011
    Posts
    13
    Rep Power
    0

    Default Re: How access values of a map that has been pass as a parameter?

    I corrected the mistakes (it should have been "getStatements" and "void classify"). What I'm looking for is a way for binding the stmts (line 40+41) to certain values of the map.

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default Re: How access values of a map that has been pass as a parameter?

    What happens if you use a ProviderId argument in the getStatements method?
    The Map class has methods that will return a list of the key values.

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    19

    Default Re: How access values of a map that has been pass as a parameter?

    Why do you need the Statements to specific provider ids?
    Do you need to know that a particular Set is from a particular id?

    If not, then just handle each Set one at a time...(Map has an entries() method that might prove useful).

  10. #10
    Tim99 is offline Member
    Join Date
    Dec 2011
    Posts
    13
    Rep Power
    0

    Default Re: How access values of a map that has been pass as a parameter?

    @Tolls: In order to classify users, I have to extract certain parts of their profiles. And I'm desperately trying to access them. Perhaps this could help:
    Java Code:
    public class LocationClassifier implements UserClassifier {
    	
    	Provider weatherProvider;
    	Provider locationProvider;
    	
    	public LocationClassifier(Provider weatherProvider, Provider locationProvider){
    		this.weatherProvider = weatherProvider;
    		this.locationProvider = locationProvider;
    	}
    	
    	@Override
    	public void classify(UserModel userModel) {
    
    		// How can I access the location statements?
    		Set<Statement> weatherStmts = userModel.getStatements(weatherProvider.getId());
    		Set<Statement> locationStmts = userModel.getStatements(locationProvider.getId());
    		...
    	}
    However, I absolutely have to make sure that someone who implements a new UserClassifier initializes all necessary providers. But how can I do this?

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    19

    Default Re: How access values of a map that has been pass as a parameter?

    You've got to understand that "in order to classify users" means nothing to us.
    We can't offer suggestions on nigh-on non-existent requirements.

    How you do this classification, and what is expected from it, is going to effect how you go about structuring your data.
    Obviously it is also quite likely to be more than can be done in a forum like this.

    I will say you are quite correct to be wary of that latest bit of code. Anything that requires someone to add in their own Providers into this classification code is suspect, unless (and this goes into my point previously) that is the only way you can handle "classifiying users".

Similar Threads

  1. Can we pass Parameter to the method through properties File.
    By deshmukh.niraj04 in forum New To Java
    Replies: 2
    Last Post: 04-18-2011, 09:41 AM
  2. Replies: 1
    Last Post: 03-11-2011, 01:55 PM
  3. how to pass value of table cell as parameter/attribute
    By ajincoep in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 02-08-2011, 03:04 PM
  4. how to pass parameter from one jsp to another jsp
    By kader_sit in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 06-10-2010, 02:04 PM
  5. I can't seem to pass a file through a parameter
    By daletron3030 in forum New To Java
    Replies: 5
    Last Post: 01-15-2009, 06:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •