Note that there are some explanatory texts on larger screens.

plurals
  1. POusing comparators as embedded classes, the mother class (initialized in clone ) fields are not visible in the compare method
    primarykey
    data
    text
    <p>I have developed a server-to-server protocol called CCMN and different drop policies for the messages cached by each server. The PEERSIM simulator creates a template node with the CCMN protocol and then clones this template node. </p> <p>The CCMN class includes different data structures maintaining the states required to implement the drop policies. For instance, <em>Pmap</em> resolves a content identifier to a content object, and <em>freq</em> a content identifier to the number of times a content object has been used.</p> <pre><code>public HashMap &lt;String, Content&gt; Pmap; public HashMap&lt;String, Integer&gt; freq; </code></pre> <p>The initialization of these data structures is done in the clone method of CCMN. In order to support the drop policies, I use a priorityQueue initialized with a comparator corresponding to the policy to use. In the clone method:</p> <pre><code>if(dp.equals(DroppingPolicy.LFU)){ </code></pre> <p>lfu less_frequent=new lfu(); av.raw_drop=new PriorityQueue(1, less_frequent); } The comparator are declared as follows:</p> <pre><code>public class lfu implements Comparator&lt;String&gt; { </code></pre> <p>public int compare(String s0, String s1) { if(freq.get(s0) > freq.get(s1)) return 1; else if(freq.get(s0) &lt; freq.get(s1)) return -1; else return 0; } }</p> <p><strong>The problem is that</strong> I get a NullPointerException exception when i call :</p> <pre><code>raw_drop.add(ct.getID()); </code></pre> <p>By debugging, I found that the add works for the first element, but the exception occurs when a second element is added. I traced the exception to the compare method, by checking the variables I find that the <em>freq</em> variable (and the other variables initialized in the clone method) equals <em>null</em>, while the variables defined in the constructor are well defined.</p> <p>Moreover, I check that <em>freq</em> is well initialized before the <em>add</em> call.</p> <p>I guess that there is a problem between the definition of the comparators as embedded classes and the <em>clone</em> method.</p> <p>Any help is welcome.</p> <p>Regards, Mohamed</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload