Author: jerome
Date: 2008-08-16 10:50:56 +0200 (Sat, 16 Aug 2008)
New Revision: 1512

Modified:
   
software_suite_v2/software/tools/chatterTux/trunk/Chatter_tux/src/IniFile.java
Log:
* Simple ini file reader.We now have an integer index to each stored keys ==> 
getting values by key name or key index from hashtable.

Modified: 
software_suite_v2/software/tools/chatterTux/trunk/Chatter_tux/src/IniFile.java
===================================================================
--- 
software_suite_v2/software/tools/chatterTux/trunk/Chatter_tux/src/IniFile.java  
    2008-08-16 08:48:36 UTC (rev 1511)
+++ 
software_suite_v2/software/tools/chatterTux/trunk/Chatter_tux/src/IniFile.java  
    2008-08-16 08:50:56 UTC (rev 1512)
@@ -34,7 +34,8 @@
        
        private File file;
        private Ini ini;
-       private Hashtable keys;
+       private Hashtable<String, Vector<String>> keys;
+       private Hashtable<Integer, String> indexes;
        
        public IniFile(File file){
                this.file = file;
@@ -42,9 +43,6 @@
                try {
                        //ini.load(new URL(file.getAbsolutePath()));
                        this.keys = this.getKeys(this.file);
-                       if(this.keys.size() > 0){
-                               System.out.println("Hash table size: " + 
this.keys.size());
-                       }
                } catch (Exception except){ except.printStackTrace(); }
        }
        
@@ -54,8 +52,15 @@
        }
        
        
-       private Hashtable getKeys(File file) throws Exception{
+       /**
+        * This function gets keys into .ini file and store an index to each 
key.
+        * @param file
+        * @return
+        * @throws Exception
+        */
+       private Hashtable<String, Vector<String>> getKeys(File file) throws 
Exception{
                Hashtable<String, Vector<String>> keys = new Hashtable<String, 
Vector<String>>();
+               Hashtable<Integer, String> indexes = new Hashtable<Integer, 
String>();
                Vector<String> values = new Vector<String>();
                String storedKeys = "";
                
@@ -68,7 +73,8 @@
                        
                        if(ligne.contains("[") && ligne.contains("]")){
                                //then it's a key.
-                               storedKeys = ligne;
+                               storedKeys = ligne.replace("[", 
"").replace("]", "");
+                               indexes.put(keys.size(), storedKeys); 
//Register index.
                        }
                        else if(ligne.contains("=")){
                                //then it's a key value.
@@ -82,7 +88,34 @@
                }
                
                br.close(); 
-
+               this.indexes = indexes;
                return keys;
        }
+       
+       
+       /*
+        * Return a key at parameter index.
+        */
+       public String getKeyAtIndex(int index){
+               return this.indexes.get(index).toString();
+       }
+       
+       
+       /*
+        * Return ini properties by key index.   
+        * @param index
+        * @return
+        */
+       public Vector<String> getKeyPropertiesAtIndex(int index){
+               String key = this.indexes.get(index).toString();
+               return (Vector<String>)this.keys.get(key);
+       }
+       
+       
+       /*
+        * Return ini properties by key name.
+        */
+       public Vector<String> getKeyPropertiesAtKey(String key){
+               return (Vector<String>)this.keys.get(key);
+       }
 }


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn

Reply via email to