edu.wisc.trace.urcsdk.client.resources
Class DefaultOptimizer

java.lang.Object
  extended by edu.wisc.trace.urcsdk.client.resources.DefaultOptimizer
All Implemented Interfaces:
IResourceOptimizer

public class DefaultOptimizer
extends java.lang.Object
implements IResourceOptimizer

DefaultOptimizer is the default implementation of the IResourceOptimizer. The algorithm it uses scales well and should be acceptable for most implementations. Limitations of the DefaultOptimizer: - does not optimize resources based on a weighted system, therefore all prefs have the same value. So a client that would prefer a resource in a particular format might not get it if there is another resource with a different format but all other prefs match. - if two resource sheets are identical, the first one with the best prefs match is chosen.

Version:
$Revision: 1.21 $
Author:
Andrew Martin, Hemanth Vijayan

Constructor Summary
DefaultOptimizer()
           
 
Method Summary
 IResource pickResource(java.util.List<IResource> reslist1, java.util.List<IResource> reslist2, UserPreferences userPrefs, boolean isFinal)
          This method chooses the best resource amongs two resource lists-reslist1 and reslist2 based on the userPrefs.
 IResource pickResource(java.util.List<IResource> resources, UserPreferences userPrefs, boolean isFinal)
          P-code for picking algorithm:
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultOptimizer

public DefaultOptimizer()
Method Detail

pickResource

public IResource pickResource(java.util.List<IResource> reslist1,
                              java.util.List<IResource> reslist2,
                              UserPreferences userPrefs,
                              boolean isFinal)
This method chooses the best resource amongs two resource lists-reslist1 and reslist2 based on the userPrefs. isFinal is true if the resource manager cannot parse any more resource sheets to pick the best resource, so the optimizer picks the next best resource. If isFinal is false, a null value is passed back if the optimizer wants the resource manager to parse more resources. Returning an IResource.EMPTY_RESOURCE implys an abort. The Default optimizer does not abort.

Specified by:
pickResource in interface IResourceOptimizer
Parameters:
reslist1 -
reslist2 -
userPrefs -
isFinal - reslist1 and reslist2 can be null
Returns:
the best avaialable resource

pickResource

public IResource pickResource(java.util.List<IResource> resources,
                              UserPreferences userPrefs,
                              boolean isFinal)

P-code for picking algorithm:

>switch IResource list size:
                case 0: 
                        return EmptyResource 
                case 1: 
                        return first element of list 
                default: 
                        bestResource = null 
                        bestScore = 0 
                        for each resource in IResource list
                                score = 0 
                                for each property in uprefs
                                        for each value in list 
                                                if value with matching property and value exists in resource
                                                        add 1 to score
                                if score > bestScore 
                                        bestScore = score
                                        bestResource = resource
 
                        return bestResource
 

Parameters:
userPrefs - an UserPreferences value
Returns:
an IResource value


Copyright © 2006 Trace R&D Center, University of Wisconsin-Madison. All Rights Reserved.