{
// Normally aItem is an offer - a concrete media type.
// ensureSorted() ;
// Search all, find best by specifivity, "q"(quality), and then first occurring if otherwise equal.
MediaRange choice = null ;
for ( MediaRange acceptItem : ranges )
{
if ( acceptItem.accepts(aItem) )
{
// Return the more grounded term
// E.g. aItem = text/plain ; acceptItem = text/*
if ( choice != null && choice.get_q() >= acceptItem.get_q() )
continue ;
// Return the more grounded term
// E.g. aItem = text/plain ; acceptItem = text/*
// This looses any q
if ( aItem.moreGroundedThan(acceptItem) )
{
// Clone/change.
acceptItem = new MediaRange(aItem.getType(), aItem.getSubType(), acceptItem.getCharset()) ;
}
choice = acceptItem ;
}
}
return choice ;