java - Tracking which HashMap values have been returned -


i have large hashmap<integer, myobject> located on server. need send string myobject across network client. problem can't figure out way keep track of myobject has been accessed send string.

i'd client can repeatedly call server's function retrieve string, client can add strings arraylist. server indicate strings have been sent returning null.

i can't send arraylist<string> of strings limited tiny message size due use of rsa encryption.

the way i've thought of far keep static instance variable hashset<integer> holds of accessed myobjects. mean i'd have cross reference hashmap hashset every lookup. there must better way.

this tiny example of map keeps track of keys did accessed. basicly has overriden get method of hashmap , additionaly adds key did accessed set

import java.util.hashmap; import java.util.hashset; import java.util.set;  public class trackmap<k, v>  extends hashmap<k,v>{     private static final long serialversionuid = 1l;      set<object> usedkeys = new hashset<>();      @override     public v get(object key) {         usedkeys.add(key);         return super.get(key);     }      public set<object> getusedkeys() {         return usedkeys;     }      public static void main(string[] args) {         trackmap<integer, string> test = new trackmap<>();         for(int = 0;i<100;++i) {             test.put(i, integer.tostring(i));         }         system.out.println(test.get(5));         system.out.println(test.get(10));         system.out.println(test.get(15));         system.out.println(test.get(17));         system.out.println(test.get("what?"));          for(object : test.getusedkeys()) {             system.out.println("the key " + + " accessed");         }     } } 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -