[libbluray-devel] Fix org.dvb.user.Preference

hpi1 git at videolan.org
Mon Sep 8 11:42:48 CEST 2014


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Mon Sep  8 11:09:15 2014 +0300| [14dcecc119ff665e2c5b4e560af3362ba7dbda64] | committer: hpi1

Fix org.dvb.user.Preference

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=14dcecc119ff665e2c5b4e560af3362ba7dbda64
---

 .../bdj/java/org/dvb/user/Preference.java          |   61 +++++++++++++-------
 1 file changed, 39 insertions(+), 22 deletions(-)

diff --git a/src/libbluray/bdj/java/org/dvb/user/Preference.java b/src/libbluray/bdj/java/org/dvb/user/Preference.java
index ba499d3..99e49a9 100644
--- a/src/libbluray/bdj/java/org/dvb/user/Preference.java
+++ b/src/libbluray/bdj/java/org/dvb/user/Preference.java
@@ -20,7 +20,7 @@
 package org.dvb.user;
 
 import java.util.Iterator;
-import java.util.LinkedList;
+import java.util.Vector;
 
 public class Preference {
     protected Preference() {
@@ -40,8 +40,10 @@ public class Preference {
     }
 
     public void add(String value) {
-        values.remove(value);
-        values.add(value);
+        synchronized (values) {
+            values.remove(value);
+            values.add(value);
+        }
     }
 
     public void add(String value[]) {
@@ -50,24 +52,32 @@ public class Preference {
     }
 
     public void add(int position, String value) {
-        values.remove(value);
-        if (position < 0)
-            position = 0;
-        else if (position > values.size())
-            position = values.size();
-        values.add(position, value);
+        synchronized (values) {
+            values.remove(value);
+            if (position < 0)
+                position = 0;
+            else if (position > values.size())
+                position = values.size();
+            values.add(position, value);
+        }
     }
 
     public String[] getFavourites() {
-        if (values.isEmpty())
-            return new String[0];
-        return (String[])values.toArray();
+        synchronized (values) {
+            if (values.isEmpty())
+                return new String[0];
+            String[] result = new String[values.size()];
+            values.copyInto(result);
+            return result;
+        }
     }
 
     public String getMostFavourite() {
-        if (values.isEmpty())
-            return null;
-        return (String)values.get(0);
+        synchronized (values) {
+            if (values.isEmpty())
+                return null;
+            return (String)values.get(0);
+        }
     }
 
     public String getName() {
@@ -75,24 +85,31 @@ public class Preference {
     }
 
     public int getPosition(String value) {
-        return values.indexOf(value);
+        synchronized (values) {
+            return values.indexOf(value);
+        }
     }
 
     public boolean hasValue() {
-        return !values.isEmpty();
+        synchronized (values) {
+            return !values.isEmpty();
+        }
     }
 
     public void remove(String value) {
-        values.remove(value);
+        synchronized (values) {
+            values.remove(value);
+        }
     }
 
     public void removeAll() {
-        values.clear();
+        synchronized (values) {
+            values.clear();
+        }
     }
 
     public void setMostFavourite(String value) {
-        values.remove(value);
-        values.addFirst(value);
+        add(0, value);
     }
 
     public String toString() {
@@ -108,5 +125,5 @@ public class Preference {
     }
 
     private String name;
-    private LinkedList values = new LinkedList();
+    private Vector values = new Vector();
 }



More information about the libbluray-devel mailing list