本文整理了Java中org.restlet.data.Preference.getQuality()
方法的一些代码示例,展示了Preference.getQuality()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Preference.getQuality()
方法的具体详情如下:
包路径:org.restlet.data.Preference
类名称:Preference
方法名:getQuality
[英]Returns the quality/preference level.
[中]返回质量/首选项级别。
代码示例来源:origin: org.restlet.jee/org.restlet.ext.jaxrs
/**
* Creates a new SortedMetadata from the given Metadata.
*
* @param preferences
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
private SortedMetadata(Collection<Preference<T>> preferences) {
SortedMap<Float, Collection<T>> map = new TreeMap<Float, Collection<T>>(
Collections.reverseOrder());
for (Preference<T> preference : preferences) {
Float quality = preference.getQuality();
Collection<T> metadatas = map.get(quality);
if (metadatas == null) {
metadatas = new ArrayList<T>(2);
map.put(quality, metadatas);
}
metadatas.add(preference.getMetadata());
}
Collection<Collection<T>> values = map.values();
this.metadatas = Collections.unmodifiableList(new ArrayList(values));
}
代码示例来源:origin: org.restlet.osgi/org.restlet
/**
* Returns the preferred metadata taking into account both metadata
* supported by the server and client preferences.
*
* @param supported
* The metadata supported by the server.
* @param preferences
* The client preferences.
* @return The preferred metadata.
*/
public static <T extends Metadata> T getPreferredMetadata(
List<T> supported, List<Preference<T>> preferences) {
T result = null;
float maxQuality = 0;
if (supported != null) {
for (Preference<T> pref : preferences) {
for (T metadata : supported) {
if (pref.getMetadata().isCompatible(metadata)
&& (pref.getQuality() > maxQuality)) {
result = metadata;
maxQuality = pref.getQuality();
}
}
}
}
return result;
}
代码示例来源:origin: org.restlet.osgi/org.restlet
/**
* Scores a list of metadata relatively to enriched client preferences.
*
* @param metadataList
* The list of metadata to score.
* @return The score.
*/
protected <T extends Metadata> float scoreMetadata(List<T> metadataList,
List<Preference<T>> prefs) {
float result = -1.0F;
float current;
if ((metadataList != null) && !metadataList.isEmpty()) {
for (Preference<T> pref : prefs) {
for (T metadata : metadataList) {
if (pref.getMetadata().includes(metadata)) {
current = pref.getQuality();
} else {
current = -1.0F;
}
if (current > result) {
result = current;
}
}
}
} else {
result = 0.0F;
}
return result;
}
代码示例来源:origin: org.restlet/org.restlet
@Override
public String toString() {
return (getMetadata() == null) ? ""
: (getMetadata().getName() + ":" + getQuality());
}
}
代码示例来源:origin: org.restlet.osgi/org.restlet
/**
* Scores a metadata relatively to enriched client preferences.
*
* @param metadata
* The metadata to score.
* @return The score.
*/
protected <T extends Metadata> float scoreMetadata(T metadata,
List<Preference<T>> prefs) {
float result = -1.0F;
float current;
if (metadata != null) {
for (Preference<? extends Metadata> pref : prefs) {
if (pref.getMetadata().includes(metadata)) {
current = pref.getQuality();
} else {
current = -1.0F;
}
if (current > result) {
result = current;
}
}
} else {
result = 0.0F;
}
return result;
}
代码示例来源:origin: DeviceConnect/DeviceConnect-Android
@Override
public String toString() {
return (getMetadata() == null) ? ""
: (getMetadata().getName() + ":" + getQuality());
}
}
代码示例来源:origin: org.restlet.osgi/org.restlet
@Override
public String toString() {
return (getMetadata() == null) ? ""
: (getMetadata().getName() + ":" + getQuality());
}
}
代码示例来源:origin: org.restlet.osgi/org.restlet
/**
* Returns the best supported encoding for a given client.
*
* @param client
* The client preferences to use.
* @return The best supported encoding for the given call.
*/
public Encoding getBestEncoding(ClientInfo client) {
Encoding bestEncoding = null;
Encoding currentEncoding = null;
Preference<Encoding> currentPref = null;
float bestScore = 0F;
for (Iterator<Encoding> iter = getSupportedEncodings().iterator(); iter
.hasNext();) {
currentEncoding = iter.next();
for (Iterator<Preference<Encoding>> iter2 = client
.getAcceptedEncodings().iterator(); iter2.hasNext();) {
currentPref = iter2.next();
if (currentPref.getMetadata().equals(Encoding.ALL)
|| currentPref.getMetadata().equals(currentEncoding)) {
// A match was found, compute its score
if (currentPref.getQuality() > bestScore) {
bestScore = currentPref.getQuality();
bestEncoding = currentEncoding;
}
}
}
}
return bestEncoding;
}
代码示例来源:origin: org.restlet.osgi/org.restlet
&& (preference.getQuality() < score)) {
preference.setQuality(score);
found = true;
代码示例来源:origin: org.restlet.osgi/org.restlet
/**
* Scores a media type relatively to enriched client preferences.
*
* @param mediaType
* The media type to score.
* @return The score.
*/
public float scoreMediaType(MediaType mediaType) {
float result = -1.0F;
float current;
if (mediaType != null) {
for (Preference<MediaType> pref : getMediaTypePrefs()) {
if (pref.getMetadata().includes(mediaType, false)) {
current = pref.getQuality();
} else {
current = -1.0F;
}
if (current > result) {
result = current;
}
}
} else {
result = 0.0F;
}
return result;
}
代码示例来源:origin: org.restlet.osgi/org.restlet
if (pref.getQuality() == 0) {
if (undesired == null) {
undesired = new ArrayList<T>();
if (canAdd(parent, undesired)) {
result.add(new Preference<T>(parent,
0.005f + (0.001f * userPref.getQuality())));
代码示例来源:origin: org.restlet.osgi/org.restlet
@Override
public PreferenceWriter append(Preference<?> pref) {
append(pref.getMetadata().getName());
if (pref.getQuality() < 1F) {
append(";q=");
appendQuality(pref.getQuality());
}
if (pref.getParameters() != null) {
Parameter param;
for (Iterator<Parameter> iter = pref.getParameters().iterator(); iter
.hasNext();) {
param = iter.next();
if (param.getName() != null) {
append(';').append(param.getName());
if ((param.getValue() != null)
&& (param.getValue().length() > 0)) {
append('=').append(param.getValue());
}
}
}
}
return this;
}
内容来源于网络,如有侵权,请联系作者删除!