You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@abdera.apache.org by jm...@apache.org on 2011/09/24 19:34:36 UTC
svn commit: r1175204 -
/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/Preference.java
Author: jmsnell
Date: Sat Sep 24 17:34:35 2011
New Revision: 1175204
URL: http://svn.apache.org/viewvc?rev=1175204&view=rev
Log:
Minor tweaks
Modified:
abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/Preference.java
Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/Preference.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/Preference.java?rev=1175204&r1=1175203&r2=1175204&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/Preference.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/Preference.java Sat Sep 24 17:34:35 2011
@@ -3,6 +3,7 @@ package org.apache.abdera2.common.http;
import java.io.Serializable;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -64,13 +65,18 @@ public class Preference implements Seria
private static final long serialVersionUID = -6238673046322517740L;
private final String token;
- private String value;
+ private final String value;
private final Map<String,String> params =
new HashMap<String,String>();
public Preference(String token) {
+ this(token,null);
+ }
+
+ public Preference(String token, String value) {
CharUtils.verify(token, Profile.TOKEN);
this.token = token.toLowerCase();
+ this.value = value;
}
public String getToken() {
@@ -81,10 +87,6 @@ public class Preference implements Seria
return value;
}
- public void setValue(String value) {
- this.value = value;
- }
-
private static final Set<String> reserved =
new HashSet<String>();
static {
@@ -212,8 +214,7 @@ public class Preference implements Seria
tokenval = Codec.decode(CharUtils.unquote(ps[1]));
}
- Preference preference = new Preference(token);
- preference.setValue(tokenval);
+ Preference preference = new Preference(token,tokenval);
prefs.add(preference);
if (params != null) {
@@ -252,6 +253,10 @@ public class Preference implements Seria
return buf.toString();
}
+ /**
+ * Utility method that checks to see if the given token is included
+ * in the collection of preferences.
+ */
public static boolean contains(
Iterable<Preference> preferences,
String token) {
@@ -260,4 +265,16 @@ public class Preference implements Seria
return true;
return false;
}
+
+ /**
+ * Utility method that checks to see if the given token is included
+ * in the collection of preference
+ */
+ public static boolean contains(
+ Iterable<Preference> preferences,
+ Preference preference) {
+ return preferences instanceof Collection ?
+ ((Collection<Preference>)preferences).contains(preference) :
+ contains(preferences,preference.getToken());
+ }
}