[libbluray-devel] javax.tv.service.navigation.*: improve compatibility

hpi1 git at videolan.org
Wed Apr 6 10:27:54 CEST 2016


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Tue Apr  5 13:48:01 2016 +0300| [2a65274ce3d5391bc4a1a0939475147001f63a07] | committer: hpi1

javax.tv.service.navigation.*: improve compatibility

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

 .../tv/service/navigation/DeliverySystemType.java  |    2 ++
 .../javax/tv/service/navigation/LocatorFilter.java |   28 ++++++++++++++++++--
 .../tv/service/navigation/PreferenceFilter.java    |    3 +++
 .../tv/service/navigation/ServiceIteratorImpl.java |   13 ++++-----
 .../tv/service/navigation/ServiceListImpl.java     |   11 ++++++--
 .../tv/service/navigation/ServiceTypeFilter.java   |    4 ++-
 .../navigation/SortNotAvailableException.java      |    1 +
 7 files changed, 51 insertions(+), 11 deletions(-)

diff --git a/src/libbluray/bdj/java/javax/tv/service/navigation/DeliverySystemType.java b/src/libbluray/bdj/java/javax/tv/service/navigation/DeliverySystemType.java
index 2435741..7825218 100644
--- a/src/libbluray/bdj/java/javax/tv/service/navigation/DeliverySystemType.java
+++ b/src/libbluray/bdj/java/javax/tv/service/navigation/DeliverySystemType.java
@@ -21,6 +21,8 @@ package javax.tv.service.navigation;
 
 public class DeliverySystemType {
     protected DeliverySystemType(String name) {
+        if (name == null)
+            throw new NullPointerException("no name");
         this.name = name;
     }
 
diff --git a/src/libbluray/bdj/java/javax/tv/service/navigation/LocatorFilter.java b/src/libbluray/bdj/java/javax/tv/service/navigation/LocatorFilter.java
index 8fb7aa3..5dfbee0 100644
--- a/src/libbluray/bdj/java/javax/tv/service/navigation/LocatorFilter.java
+++ b/src/libbluray/bdj/java/javax/tv/service/navigation/LocatorFilter.java
@@ -23,8 +23,24 @@ import javax.tv.locator.Locator;
 import javax.tv.locator.InvalidLocatorException;
 import javax.tv.service.Service;
 
+import org.bluray.net.BDLocator;
+import org.bluray.ti.TitleImpl;
+
 public final class LocatorFilter extends ServiceFilter {
     public LocatorFilter(Locator[] locators) throws InvalidLocatorException {
+        if (locators == null)
+            throw new NullPointerException();
+
+        for (int i = 0; i < locators.length; i++) {
+            try {
+                if (locators[i] == null)
+                    throw new InvalidLocatorException(locators[i]);
+                new BDLocator(locators[i].toExternalForm());
+            } catch (org.davic.net.InvalidLocatorException e) {
+                throw new InvalidLocatorException(locators[i]);
+            }
+        }
+
         this.locators = locators;
     }
 
@@ -36,9 +52,17 @@ public final class LocatorFilter extends ServiceFilter {
         if (service == null)
             throw new NullPointerException();
 
+        if (!(service instanceof TitleImpl))
+            return false;
+
+        int num = ((TitleImpl)service).getTitleNum();
         for (int i = 0; i < locators.length; i++) {
-            if (locators[i].equals(service.getLocator()))
-                return true;
+
+            try {
+                BDLocator bdl = new BDLocator(locators[i].toExternalForm());
+                if (bdl.getTitleNumber() == num)
+                    return true;
+            } catch (org.davic.net.InvalidLocatorException e) { }
         }
 
         return false;
diff --git a/src/libbluray/bdj/java/javax/tv/service/navigation/PreferenceFilter.java b/src/libbluray/bdj/java/javax/tv/service/navigation/PreferenceFilter.java
index 4297250..b44a3b8 100644
--- a/src/libbluray/bdj/java/javax/tv/service/navigation/PreferenceFilter.java
+++ b/src/libbluray/bdj/java/javax/tv/service/navigation/PreferenceFilter.java
@@ -24,6 +24,9 @@ import javax.tv.service.Service;
 public final class PreferenceFilter extends ServiceFilter {
 
     public PreferenceFilter(FavoriteServicesName name) {
+        System.err.println("No preference");
+        if (name == null)
+            throw new NullPointerException();
         throw new IllegalArgumentException();
     }
 
diff --git a/src/libbluray/bdj/java/javax/tv/service/navigation/ServiceIteratorImpl.java b/src/libbluray/bdj/java/javax/tv/service/navigation/ServiceIteratorImpl.java
index 441cb5b..e66eb2f 100644
--- a/src/libbluray/bdj/java/javax/tv/service/navigation/ServiceIteratorImpl.java
+++ b/src/libbluray/bdj/java/javax/tv/service/navigation/ServiceIteratorImpl.java
@@ -19,6 +19,7 @@
 package javax.tv.service.navigation;
 
 import java.util.LinkedList;
+import java.util.NoSuchElementException;
 
 import javax.tv.service.Service;
 
@@ -36,15 +37,15 @@ public class ServiceIteratorImpl implements ServiceIterator {
     }
 
     public Service nextService() {
-        if (index < services.size())
-            return (Service)services.get(index++);
-        return null;
+        if (!hasNext())
+            throw new NoSuchElementException("End of list reached");
+        return (Service)services.get(index++);
     }
 
     public Service previousService() {
-        if (index > 0)
-            return (Service)services.get(--index);
-        return null;
+        if (!hasPrevious())
+            throw new NoSuchElementException("Start of list reached");
+        return (Service)services.get(--index);
     }
 
     public boolean hasNext() {
diff --git a/src/libbluray/bdj/java/javax/tv/service/navigation/ServiceListImpl.java b/src/libbluray/bdj/java/javax/tv/service/navigation/ServiceListImpl.java
index 9846ca3..0ecb6d5 100644
--- a/src/libbluray/bdj/java/javax/tv/service/navigation/ServiceListImpl.java
+++ b/src/libbluray/bdj/java/javax/tv/service/navigation/ServiceListImpl.java
@@ -53,27 +53,34 @@ public class ServiceListImpl implements ServiceList {
             try {
                 bdLocator = new BDLocator(locator.toExternalForm());
             } catch (org.davic.net.InvalidLocatorException e) {
+                System.err.println("invalid locator");
                 throw new InvalidLocatorException(locator);
             }
         } else {
             bdLocator = (BDLocator)locator;
         }
         int title = bdLocator.getTitleNumber();
-        if (title < 0)
+        if (title < 0) {
+            System.err.println("invalid title in locator");
             throw new InvalidLocatorException(locator);
+        }
         for (int i = 0; i < size(); i++) {
             TitleImpl ti = (TitleImpl)services.get(i);
             if (((TitleImpl)services.get(i)).getTitleNum() == title)
                 return ti;
         }
+        System.err.println("findService: " + locator + " not found");
         return null;
     }
 
     public ServiceList filterServices(ServiceFilter filter) {
+        if (filter == null) {
+            System.err.println("null service filter");
+        }
         LinkedList list = new LinkedList();
         for (int i = 0; i < size(); i++) {
             Service service = getService(i);
-            if (filter.accept(service))
+            if (filter == null || filter.accept(service))
                 list.add(service);
         }
         return new ServiceListImpl(list);
diff --git a/src/libbluray/bdj/java/javax/tv/service/navigation/ServiceTypeFilter.java b/src/libbluray/bdj/java/javax/tv/service/navigation/ServiceTypeFilter.java
index 2ab7160..1a7ad1b 100644
--- a/src/libbluray/bdj/java/javax/tv/service/navigation/ServiceTypeFilter.java
+++ b/src/libbluray/bdj/java/javax/tv/service/navigation/ServiceTypeFilter.java
@@ -33,7 +33,9 @@ public final class ServiceTypeFilter extends ServiceFilter {
     }
 
     public boolean accept(Service service) {
-        return service.getServiceType().equals(type);
+        if (service == null)
+            throw new NullPointerException();
+        return service.getServiceType() == type;
     }
 
     private ServiceType type;
diff --git a/src/libbluray/bdj/java/javax/tv/service/navigation/SortNotAvailableException.java b/src/libbluray/bdj/java/javax/tv/service/navigation/SortNotAvailableException.java
index 2d02a5e..8b2a051 100644
--- a/src/libbluray/bdj/java/javax/tv/service/navigation/SortNotAvailableException.java
+++ b/src/libbluray/bdj/java/javax/tv/service/navigation/SortNotAvailableException.java
@@ -27,6 +27,7 @@ public class SortNotAvailableException extends SIException
     }
 
     public SortNotAvailableException(String reason) {
+        super(reason);
     }
 
     private static final long serialVersionUID = 5524379730037808067L;



More information about the libbluray-devel mailing list