private static float getQualityFactor(String pAccept, String pContentType) {
        float qFactor = 0;
        int foundIndex = pAccept.indexOf(pContentType);
        if (foundIndex >= 0) {
            int startQIndex = foundIndex + pContentType.length();
            if (startQIndex < pAccept.length() && pAccept.charAt(startQIndex) == ';') {
                while (startQIndex < pAccept.length() && pAccept.charAt(startQIndex++) == ' ') {
                    // Skip over whitespace
                }

                if (pAccept.charAt(startQIndex++) == 'q' && pAccept.charAt(startQIndex++) == '=') {
                    int endQIndex = pAccept.indexOf(',', startQIndex);
                    if (endQIndex < 0) {
                        endQIndex = pAccept.length();
                    }

                    try {
                        qFactor = Float.parseFloat(pAccept.substring(startQIndex, endQIndex));
                        //System.out.println("Found qFactor " + qFactor);
                    }
                    catch (NumberFormatException e) {
                        // TODO: Determine what to do here.. Maybe use a very low value?
                        // Ahem.. The specs don't say anything about how to interpret a wrong q factor..
                        //System.out.println("Unparseable q setting; " + e.getMessage());
                    }
                }
                // TODO: Determine what to do here.. Maybe use a very low value?
                // Unparseable q value, use 0
            }
            else {
                // Else, assume quality is 1.0
                qFactor = 1;
            }
        }
        return qFactor;
    }
private static float getQualityFactor ( String pAccept , String pContentType ) { float qFactor = 0 ; int foundIndex = pAccept . indexOf ( pContentType ) ; if ( foundIndex >= 0 ) { int startQIndex = foundIndex + pContentType . length ( ) ; if ( startQIndex < pAccept . length ( ) && pAccept . charAt ( startQIndex ) == ';' ) { while ( startQIndex < pAccept . length ( ) && pAccept . charAt ( startQIndex ++ ) == ' ' ) { } if ( pAccept . charAt ( startQIndex ++ ) == 'q' && pAccept . charAt ( startQIndex ++ ) == '=' ) { int endQIndex = pAccept . indexOf ( ',' , startQIndex ) ; if ( endQIndex < 0 ) { endQIndex = pAccept . length ( ) ; } try { qFactor = Float . parseFloat ( pAccept . substring ( startQIndex , endQIndex ) ) ; } catch ( NumberFormatException e ) { } } } else { qFactor = 1 ; } } return qFactor ; }
@param pAccept the accpet header value
@param pContentType the content type to get the quality factor for
@return the q factor of the given format, according to the accept header