private static boolean isBetterOption(BigDecimal bestQuality, Variant best,
BigDecimal optionQuality, Variant option)
{
if (best == null)
return true;
MediaType bestType = best.getMediaType();
MediaType optionType = option.getMediaType();
if (bestType != null && optionType != null)
{
if (bestType.getType().equals(optionType.getType()))
{
// Same type
if (bestType.getSubtype().equals(optionType.getSubtype()))
{
// Same subtype
int bestCount = bestType.getParameters().size();
int optionCount = optionType.getParameters().size();
if (optionCount > bestCount)
return true; // more matching parameters
else if (optionCount < bestCount)
return false; // less matching parameters
}
else if ("*".equals(bestType.getSubtype()))
{
return true; // more specific subtype
}
else if ("*".equals(optionType.getSubtype()))
{
return false; // less specific subtype
}
}
else if ("*".equals(bestType.getType()))
{
return true; // more specific type
}
else if ("*".equals(optionType.getType()))
{
return false; // less specific type;
}
}