abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r1175204 - /abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/Preference.java
Date Sat, 24 Sep 2011 17:34:36 GMT
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());
+  }
 }



Mime
View raw message