[Android] DirectoryAdapter: null string checks

Edward Wang git at videolan.org
Mon May 20 20:26:22 CEST 2013


vlc-ports/android | branch: master | Edward Wang <edward.c.wang at compdigitec.com> | Mon May 20 14:26:18 2013 -0400| [06549cfe488b7cb1a171cf27f65e418e4bb0a7a1] | committer: Edward Wang

DirectoryAdapter: null string checks

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=06549cfe488b7cb1a171cf27f65e418e4bb0a7a1
---

 vlc-android/src/org/videolan/vlc/Util.java                 |    9 ++++++++-
 vlc-android/src/org/videolan/vlc/gui/DirectoryAdapter.java |    6 ++++--
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/Util.java b/vlc-android/src/org/videolan/vlc/Util.java
index 59592ff..2549887 100644
--- a/vlc-android/src/org/videolan/vlc/Util.java
+++ b/vlc-android/src/org/videolan/vlc/Util.java
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * Util.java
  *****************************************************************************
- * Copyright © 2011-2012 VLC authors and VideoLAN
+ * Copyright © 2011-2013 VLC authors and VideoLAN
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -416,4 +416,11 @@ public class Util {
     public static String formatRateString(float rate) {
         return String.format(java.util.Locale.US, "%.2fx", rate);
     }
+
+    /**
+     * equals() with two strings where either could be null
+     */
+    public static boolean nullEquals(String s1, String s2) {
+        return (s1 == null ? s2 == null : s1.equals(s2));
+    }
 }
diff --git a/vlc-android/src/org/videolan/vlc/gui/DirectoryAdapter.java b/vlc-android/src/org/videolan/vlc/gui/DirectoryAdapter.java
index 37ed603..3b3e76b 100644
--- a/vlc-android/src/org/videolan/vlc/gui/DirectoryAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/DirectoryAdapter.java
@@ -58,6 +58,8 @@ public class DirectoryAdapter extends BaseAdapter {
         public ArrayList<DirectoryAdapter.Node> children;
         /**
          * Name of the file/folder (not full path).
+         *
+         * null on the root node (root selection folder).
          */
         String name;
         String visibleName;
@@ -100,14 +102,14 @@ public class DirectoryAdapter extends BaseAdapter {
 
         public Boolean existsChild(String _n) {
             for(DirectoryAdapter.Node n : this.children) {
-                if(n.name.equals(_n)) return true;
+                if(Util.nullEquals(n.name, _n)) return true;
             }
             return false;
         }
 
         public DirectoryAdapter.Node ensureExists(String _n) {
             for(DirectoryAdapter.Node n : this.children) {
-                if(n.name.equals(_n)) return n;
+                if(Util.nullEquals(n.name, _n)) return n;
             }
             DirectoryAdapter.Node nn = new Node(_n);
             this.children.add(nn);



More information about the Android mailing list