TreeMap does not increment under this algorithm

Amn Ojee Uw amnojeeuw at gmail.com
Fri Apr 15 21:19:47 UTC 2022


I am not sure if I should post this concern in here, if not, please give 
some directions.

OS win8.1
JDK 17

// StringVerification is my own version of
// what a string class should be all about, it is a wrapper class for 
StringBuffer
public class MyABCs {
     private final StringVerification sv;
     private final List<StringVerification> en_alph_list;
     ...

     public MyABCs() {
         this.sv = new StringVerification();
         this.en_alph_list = new ArrayList<>();

         this.sv.setData("a");
         this.en_alph_list.add(new StringVerification(sv.getData()));
         this.sv.setData("b");
         this.en_alph_list.add(new StringVerification(sv.getData()));
         this.sv.setData("b");
         this.en_alph_list.add(new StringVerification(sv.getData()));
         ///  ...
         this.sv.setData("x");
         this.en_alph_list.add(new StringVerification(sv.getData()));
         this.sv.setData("y");
         this.en_alph_list.add(new StringVerification(sv.getData()));
         this.sv.setData("z");
         this.en_alph_list.add(new StringVerification(sv.getData()));

     public List<StringVerification> getListOfCharacter() {
         return this.en_alph_list;
     }
     This class is converted to a artifact called MyABCs.jar and
     it is consumed by the MyAbcImplementation , like this:

     public class MyAbcImplementation {
         private final MyABCs en_char;
         private final List<StringVerification> tmpList;
         private final SortedMap<StringVerification, Double> treemap;
         Double d = 0.0;
         Integer i = 0;
         int pos = 0;

         public MyAbcImplementation(){
             this.en_char = new MyABCs();
             this.tmpList = new ArrayList<StringVerification>();
             this.treemap = new TreeMap<>();
             this.show();
         }
         public show(){
             //Populate the list
this.tmpList.addAll(this.en_char.getListOfCharacter());
             //Displays the correct size 26
             System.out.println("Size of tmpList : " + this.tmpList.size());
             for (; pos != tmpList.size(); pos++,d++) {
                 treemap.put(this.tmpList.get(pos), d);
             }
/**** THIS IS THE PROBLEM ***/
             //Displays 1, which is incorrect, it should be 26
             System.out.println("From en_vawels() - TreeMap size is " + 
treemap.size());
         }


I have looked at this problem from many angels, but to no avail. I know 
that the problem is in the loop whatever look I use the result is the 
same, 1 and never 26.
I don't think that it is a developer's problem, I mean, me; no never ;) 
. However, it might be a TreeMap/ArrayList combo problem.

The objective is to print out the Key and then the Value in each of the 
elements of the TreeMap.
Please not that I have successfully managed to print Key and Value, but 
only of the ONE element in the TreeMap, remember size is always 1, brrrr.

I need to insert ALL the values in tmpList as K with an incremental 
value as V, thus the loop.

Perhaps it is the problem resides in the combo mentioned above or, just 
by some remote probability I am doing something wrong ;). Yaaa, me too, 
I think is the latter.

Thanks in advance, any help would be very much appreciated.

-- 
*ArbolOne* Using Fire Fox and Thunderbird. Developing for Android using 
Java, C/C++, HTM/CSS and SQLite as our platform has been exciting and 
most rewarding. [ Ñ ]

-- 
This email has been checked for viruses by AVG.
https://www.avg.com


More information about the guide-dev mailing list