java - Print out the entries from the map when the value gets changed -


i working on project in need print out data database in way. let's take example, suppose in database, have below entries only-

framework 1.0.0 bundleb 1.0.0 bundlec 1.0.0 

then java method make call database return me map of above data.

my map have above data below-

key framework, value 1.0.0 key bundleb, value 1.0.0 key bundlec, value 1.0.0 

suppose, started program first time, print out below code have, fine.

framework - 1.0.0 

and running background thread every 2 seconds make call database , data again database. , every 2 seconds, print out same thing below- (which not want)

framework - 1.0.0 

i want print out framework - 1.0.0 first time when running program second time when background thread running, should print out when version gets changed framework, otherwise don't print out anything.

meaning after time, if changes version information in database this-

framework 1.0.1 bundleb 1.0.0 bundlec 1.0.0 

then should print out this-

framework - 1.0.1 

i hope questions clear enough. below code have far.

public class test {      public static map<string, string> bundlelist = new linkedhashmap<string, string>();      private static map<string, string> oldbundlelist = new linkedhashmap<string, string>();       public static void main(string[] args) {          getattributesfromdatabase();          loggingaftereveryxmilliseconds();      }       private static void getattributesfromdatabase() {          map<string, string> bundleinformation = new linkedhashmap<string, string>();          bundleinformation = getfromdatabase();         if(!bundleinformation.isempty()) {             oldbundlelist = bundlelist;             bundlelist = bundleinformation;         }          final map<string, mapdifference.valuedifference<string>> entriesdiffering = maps.difference(oldbundlelist, bundlelist).entriesdiffering();         if (!entriesdiffering.isempty()) {             (string key : entriesdiffering.keyset()) {                 bundlelist.put(key, bundlelist.get(key));             }          }          string version = bundlelist.get("framework");         printoutzeroinformation("framework", version);     }      private static void printoutzeroinformation(string string, string version) {         system.out.println(string+" - "+version);            }      private static map<string, string> getfromdatabase() {          map<string, string> hello = new linkedhashmap<string, string>();          string version0 = "1.0.0";         string version1 = "1.0.0";         string version2 = "1.0.0";          hello.put("framework", version0);         hello.put("bundlea", version1);         hello.put("bundleb", version2);          return hello;     }      private static void loggingaftereveryxmilliseconds() {         new thread() {             public void run() {                 while (true) {                     try {                         thread.sleep(2000);                     } catch (interruptedexception ex) {                      }                     getattributesfromdatabase();                 }             }         }.start();     } } 

any appreciated on this.

i didn't run it. i'm giving idea. try same print well. let me know if don't it.

private static void getfromdatabase() {          map<string, string> hello = new linkedhashmap<string, string>();                      string version0 = "1.0.0";         string version1 = "1.0.0";         string version2 = "1.0.0";          hello.put("framework", version0);         hello.put("bundlea", version1);         hello.put("bundleb", version2);          //the following code update bundlelist when it's different hello         if (!bundlelist.isempty()) {             if (bundlelist.get("framework") != hello.get("framework"))                 bundlelist.put("framework", version0)             if (bundlelist.get("bundlea") != hello.get("bundlea"))                 bundlelist.put("bundlea", version1)             if (bundlelist.get("bundleb") != hello.get("bundleb"))                 bundlelist.put("bundleb", version2)         }         else { //if first time             bundlelist.put("framework", version0)             bundlelist.put("bundlea", version1)             bundlelist.put("bundleb", version2)         }     } 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -