/** * Creates a new AcceptLanguageHeader based on the newly supplied * language value. * * @param language - the new Locale value of the language * @return the newly created AcceptLanguageHeader object. */ public AcceptLanguageHeader createAcceptLanguageHeader(Locale language) { if (language == null) throw new NullPointerException("null arg"); AcceptLanguage acceptLanguage = new AcceptLanguage(); acceptLanguage.setAcceptLanguage(language); return acceptLanguage; }
/** * Return true if the q value has been set. * @since 1.0 * @return boolean */ public boolean hasQValue() { return hasParameter("q"); }
/** * Remove the q value. * @since 1.0 */ public void removeQValue() { removeParameter("q"); }
AcceptLanguage acceptLanguage = new AcceptLanguage(); acceptLanguage.setHeaderName(SIPHeaderNames.ACCEPT_LANGUAGE); if (lexer.lookAhead(0) != ';') { acceptLanguage.setLanguageRange(value.getTokenValue()); try { float fl = Float.parseFloat(value.getTokenValue()); acceptLanguage.setQValue(fl); } catch (NumberFormatException ex) { throw createParseException(ex.getMessage());
headerName(TokenTypes.ACCEPT_LANGUAGE); do { AcceptLanguage acceptLanguage = new AcceptLanguage(); acceptLanguage.setLanguageRange(value.getTokenValue()); this.lexer.SPorHT(); while (lexer.lookAhead(0) == ';') { try { float fl = Float.parseFloat(value.getTokenValue()); acceptLanguage.setQValue(fl); } catch (NumberFormatException ex) { throw createParseException(ex.getMessage());
/** * Sets q-value for media-range in AcceptLanguageHeader. Q-values allow the * * user to indicate the relative degree of preference for that media-range, * * using the qvalue scale from 0 to 1. If no q-value is present, the * * media-range should be treated as having a q-value of 1. * * * * @param q The new float value of the q-value, a value of -1 resets * the qValue. * * @throws InvalidArgumentException if the q parameter value is not * * <code>-1</code> or between <code>0 and 1</code>. * */ public void setQValue(float q) throws InvalidArgumentException { if (q < 0.0 || q > 1.0) throw new InvalidArgumentException("qvalue out of range!"); if (q == -1) this.removeParameter("q"); else this.setParameter(new NameValue("q", Float.valueOf(q))); }
/** get the QValue field. Return -1 if the parameter has not been * set. * @return float */ public float getQValue() { if (!hasParameter("q")) return -1; return ((Float) parameters.getValue("q")).floatValue(); }