public boolean accepts(MediaType item) { if ( ! accept(this.getType(), item.getType()) ) return false ; return accept(this.getSubType(), item.getSubType()) ; }
int subweight() { int x = 0 ; if ( !isStar(getType())) x += 2 ; if ( !isStar(getSubType())) x += 1 ; return x ; }
private static List<MediaRange> stringToAcceptList(String s) { List<MediaRange> ranges = new ArrayList<>(); if ( s == null ) return ranges; String[] x = s.split(","); for ( String aX : x ) { if ( aX.equals("") ) { continue; } MediaRange mType = new MediaRange(aX); ranges.add(mType); } return ranges; }
@Override public int compare(MediaRange mType1, MediaRange mType2) { int r = Double.compare(mType1.get_q(), mType2.get_q()) ; if ( r == 0 ) r = subCompare(mType1.getType(), mType2.getType()) ; if ( r == 0 ) r = subCompare(mType1.getSubType(), mType2.getSubType()) ; // if ( r == 0 ) { // // This reverses the input order so that the rightmost elements is the // // greatest and hence is the first mentioned in the accept range. // // if ( mType1.posn < mType2.posn ) // r = +1 ; // if ( mType1.posn > mType2.posn ) // r = -1 ; // } // The most significant sorts to the first in a list. r = -r ; return r ; }
public MediaRange(String type, String subType, String charset) { super(type, subType, charset) ; set_q() ; }
private void set_q() { String qStr = getParameter("q") ; if ( qStr == null ) return ; try { q = Double.parseDouble(qStr) ; } catch (NumberFormatException ex) { Log.warn(this, "Bad q seen: "+qStr) ; } }
/** * Create a list of accept items from the give MediaTypes. * @param acceptItems */ public static AcceptList create(MediaType... acceptItems) { AcceptList accepList = new AcceptList(); for ( MediaType mtype : acceptItems ) accepList.ranges.add(new MediaRange(mtype)); return accepList; }
@Override public int compare(MediaRange mType1, MediaRange mType2) { int r = Double.compare(mType1.get_q(), mType2.get_q()) ; if ( r == 0 ) r = subCompare(mType1.getType(), mType2.getType()) ; if ( r == 0 ) r = subCompare(mType1.getSubType(), mType2.getSubType()) ; // if ( r == 0 ) // { // // This reverses the input order so that the rightmost elements is the // // greatest and hence is the first mentioned in the accept range. // // if ( mType1.posn < mType2.posn ) // r = +1 ; // if ( mType1.posn > mType2.posn ) // r = -1 ; // } // The most significant sorts to the first in a list. r = -r ; return r ; }
public MediaRange(MediaType other) { super(other) ; set_q() ; }
private void set_q() { String qStr = getParameter("q") ; if ( qStr == null ) return ; try { q = Double.parseDouble(qStr) ; } catch (NumberFormatException ex) { Log.warn(this, "Bad q seen: "+qStr) ; } }
int subweight() { int x = 0 ; if ( !isStar(getType())) x += 2 ; if ( !isStar(getSubType())) x += 1 ; return x ; }
public boolean accepts(MediaType item) { if ( ! accept(this.getType(), item.getType()) ) return false ; return accept(this.getSubType(), item.getSubType()) ; }
/** * Create a list of accept items from strings. * @param acceptStrings */ public static AcceptList create(String... acceptStrings) { AcceptList accepList = new AcceptList(); for ( String acceptString : acceptStrings ) { accepList.ranges.add(new MediaRange(acceptString)); } return accepList; }