title: Are my cache references and hits wrong because of my BufferedReader?
body: <p>I am having an issue with the correct amount of cache hits and misses in my implementation for my data structures course.</p>
  <p>I am using a buffered reader as follows in order to read every line of an encyclopedia:</p>
  <pre><code>            try(BufferedReader in = new BufferedReader(new FileReader(args[2]))){
                  String line;
                  
                  while((line=in.readLine())!=null){
                      String[] keys = line.split(&quot; &quot;);
                      if(line.trim().length()&gt;0){
                          for(int i=0;i&lt;keys.length;i++){
                              list.getObject(keys[i]);
                          }
                      }
                  }
              }catch
  </code></pre>
  <p>Within my Encyclopedia.txt file, there are 1,347,451 words, which means that my number of references should be just about that, however I am over by 95,699.</p>
  <p>The number of hits I am supposed to have for this file should be 837,461, given a cache size of 1000, but again I am over by 95,578.</p>
  <p>Below is my code where I increment the number of references(nr1) and the number of hits(nh1):</p>
  <pre><code>public T getObject(T key){
          if(fCache.size()==0){
              //if it is the first element being added
              fCache.add(key);
          }else{
              int target=0;
              if((target=fCache.indexOf(key))!=(-1)){
                  //first cache contains key
                  fCache.remove(target);
                  fCache.add(key);
                  nh1++;
              }else{
                  //first cache does not contain key
                  if(fCache.size()&gt;=fSize){
                      //too big
                      fCache.remove(0);
                      fCache.add(key);
                  }else if(fCache.size()&lt;fSize){
                      fCache.add(key);
                  }
              }
          }
      nr1++;
  }
  </code></pre>
  <p>The above snippet is the only place where nr1 and nh1 are incremented, so I am assuming that with larger files, BufferedReader is calling getObject() too many times, but I do not understand why, as it works fine on smaller files.</p>
  <p>EDIT:</p>
  <p>expected output is:</p>
  <pre><code>The number of 1st-level references: 1347451
   10 The number of 1st-level cache hits: 837461
   11 The 1st-level cache hit ratio             : 0.6215149938661962
  </code></pre>
  <p>and my output is:</p>
  <pre><code>The number of 1st-level references: 1443150
  The number of 1st-level cache hits: 933039
  The number of 1st-level cache hit ratio : 0.6465294667913938
  </code></pre>